我通常使用ido-switch-buffer
,但有时当候选人太多时,
helm-buffers-list
更可取。但是打破偶像是一件麻烦事,
打电话给helm并重新输入丢失的信息。
所以我编写了这段代码,它直接在helm中重新使用ido中输入的信息:
(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)))
一个问题是ido留在迷你缓冲区中。
当我在ido-exit-minibuffer
之前添加电话helm
时,不会调用它。
当我在之后添加它时,它会重置窗口配置。
我怎么解决这个问题?
答案 0 :(得分:2)
请参阅回答https://stackoverflow.com/a/21165658/1937596
首先,我修补你的功能。
(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)
))
我的食谱也修复了函数体ido-buffer-internal
(ido-switch-buffer
的内部)。
您必须执行一次此代码。
(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)))))))
我添加了一个辅助功能。
(defun eab/ido-helm ()
(interactive)
(setq ido-exit 'eab-ido-helm)
(exit-minibuffer))
注意,我在eab/ido-helm
中使用switch-to-helm-buffers-list
代替define-key
。
(add-hook
'ido-setup-hook
(lambda()
(define-key ido-buffer-completion-map "\C-i"
'eab/ido-helm)))
答案 1 :(得分:1)
这就是我想出的。无需修补。
(define-key ido-buffer-completion-map "\C-i" 'ido-buffer-helm)
(defvar ibh-initial nil)
(defun ibh-hook ()
(when ibh-initial
(let ((str ibh-initial))
(setq ibh-initial)
(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)))
(remove-hook 'post-command-hook 'ibh-hook))
(require 'delsel)
(defun ido-buffer-helm ()
(interactive)
(setq ibh-initial ido-text)
(add-hook 'post-command-hook 'ibh-hook)
(minibuffer-keyboard-quit))