Helm: Create -switch-other-window switcher

master
Pierre Neidhardt 2019-02-25 18:19:51 +01:00
parent 89768b8940
commit 00e88429ae
1 changed files with 16 additions and 5 deletions

View File

@ -30,7 +30,12 @@
:persistent-action 'helm-buffers-list-persistent-action)
,@extra-sources
(helm-build-dummy-source ,(format "Open new %s" name)
:action (helm-make-actions ,(format "Open new %s" name) ',new-fn)))
:action (helm-make-actions
,(format "Open new %s" name) ',new-fn
,(format "Open new %s in new window" name)
(lambda (args)
(let ((buffer (save-window-excursion (funcall ,new-fn args))))
(switch-to-buffer-other-window buffer))))))
:buffer ,(format "*helm-%s-buffers*" name)))))
(defmacro helm-defswitcher (name predicate new-fn &optional extra-sources)
@ -41,16 +46,22 @@ See `eshell' for the numeric prefix ARG."
(let ((mode (intern (format "%s-mode" (downcase name)))))
`(progn
(helm-deflister ,name ,predicate ,new-fn ,extra-sources)
(defun ,(intern (format "helm-%s-switch" (downcase name))) (&rest arg)
(defun ,(intern (format "helm-%s-switch" (downcase name))) (&optional menu other-window)
(interactive "P")
(if (or arg (derived-mode-p ',mode))
(if (or menu (derived-mode-p ',mode))
;; TODO: Funcall the return value of helm-deflister.
(funcall ',(intern (format "helm-%s-buffers" (downcase name))))
(let ((last (cl-loop for buffer in (buffer-list)
when (funcall ,predicate buffer)
return buffer)))
(if last
(switch-to-buffer last)
(funcall ,new-fn))))))))
(if (get-buffer-window last)
(select-window (get-buffer-window last))
(funcall (if other-window 'switch-to-buffer-other-window 'switch-to-buffer) last))
(funcall ,new-fn)))))
(defun ,(intern (format "helm-%s-switch-other-window" (downcase name))) (&optional menu)
(interactive "P")
(funcall ',(intern (format "helm-%s-switch" (downcase name)))
menu 'other-window)))))
(provide 'patch-helm)