From e57d99dc92dbb860508307c5c3b70d7625550a6d Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto Date: Sun, 16 Jul 2017 09:55:31 +0200 Subject: [PATCH] Add functions to build sources (#47) * 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. --- README.md | 6 +++++ helm-ls-git.el | 66 +++++++++++++++++++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 1b44229..61cbbca 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/helm-ls-git.el b/helm-ls-git.el index d60f4b6..9b213ff 100644 --- a/helm-ls-git.el +++ b/helm-ls-git.el @@ -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 @@ -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) @@ -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