branch: elpa/helm commit 607cbfabc62a48d61c465bdfe9fc08839c0a4490 Author: Thierry Volpiatto <thie...@posteo.net> Commit: Thierry Volpiatto <thie...@posteo.net>
New var to handle quit-and-find-file-fn when these can't be added in source (helm-generic sources). --- helm-buffers.el | 1 + helm-mode.el | 5 +++++ helm-utils.el | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/helm-buffers.el b/helm-buffers.el index 0b6c90e5b6..fd040850ef 100644 --- a/helm-buffers.el +++ b/helm-buffers.el @@ -1110,6 +1110,7 @@ Can be used by any source that list buffers." (cl-assert (not helm-buffers-in-project-p) nil "You are already browsing this project")) +;;;###autoload (defun helm-buffers-quit-and-find-file-fn (source) (let* ((sel (get-buffer (helm-get-selection nil nil source))) (bname (and (bufferp sel) (buffer-name sel)))) diff --git a/helm-mode.el b/helm-mode.el index a68272f2fd..6a8ecfe975 100644 --- a/helm-mode.el +++ b/helm-mode.el @@ -255,6 +255,11 @@ This is mainly needed to prevent \"*Completions*\" buffers to popup.") Not guaranteed to work with Emacs < 27." :type 'boolean :group 'helm-mode) + +(defvar helm-mode-find-file-target-alist + '(("switch-to-buffer" . helm-buffers-quit-and-find-file-fn)) + "An alist composed of (SOURCE_NAME . FUNCTION) elements. +Where FUNCTION is a function suitable for `helm-quit-and-find-file'.") (defface helm-mode-prefix `((t ,@(and (>= emacs-major-version 27) '(:extend t)) diff --git a/helm-utils.el b/helm-utils.el index 2c64d303bb..3fc02544ff 100644 --- a/helm-utils.el +++ b/helm-utils.el @@ -596,7 +596,9 @@ from its directory." (put 'helm-quit-and-find-file 'helm-only t) (defun helm--quit-and-find-file-default-file (source) - (let ((target-fn (helm-get-attr 'find-file-target source))) + (let ((target-fn (or (helm-get-attr 'find-file-target source) + (assoc-default (helm-get-attr 'name source) + helm-mode-find-file-target-alist)))) ;; target-fn function may return nil, in this case fallback to default. (helm-aif (and target-fn (funcall target-fn source)) it