Skip to content

Commit

Permalink
Merge branch 'dvzubarev-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Shingo Fukuyama authored and Shingo Fukuyama committed Jun 19, 2016
2 parents fd01dac + bf3b88d commit fa09a17
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`

Expand Down
78 changes: 39 additions & 39 deletions helm-swoop.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------

Expand Down Expand Up @@ -969,6 +972,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)
Expand Down Expand Up @@ -1214,6 +1219,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)
"\
Expand All @@ -1227,19 +1247,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
Expand All @@ -1256,19 +1264,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)))
Expand All @@ -1286,19 +1282,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
Expand All @@ -1317,6 +1301,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
Expand Down

0 comments on commit fa09a17

Please sign in to comment.