From 3f5f10144340ac118965d21aecd89f05ab9830d4 Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Sun, 24 Oct 2021 21:23:38 +0800 Subject: [PATCH 1/4] Enable helm-follow-mode feature for helm-git-grep --- README.md | 12 ++++++++++++ helm-git-grep.el | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d5602e..7fe6bd7 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ * [Customization](#customization) * [Variables](#variables) * [helm\-git\-grep\-sources](#helm-git-grep-sources) + * [helm\-follow\-mode\-persistent](#helm-follow-mode-persistent) * [helm\-git\-grep\-candidate\-number\-limit](#helm-git-grep-candidate-number-limit) * [helm\-git\-grep\-max\-length\-history](#helm-git-grep-max-length-history) * [helm\-git\-grep\-use\-ioccur\-style\-keys](#helm-git-grep-use-ioccur-style-keys) @@ -167,6 +168,17 @@ If you don't want to search in submodules, Set only `helm-git-grep-source` like (setq helm-git-grep-sources '(helm-git-grep-source)) +#### `helm-follow-mode-persistent` + +Please set `helm-follow-mode-persistent` to non-nil if you want to use `helm-follow-mode` by default. + +You must set it before loading `helm-git-grep.el`. + +``` lisp +(custom-set-variables + '(helm-follow-mode-persistent t)) +``` + #### `helm-git-grep-candidate-number-limit` **(Default: `300`)** diff --git a/helm-git-grep.el b/helm-git-grep.el index c9a66af..7a9b97f 100644 --- a/helm-git-grep.el +++ b/helm-git-grep.el @@ -667,11 +667,14 @@ You can save your results in a helm-git-grep-mode buffer, see below. (defvar helm-git-grep-source (helm-make-source "Git Grep" 'helm-git-grep-class - :candidates-process 'helm-git-grep-process)) + :candidates-process 'helm-git-grep-process + :follow (and helm-follow-mode-persistent 1))) (defvar helm-git-grep-submodule-source (helm-make-source "Git Submodule Grep" 'helm-git-grep-class - :candidates-process 'helm-git-grep-submodule-grep-process)) + :candidates-process 'helm-git-grep-submodule-grep-process + :follow (and helm-follow-mode-persistent 1))) + (defun helm-git-grep-1 (&optional input) "Execute helm git grep. From 6a5879e90b70712ea14dae76a55711e8206483cb Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Sun, 24 Oct 2021 21:27:09 +0800 Subject: [PATCH 2/4] =?UTF-8?q?Fix=20=E2=80=98loop=E2=80=99=20=E2=80=98cas?= =?UTF-8?q?e=E2=80=99=20is=20an=20obsolete=20alias=20warn.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helm-git-grep.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-git-grep.el b/helm-git-grep.el index 7a9b97f..635a572 100644 --- a/helm-git-grep.el +++ b/helm-git-grep.el @@ -44,7 +44,7 @@ ;;; Code: -(eval-when-compile (require 'cl)) +(eval-when-compile (require 'cl-lib)) (require 'helm) (require 'helm-files) @@ -323,7 +323,7 @@ newline return an empty string." new-buf) (when (get-buffer buf) (setq new-buf (read-string prompt buf)) - (loop for b in (helm-buffer-list) + (cl-loop for b in (helm-buffer-list) when (and (string= new-buf b) (not (y-or-n-p (format "Buffer `%s' already exists overwrite? " @@ -358,7 +358,7 @@ if MARK is t, Set mark." (fname (or (with-current-buffer helm-buffer (get-text-property (point-at-bol) 'help-echo)) (nth 2 candidate)))) - (case where + (cl-case where (other-window (find-file-other-window fname)) (other-frame (find-file-other-frame fname)) (grep (helm-git-grep-save-results-1)) From 345fe3bd133a47f984956eca2c63804e75dda0ba Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Thu, 4 Nov 2021 13:39:46 +0800 Subject: [PATCH 3/4] When create helm git grep buffer, not promot buffer name, and just override it. --- helm-git-grep.el | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/helm-git-grep.el b/helm-git-grep.el index 635a572..99ad27d 100644 --- a/helm-git-grep.el +++ b/helm-git-grep.el @@ -318,22 +318,11 @@ newline return an empty string." (defun helm-git-grep-save-results-1 () "Save helm git grep result in a `helm-git-grep-mode' buffer." - (let ((prompt "GrepBufferName: ") - (buf "*hggrep*") - new-buf) - (when (get-buffer buf) - (setq new-buf (read-string prompt buf)) - (cl-loop for b in (helm-buffer-list) - when (and (string= new-buf b) - (not (y-or-n-p - (format "Buffer `%s' already exists overwrite? " - new-buf)))) - do (setq new-buf (read-string prompt "*hggrep "))) - (setq buf new-buf)) + (let ((buf "*helm-git-grep*") + (default-dir (helm-git-grep-base-directory))) (with-current-buffer (get-buffer-create buf) (setq buffer-read-only t) - (let ((default-dir (helm-git-grep-base-directory)) - (inhibit-read-only t)) + (let ((inhibit-read-only t)) (erase-buffer) (insert (format "-*- mode: grep; default-directory: \"%s\" -*-\n\n" default-dir) From 08d5d1a1560a6375b2cd675bb379877c6013953d Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Thu, 4 Nov 2021 13:44:18 +0800 Subject: [PATCH 4/4] Load wgrep directly when save result into helm git grep buffer if wgrep feature exists. --- helm-git-grep.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/helm-git-grep.el b/helm-git-grep.el index 99ad27d..70789f6 100644 --- a/helm-git-grep.el +++ b/helm-git-grep.el @@ -335,6 +335,8 @@ newline return an empty string." (buffer-substring (point) (point-max))))) (setq default-directory default-dir) (helm-git-grep-mode) + (if (fboundp 'wgrep-change-to-wgrep-mode) + (wgrep-change-to-wgrep-mode)) (pop-to-buffer buf))) (message "Helm Git Grep Results saved in `%s' buffer" buf)))