From 4f94446c0b8197d0617b0ed6a9f7360a9ea1f02f Mon Sep 17 00:00:00 2001 From: denin Date: Sun, 15 May 2016 12:55:07 +0300 Subject: [PATCH 1/2] add helm-multi-swoop-projectile function - move some common code to helm-multi-swoop--get-query function - add support for projectile; search in all opened buffers of the current project --- README.md | 8 ++++++ helm-swoop.el | 75 +++++++++++++++++++++++++-------------------------- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index fab87bd..c255a5e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ List match lines to another buffer, which is able to squeeze by any words you in * `C-u M-x helm-multi-swoop` apply last selected buffers from the second time * `M-x helm-multi-swoop-org` apply to all org-mode buffers * `M-x helm-multi-swoop-current-mode` apply to all buffers with the same major-mode as the current buffer +* `M-x helm-multi-swoop-projectile` Apply to all opened buffers of the current project * `M-x helm-swoop-same-face-at-point` list lines have the same face at the cursor is on * During isearch `M-i` to hand the word over to helm-swoop * During helm-swoop `M-i` to hand the word over to helm-multi-swoop-all @@ -59,6 +60,13 @@ Skip the select phase and apply to all org-mode buffers #### `M-x helm-multi-swoop-current-mode` Skip the select phase and apply to all buffers with the same major mode as the current buffer +#### `M-x helm-multi-swoop-projectile` +Skip the select phase and apply to all opened buffers of the current project. +It requires projectile to be installed. +You may specify a filter that will be used for buffers +by setting variable `helm-multi-swoop-projectile-buffers-filter`. +By default its value is `projectile-buffers-with-file-or-process`. + #### Multiline behavior `M-4 M-x helm-swoop` or `C-u 4 M-x helm-swoop` diff --git a/helm-swoop.el b/helm-swoop.el index e984533..3d4e44b 100644 --- a/helm-swoop.el +++ b/helm-swoop.el @@ -969,6 +969,8 @@ If $linum is number, lines are separated by $linum" (helm-exit-and-execute-action 'helm-multi-swoop--exec))) (delq nil $map))) +(defvar helm-multi-swoop-projectile-buffers-filter + #'projectile-buffers-with-file-or-process) ;; action ----------------------------------------------------- (defadvice helm-next-line (around helm-multi-swoop-next-line disable) @@ -1214,6 +1216,21 @@ If $linum is number, lines are separated by $linum" (match . ,(helm-swoop-match-functions)) (search . ,(helm-swoop-search-functions)))) +(defun helm-multi-swoop--get-query ($query) + (cond ($query + (setq helm-multi-swoop-query $query)) + (mark-active + (let (($st (buffer-substring-no-properties + (region-beginning) (region-end)))) + (if (string-match "\n" $st) + (message "Multi line region is not allowed") + (setq helm-multi-swoop-query + (helm-swoop-pre-input-optimize $st))))) + ((setq helm-multi-swoop-query + (helm-swoop-pre-input-optimize + (funcall helm-swoop-pre-input-function)))) + (t (setq helm-multi-swoop-query "")))) + ;;;###autoload (defun helm-multi-swoop (&optional $query $buflist) "\ @@ -1227,19 +1244,7 @@ If you have done helm-multi-swoop before, you can skip select buffers step. Last selected buffers will be applied to helm-multi-swoop. " (interactive) - (cond ($query - (setq helm-multi-swoop-query $query)) - (mark-active - (let (($st (buffer-substring-no-properties - (region-beginning) (region-end)))) - (if (string-match "\n" $st) - (message "Multi line region is not allowed") - (setq helm-multi-swoop-query - (helm-swoop-pre-input-optimize $st))))) - ((setq helm-multi-swoop-query - (helm-swoop-pre-input-optimize - (funcall helm-swoop-pre-input-function)))) - (t (setq helm-multi-swoop-query ""))) + (setq helm-multi-swoop-query (helm-multi-swoop--get-query $query)) (if (equal current-prefix-arg '(4)) (helm-multi-swoop--exec nil :$query helm-multi-swoop-query @@ -1256,19 +1261,7 @@ Last selected buffers will be applied to helm-multi-swoop. (defun helm-multi-swoop-all (&optional $query) "Apply all buffers to helm-multi-swoop" (interactive) - (cond ($query - (setq helm-multi-swoop-query $query)) - (mark-active - (let (($st (buffer-substring-no-properties - (region-beginning) (region-end)))) - (if (string-match "\n" $st) - (message "Multi line region is not allowed") - (setq helm-multi-swoop-query - (helm-swoop-pre-input-optimize $st))))) - ((setq helm-multi-swoop-query - (helm-swoop-pre-input-optimize - (funcall helm-swoop-pre-input-function)))) - (t (setq helm-multi-swoop-query ""))) + (setq helm-multi-swoop-query (helm-multi-swoop--get-query $query)) (helm-multi-swoop--exec nil :$query helm-multi-swoop-query :$buflist (helm-multi-swoop--get-buffer-list))) @@ -1286,19 +1279,7 @@ Last selected buffers will be applied to helm-multi-swoop. (defun helm-multi-swoop-by-mode ($mode &optional $query) "Apply all buffers whose mode is MODE to helm-multi-swoop" - (cond ($query - (setq helm-multi-swoop-query $query)) - (mark-active - (let (($st (buffer-substring-no-properties - (region-beginning) (region-end)))) - (if (string-match "\n" $st) - (message "Multi line region is not allowed") - (setq helm-multi-swoop-query - (helm-swoop-pre-input-optimize $st))))) - ((setq helm-multi-swoop-query - (helm-swoop-pre-input-optimize - (funcall helm-swoop-pre-input-function)))) - (t (setq helm-multi-swoop-query ""))) + (setq helm-multi-swoop-query (helm-multi-swoop--get-query $query)) (if (get-buffers-matching-mode $mode) (helm-multi-swoop--exec nil :$query helm-multi-swoop-query @@ -1317,6 +1298,22 @@ Last selected buffers will be applied to helm-multi-swoop. (interactive) (helm-multi-swoop-by-mode major-mode $query)) +;;;###autoload +(defun helm-multi-swoop-projectile (&optional $query) + "Apply all opened buffers of the current project to helm-multi-swoop" + (interactive) + (setq helm-multi-swoop-query (helm-multi-swoop--get-query $query)) + (if (require 'projectile nil 'noerror) + ;; set filter function that is used in projectile-project-buffers + (let ((projectile-buffers-filter-function + helm-multi-swoop-projectile-buffers-filter)) + (helm-multi-swoop--exec nil + :$query helm-multi-swoop-query + :$buflist (mapcar #'buffer-name + (projectile-project-buffers)))) + (error "Package 'projectile' is not available"))) + + (defun helm-swoop--wrap-function-with-pre-input-function ($target-func $pre-input-func) (let (($restore helm-swoop-pre-input-function)) (unwind-protect From bf3b88d24c18b0bdafdfebc88b98acc049469fe9 Mon Sep 17 00:00:00 2001 From: Shingo Fukuyama Date: Mon, 20 Jun 2016 01:40:55 +0900 Subject: [PATCH 2/2] Fix compile error --- helm-swoop.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helm-swoop.el b/helm-swoop.el index 3d4e44b..9a87c09 100644 --- a/helm-swoop.el +++ b/helm-swoop.el @@ -92,6 +92,9 @@ (require 'helm-grep) (declare-function migemo-search-pattern-get "migemo") +(declare-function projectile-buffers-with-file-or-process "projectile") +(declare-function projectile-project-buffers "projectile") +(defvar projectile-buffers-filter-function) ;;; @ helm-swoop ----------------------------------------------