I'm generally using ido-switch-buffer
, but sometimes when there are too many candidates,
helm-buffers-list
is preferable. But it's a hassle to break out of ido,
call helm and re-enter the lost information.
So I wrote this code, that re-uses information entered in ido directly in helm:
(require 'helm-buffers)
(defun switch-to-helm-buffers-list ()
"Emulate `helm-buffers-list' call with ido contents as initial input."
(interactive)
(let ((str (minibuffer-contents-no-properties)))
(helm :sources '(helm-source-buffers-list
helm-source-ido-virtual-buffers
helm-source-buffer-not-found)
:buffer "*helm buffers*"
:keymap helm-buffer-map
:truncate-lines t
:input str)
;; (ido-exit-minibuffer)
))
(add-hook
'ido-setup-hook
(lambda()
(define-key ido-buffer-completion-map "\C-i"
'switch-to-helm-buffers-list)))
One problem is that ido is left to linger in the minibuffer.
When I add a call ido-exit-minibuffer
before helm
, it's not called.
And when I add it after, it resets the window configuration.
How can I solve this problem?
See answer https://stackoverflow.com/a/21165658/1937596
First, I patch your function a little.
(require 'helm-buffers)
(defun switch-to-helm-buffers-list ()
"Emulate `helm-buffers-list' call with ido contents as initial input."
(interactive)
(let ((str ido-text))
(helm :sources '(helm-source-buffers-list
helm-source-ido-virtual-buffers
helm-source-buffer-not-found)
:buffer "*helm buffers*"
:keymap helm-buffer-map
:truncate-lines t
:input str)
))
My recipe patches the body of function ido-buffer-internal
(internal for ido-switch-buffer
) too.
You have to execute this code once.
(eval
(read
(replace-regexp-in-string
"cond"
"cond ((eq ido-exit 'eab-ido-helm) (call-interactively 'switch-to-helm-buffers-list)) "
(save-window-excursion
(find-function-do-it 'ido-buffer-internal nil 'switch-to-buffer)
(let ((bgn (point)))
(forward-sexp)
(let ((end (point)))
(buffer-substring-no-properties bgn end)))))))
And I add one auxiliary function.
(defun eab/ido-helm ()
(interactive)
(setq ido-exit 'eab-ido-helm)
(exit-minibuffer))
Note, I use eab/ido-helm
instead of switch-to-helm-buffers-list
in define-key
.
(add-hook
'ido-setup-hook
(lambda()
(define-key ido-buffer-completion-map "\C-i"
'eab/ido-helm)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With