Skip to content

Commit

Permalink
Add functions to build sources (#47)
Browse files Browse the repository at this point in the history
* helm-ls-git.el (helm-source-ls-git-status): Docstring.
(helm-source-ls-git):                         Docstring.
(helm-source-ls-git-buffers):                 Docstring.
(helm-ls-git-build-git-status-source): New.
(helm-ls-git-build-ls-git-source):     New.
(helm-ls-git-build-buffers-source):    New.
(helm-ls-git-ls): Use them to build sources.
* README.md: Update.
  • Loading branch information
Thierry Volpiatto committed Jul 16, 2017
1 parent 1253c76 commit e57d99d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ to the `current-buffer`:
M-x `helm-find-files`
navigate to some git repo and hit `C-x C-d`

If you want to use the helm-ls-git sources somewhere else, you can build them individually with functions
`helm-ls-git-build-git-status-source`, `helm-ls-git-build-buffers-source` and `helm-ls-git-build-ls-git-source`.

As these sources built with their own classes, they can be configured with defmethod `helm-setup-user-source`,
see [FAQ](https://github.com/emacs-helm/helm/wiki/FAQ#why-is-a-customizable-helm-source-nil).

## Usage

* By calling `helm-ls-git-ls` or `helm-browse-project` in any buffer that is a part of a git
Expand Down
66 changes: 49 additions & 17 deletions helm-ls-git.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@
(make-obsolete-variable 'helm-c-source-ls-git-status 'helm-source-ls-git-status "1.5.1")

;; Define the sources.
(defvar helm-source-ls-git-status nil)
(defvar helm-source-ls-git nil)
(defvar helm-source-ls-git-buffers nil)
(defvar helm-source-ls-git-status nil
"This source will built at runtime.
It can be build explicitely with function
`helm-ls-git-build-git-status-source'.")
(defvar helm-source-ls-git nil
"This source will built at runtime.
It can be build explicitely with function
`helm-ls-git-build-ls-git-source'.")
(defvar helm-source-ls-git-buffers nil
"This source will built at runtime.
It can be build explicitely with function
`helm-ls-git-build-buffers-source'.")



(defgroup helm-ls-git nil
Expand Down Expand Up @@ -527,6 +537,39 @@ and launch git-grep from there.
(funcall helm-ls-git-status-command
(helm-default-directory))))
1)))))

(defun helm-ls-git-build-git-status-source ()
"Build `helm-source-ls-git-status'.
Do nothing when `helm-source-ls-git-status' is not member of
`helm-ls-git-default-sources'."
(and (memq 'helm-source-ls-git-status helm-ls-git-default-sources)
(helm-make-source "Git status" 'helm-ls-git-status-source
:fuzzy-match helm-ls-git-fuzzy-match
:group 'helm-ls-git)))

(defun helm-ls-git-build-ls-git-source ()
"Build `helm-source-ls-git'.
Do nothing when `helm-source-ls-git' is not member of
`helm-ls-git-default-sources'."
(and (memq 'helm-source-ls-git helm-ls-git-default-sources)
(helm-make-source "Git files" 'helm-ls-git-source
:fuzzy-match helm-ls-git-fuzzy-match
:group 'helm-ls-git)))

(defun helm-ls-git-build-buffers-source ()
"Build `helm-source-ls-git-buffers'.
Do nothing when `helm-source-ls-git-buffers' is not member of
`helm-ls-git-default-sources'."
(and (memq 'helm-source-ls-git-buffers helm-ls-git-default-sources)
(helm-make-source "Buffers in git project" 'helm-source-buffers
:header-name #'helm-ls-git-header-name
:buffer-list (lambda () (helm-browse-project-get-buffers
(helm-ls-git-root-dir)))
:keymap helm-ls-git-buffer-map)))


;;;###autoload
(defun helm-ls-git-ls (&optional arg)
Expand All @@ -536,22 +579,11 @@ and launch git-grep from there.
(unless (cl-loop for s in helm-ls-git-default-sources
always (symbol-value s))
(setq helm-source-ls-git-status
(and (memq 'helm-source-ls-git-status helm-ls-git-default-sources)
(helm-make-source "Git status" 'helm-ls-git-status-source
:fuzzy-match helm-ls-git-fuzzy-match
:group 'helm-ls-git))
(helm-ls-git-build-git-status-source)
helm-source-ls-git
(and (memq 'helm-source-ls-git helm-ls-git-default-sources)
(helm-make-source "Git files" 'helm-ls-git-source
:fuzzy-match helm-ls-git-fuzzy-match
:group 'helm-ls-git))
(helm-ls-git-build-ls-git-source)
helm-source-ls-git-buffers
(and (memq 'helm-source-ls-git-buffers helm-ls-git-default-sources)
(helm-make-source "Buffers in git project" 'helm-source-buffers
:header-name #'helm-ls-git-header-name
:buffer-list (lambda () (helm-browse-project-get-buffers
(helm-ls-git-root-dir)))
:keymap helm-ls-git-buffer-map))))
(helm-ls-git-build-buffers-source)))
(helm-set-local-variable 'helm-ls-git--current-branch (helm-ls-git--branch))
(helm :sources helm-ls-git-default-sources
:ff-transformer-show-only-basename nil
Expand Down

0 comments on commit e57d99d

Please sign in to comment.