簡體   English   中英

Emacs:如何打破ido迷你冰箱?

[英]Emacs: how to break out of ido minibuffer?

我通常使用ido-switch-buffer ,但有時當候選人太多時,最好使用helm-buffers-list 但是打破偶像,召喚掌舵並重新輸入丟失的信息是一件麻煩事。

所以我編寫了這段代碼,它直接在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留在迷你緩沖區中。 當我在helm之前添加一個call ido-exit-minibuffer ,它不會被調用。 當我在之后添加它時,它會重置窗口配置。 我怎么解決這個問題?

請參閱答案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-internalido-switch-buffer內部)的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))

注意,我在define-key使用eab/ido-helm而不是switch-to-helm-buffers-list

(add-hook
 'ido-setup-hook
 (lambda()
   (define-key ido-buffer-completion-map "\C-i"
     'eab/ido-helm)))

這就是我想出的。 無需修補。

(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)) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM