[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/helm 2c02419a16 1/2: Allow searching in parent directory o
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/helm 2c02419a16 1/2: Allow searching in parent directory of current session (#2680) |
Date: |
Thu, 25 Jul 2024 10:00:38 -0400 (EDT) |
branch: elpa/helm
commit 2c02419a169fe5780e0eded811840dad5d97771b
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>
Allow searching in parent directory of current session (#2680)
---
helm-grep.el | 23 +++++++++++++++++++++--
helm-occur.el | 26 +++++++++++++++++++++++---
2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/helm-grep.el b/helm-grep.el
index c3c07bf44a..0508a8690a 100644
--- a/helm-grep.el
+++ b/helm-grep.el
@@ -1697,12 +1697,18 @@ returns if available with current AG version."
proc-name
(replace-regexp-in-string "\n" "" event))))))))))
+(defvar helm-grep-ag-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map helm-grep-map)
+ (define-key map (kbd "C-s") 'helm-grep-run-ag-grep-parent-directory)
+ map))
+
(defclass helm-grep-ag-class (helm-source-async)
((nohighlight :initform t)
(pcre :initarg :pcre :initform t
:documentation
" Backend is using pcre regexp engine when non--nil.")
- (keymap :initform 'helm-grep-map)
+ (keymap :initform 'helm-grep-ag-map)
(history :initform 'helm-grep-ag-history)
(help-message :initform 'helm-grep-help-message)
(filtered-candidate-transformer :initform #'helm-grep-fc-transformer)
@@ -1736,16 +1742,29 @@ If INPUT is provided, use it as the search string."
(format "%s [%s]"
name (abbreviate-file-name directory)))
:directory directory
+ :action (append helm-grep-actions
+ `((,(format "%s grep parent directory"
+ (upcase (helm-grep--ag-command)))
+ . helm-grep-ag-grep-parent-directory)))
:candidates-process
(lambda () (helm-grep-ag-init directory type))))
(helm-set-local-variable 'helm-input-idle-delay helm-grep-input-idle-delay)
(helm :sources 'helm-source-grep-ag
- :keymap helm-grep-map
:history 'helm-grep-ag-history
:input input
:truncate-lines helm-grep-truncate-lines
:buffer (format "*helm %s*" (helm-grep--ag-command))))
+(defun helm-grep-ag-grep-parent-directory (_candidate)
+ "Restart helm-grep-ag in the parent of the currently searched directory."
+ (let* ((src (with-helm-buffer (car helm-sources)))
+ (directory (helm-basedir (helm-get-attr 'directory src) t))
+ (input helm-pattern))
+ (helm-grep-ag-1 directory nil input)))
+
+(helm-make-command-from-action helm-grep-run-ag-grep-parent-directory
+ "Ag grep parent directory." 'helm-grep-ag-grep-parent-directory)
+
(defun helm-grep-ag (directory with-types)
"Start grep AG in DIRECTORY.
When WITH-TYPES is non-nil provide completion on AG types."
diff --git a/helm-occur.el b/helm-occur.el
index e8cd5060df..9e0bac2e10 100644
--- a/helm-occur.el
+++ b/helm-occur.el
@@ -53,6 +53,7 @@ Don't set it to any value, it will have no effect.")
(define-key map (kbd "C-c o") 'helm-occur-run-goto-line-ow)
(define-key map (kbd "C-c C-o") 'helm-occur-run-goto-line-of)
(define-key map (kbd "C-x C-s") 'helm-occur-run-save-buffer)
+ (define-key map (kbd "C-s") 'helm-run-occur-grep-ag-buffer-directory)
map)
"Keymap used in occur source.")
@@ -64,8 +65,7 @@ Don't set it to any value, it will have no effect.")
'(("Go to Line" . helm-occur-goto-line)
("Goto line other window (C-u vertically)" . helm-occur-goto-line-ow)
("Goto line new frame" . helm-occur-goto-line-of)
- ("Save buffer" . helm-occur-save-results)
- )
+ ("Save buffer" . helm-occur-save-results))
"Actions for helm-occur."
:type '(alist :key-type string :value-type function))
@@ -380,7 +380,10 @@ When GSHORTHANDS is nil use PATTERN unmodified."
;; Needed for resume.
:history 'helm-occur-history
:candidate-number-limit helm-occur-candidate-number-limit
- :action 'helm-occur-actions
+ :action (append helm-occur-actions
+ `((,(format "%s grep buffer directory"
+ (upcase (helm-grep--ag-command)))
+ . helm-occur-grep-ag-buffer-directory)))
:requires-pattern 2
:follow 1
:group 'helm-occur
@@ -523,6 +526,23 @@ persistent action."
(buffer-file-name (get-buffer it)))))
(when (and occur-fname (file-exists-p occur-fname))
(expand-file-name occur-fname))))
+
+(defun helm-occur-grep-ag-buffer-directory (_candidate)
+ "Start helm-grep-ag in the `default-directory' of currently searched buffer."
+ (let* ((src (with-helm-buffer
+ ;; Search from current source or fallback to the first
+ ;; source if helm-buffer is empty, if only one source
+ ;; we are right in either cases.
+ (or (helm-get-current-source)
+ (car helm-sources))))
+ (buf (helm-get-attr 'buffer-name src))
+ (directory (with-current-buffer buf
+ default-directory))
+ (input helm-pattern))
+ (helm-grep-ag-1 directory nil input)))
+
+(helm-make-command-from-action helm-run-occur-grep-ag-buffer-directory
+ "Ag grep buffer directory." 'helm-occur-grep-ag-buffer-directory)
;;; helm-occur-mode
;;