Skip to content

Commit

Permalink
Allow switching to more than one buffer (#861).
Browse files Browse the repository at this point in the history
* helm-utils.el (helm-switch-to-buffer): Removed, use switch-to-buffer instead.
(helm-switch-to-buffers,
helm-switch-to-buffers-other-window): New.

* helm-source.el: Update type buffer.
* helm-buffers.el: Update keymap, use switch-to-buffer.
* helm-apt.el : Use switch-to-buffer.
* helm-emms.el: Use switch-to-buffer.
* helm-files.el: Use switch-to-buffer.
* helm-gentoo.el: Use switch-to-buffer.
* helm-grep.el: Use switch-to-buffer.
* helm-ring.el: Use switch-to-buffer.
  • Loading branch information
thierryvolpiatto committed Feb 9, 2015
1 parent 07ef3c2 commit 1b48c0c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 24 deletions.
2 changes: 0 additions & 2 deletions helm-aliases.el
Expand Up @@ -505,8 +505,6 @@
(make-obsolete 'helm-c-bookmark-run-jump-other-window 'helm-bookmark-run-jump-other-window "1.5.1")
(defalias 'helm-c-elisp-library-scan-list 'helm-elisp-library-scan-list)
(make-obsolete 'helm-c-elisp-library-scan-list 'helm-elisp-library-scan-list "1.5.1")
(defalias 'helm-c-switch-to-buffer 'helm-switch-to-buffer)
(make-obsolete 'helm-c-switch-to-buffer 'helm-switch-to-buffer "1.5.1")
(defalias 'helm-c-bookmark-man-setup-alist 'helm-bookmark-man-setup-alist)
(make-obsolete 'helm-c-bookmark-man-setup-alist 'helm-bookmark-man-setup-alist "1.5.1")
(defalias 'helm-c-etags-find-tag-file-directory 'helm-etags-find-tag-file-directory)
Expand Down
2 changes: 1 addition & 1 deletion helm-apt.el
Expand Up @@ -200,7 +200,7 @@ package name - description."
(defun helm-apt-cache-show-1 (package)
(let* ((command (format helm-apt-show-command package))
(buf (get-buffer-create "*helm apt show*")))
(helm-switch-to-buffer buf)
(switch-to-buffer buf)
(unless (string= package helm-apt-show-current-package)
(let ((inhibit-read-only t))
(erase-buffer)
Expand Down
10 changes: 5 additions & 5 deletions helm-buffers.el
Expand Up @@ -203,7 +203,7 @@ Only buffer names are fuzzy matched when this is enabled,
(if mjm
(with-current-buffer buffer (funcall mjm))
(set-buffer-major-mode buffer))
(helm-switch-to-buffer buffer))))))
(switch-to-buffer buffer))))))

(defvar ido-temp-list)
(defvar ido-ignored-list)
Expand Down Expand Up @@ -535,7 +535,7 @@ If REGEXP-FLAG is given use `query-replace-regexp'."
for buf in bufs
do
(save-window-excursion
(helm-switch-to-buffer buf)
(switch-to-buffer buf)
(save-excursion
(let ((case-fold-search t))
(goto-char (point-min))
Expand Down Expand Up @@ -648,7 +648,7 @@ If REGEXP-FLAG is given use `query-replace-regexp'."
"Run switch to other window action from `helm-source-buffers-list'."
(interactive)
(with-helm-alive-p
(helm-quit-and-execute-action 'switch-to-buffer-other-window)))
(helm-quit-and-execute-action 'helm-switch-to-buffers-other-window)))

(defun helm-buffer-switch-other-frame ()
"Run switch to other frame action from `helm-source-buffers-list'."
Expand Down Expand Up @@ -714,7 +714,7 @@ If REGEXP-FLAG is given use `query-replace-regexp'."
(defun helm-buffers-list-persistent-action (candidate)
(if current-prefix-arg
(helm-buffers-persistent-kill candidate)
(helm-switch-to-buffer candidate)))
(switch-to-buffer candidate)))

(defun helm-ediff-marked-buffers (_candidate &optional merge)
"Ediff 2 marked buffers or CANDIDATE and `helm-current-buffer'.
Expand Down Expand Up @@ -794,7 +794,7 @@ displayed with the `file-name-shadow' face if available."
(define-helm-type-attribute 'buffer
`((action
. ,(helm-make-actions
"Switch to buffer" 'helm-switch-to-buffer
"Switch to buffer" 'switch-to-buffer
(lambda () (and (locate-library "popwin") "Switch to buffer in popup window"))
'popwin:popup-buffer
"Switch to buffer other window `C-c o'" 'switch-to-buffer-other-window
Expand Down
2 changes: 1 addition & 1 deletion helm-emms.el
Expand Up @@ -62,7 +62,7 @@
(emms-stream-add-bookmark name url (string-to-number fd) type)
(emms-stream-save-bookmarks-file)
(emms-stream-quit)
(helm-switch-to-buffer cur-buf)))))
(switch-to-buffer cur-buf)))))

(defun helm-emms-stream-delete-bookmark (_candidate)
"Delete emms-streams bookmarks from helm."
Expand Down
4 changes: 2 additions & 2 deletions helm-files.el
Expand Up @@ -729,7 +729,7 @@ See `helm-find-files-eshell-command-on-file-1' for more info."
(format "cd '%s'" helm-ff-default-directory))
(eshell-send-input))))
(if (get-buffer "*eshell*")
(helm-switch-to-buffer "*eshell*")
(switch-to-buffer "*eshell*")
(call-interactively 'eshell))
(unless (get-buffer-process (current-buffer))
(funcall cd-eshell))))
Expand Down Expand Up @@ -2097,7 +2097,7 @@ If a prefix arg is given or `helm-follow-mode' is on open file."
(make-directory image-dired-dir))
(image-dired-display-image candidate)
(message nil)
(helm-switch-to-buffer image-dired-display-image-buffer)
(switch-to-buffer image-dired-display-image-buffer)
(with-current-buffer image-dired-display-image-buffer
(let ((exif-data (helm-ff-exif-data candidate)))
(setq default-directory helm-ff-default-directory)
Expand Down
6 changes: 3 additions & 3 deletions helm-gentoo.el
Expand Up @@ -102,7 +102,7 @@
"Gentoo default action that use `helm-gentoo-buffer'."
(if (member elm helm-cache-world)
(progn
(helm-switch-to-buffer helm-gentoo-buffer)
(switch-to-buffer helm-gentoo-buffer)
(erase-buffer)
(let ((com-list (append args (list elm))))
(apply #'call-process command nil t nil
Expand All @@ -120,7 +120,7 @@
(candidate-transformer helm-highlight-local-use)
(action . (("Description"
. (lambda (elm)
(helm-switch-to-buffer helm-gentoo-buffer)
(switch-to-buffer helm-gentoo-buffer)
(erase-buffer)
(apply #'call-process "euse" nil t nil
`("-i"
Expand All @@ -138,7 +138,7 @@
(helm-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
("Show which dep use this flag"
. (lambda (elm)
(helm-switch-to-buffer helm-gentoo-buffer)
(switch-to-buffer helm-gentoo-buffer)
(erase-buffer)
(apply #'call-process "equery" nil t nil
`("-C"
Expand Down
2 changes: 1 addition & 1 deletion helm-grep.el
Expand Up @@ -1020,7 +1020,7 @@ If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
(helm-do-grep-1 bufs))
;; bufs is empty, thats mean we have only CANDIDATE
;; and it is not a buffer-filename, fallback to occur.
(helm-switch-to-buffer candidate)
(switch-to-buffer candidate)
(when (get-buffer helm-action-buffer)
(kill-buffer helm-action-buffer))
(helm-occur)
Expand Down
4 changes: 2 additions & 2 deletions helm-ring.el
Expand Up @@ -176,11 +176,11 @@ replace with STR as yanked string."
(action . (("Goto line"
. (lambda (candidate)
(let ((items (split-string candidate ":")))
(helm-switch-to-buffer (cl-second items))
(switch-to-buffer (cl-second items))
(helm-goto-line (string-to-number (car items))))))))
(persistent-action . (lambda (candidate)
(let ((items (split-string candidate ":")))
(helm-switch-to-buffer (cl-second items))
(switch-to-buffer (cl-second items))
(helm-goto-line (string-to-number (car items)))
(helm-highlight-current-line))))
(persistent-help . "Show this line")))
Expand Down
5 changes: 3 additions & 2 deletions helm-source.el
Expand Up @@ -754,10 +754,11 @@ like `re-search-forward', see below documentation of :search slot.")

(defmethod helm--setup-source :before ((source helm-type-buffer))
(oset source :action (helm-make-actions
"Switch to buffer" 'helm-switch-to-buffer
"Switch to buffer(s)" 'helm-switch-to-buffers
(lambda () (and (locate-library "popwin") "Switch to buffer in popup window"))
'popwin:popup-buffer
"Switch to buffer other window `C-c o'" 'switch-to-buffer-other-window
"Switch to buffer(s) other window `C-c o'"
'helm-switch-to-buffers-other-window
"Switch to buffer other frame `C-c C-o'" 'switch-to-buffer-other-frame
(lambda () (and (locate-library "elscreen") "Display buffer in Elscreen"))
'helm-find-buffer-on-elscreen
Expand Down
32 changes: 27 additions & 5 deletions helm-utils.el
Expand Up @@ -190,11 +190,33 @@ Return nil if DIR is not an existing directory."
when printer
collect printer))))

;; Shut up byte compiler in emacs24*.
(defun helm-switch-to-buffer (buffer-or-name)
"Same as `switch-to-buffer' whithout warnings at compile time."
(with-no-warnings
(switch-to-buffer buffer-or-name)))
(defun helm-switch-to-buffers (buffer-or-name &optional other-window)
"Switch to buffer BUFFER-OR-NAME.
If more than one buffer marked switch to these buffers in separate windows.
If OTHER-WINDOW is specified keep current-buffer and switch to others buffers
in separate windows."
(let* ((mkds (helm-marked-candidates))
(size (/ (window-height) (length mkds))))
(or (<= window-min-height size)
(error "Too many buffers to visit simultaneously."))
(helm-aif (cdr mkds)
(progn
(if other-window
(switch-to-buffer-other-window (car mkds))
(switch-to-buffer (car mkds)))
(save-selected-window
(cl-loop for b in it
do (progn
(select-window (split-window))
(switch-to-buffer b)))))
(if other-window
(switch-to-buffer-other-window buffer-or-name)
(switch-to-buffer buffer-or-name)))))

(defun helm-switch-to-buffers-other-window (buffer-or-name)
"switch to buffer BUFFER-OR-NAME in other window.
See `helm-switch-to-buffers' for switching to marked buffers."
(helm-switch-to-buffers buffer-or-name t))

(cl-defmacro helm-position (item seq &key (test 'eq) all)
"A simple and faster replacement of CL `position'.
Expand Down

0 comments on commit 1b48c0c

Please sign in to comment.