代码之家  ›  专栏  ›  技术社区  ›  EoghanM

Emacs模式:“命令试图在minibuffer中使用minibuffer”

  •  12
  • EoghanM  · 技术社区  · 17 年前

    • 我开始键入M-x以键入命令
    • 我切换到另一个emacs窗口/缓冲区,因为我意识到我在错误的窗口中执行命令

    结果:我得到了可怕的“命令试图在minibuffer中使用minibuffer”

    The Humane Interface

    有没有办法自定义emacs行为,这样它就不用给出这个错误,而是取消第一个迷你缓冲区,并用一个新的迷你缓冲区替换它?

    6 回复  |  直到 17 年前
        1
  •  7
  •   Trey Jackson    17 年前

    您可以设置变量 enable-recursive-minibuffers

    M-x 'execute-extended-command ,并且为该命令重新托管(更改原始缓冲区)类似于使用continuation进行编程。i、 你从位置X调用一个子程序,但是当完成后你没有返回到X,而是返回到Y。我个人认为这会带来更多的混乱,而不是解决问题。但我理解这种挫折感(也知道其他人也有同样的挫折感)。

        2
  •  6
  •   octi    14 年前

    事实上,这个emacs“特性”是咄咄逼人和令人讨厌的。 我发现这是问题的正确答案。很可能是因为你用鼠标而不是minibuffer命令切换窗口,所以你失去了minibuffer的焦点。因此,每当您使用鼠标失去焦点时,小缓冲区将被清除。查看这篇文章。它对我来说很有效,而且比递归的迷你缓冲区要好得多,这会让人头疼

    http://trey-jackson.blogspot.com/2010/04/emacs-tip-36-abort-minibuffer-when.html

        3
  •  5
  •   Brian Campbell Dennis Williamson    17 年前

    我不确定是否有这样的定制,但我避免这种情况的方法是 控制键 要取消这个命令,我正在写一个小布告板。

        4
  •  4
  •   Trey Jackson    17 年前

    因为我的第一个答案并不能直接给出你想要的,所以我想我会想出一个真正的解决办法。这就是我所拥有的:

    (defvar my-execute-extended-command-source-buffer nil
      "var holding the buffer to which the extended-execute-command should apply")
    (defvar in-my-execute-extended-command nil
      "internal use - indicates whether we're in a 'recursive edit' of sorts")
    (defun my-execute-extended-command (command)
      "home-grown version of execute-extended-command that supports re-hosting the buffer"
      (interactive (list (if in-my-execute-extended-command
                       nil
                     (let ((in-my-execute-extended-command t))
                       (setq my-execute-extended-command-source-buffer (current-buffer))
                       (completing-read "My-x " obarray 'commandp t nil 'extended-command-history nil nil)))))
      (if in-my-execute-extended-command
          (progn (setq my-execute-extended-command-source-buffer (current-buffer))
                 (select-window (minibuffer-window)))
        (switch-to-buffer my-execute-extended-command-source-buffer)
        (call-interactively (symbol-function (intern command)))))
    

    F10 就我而言,我不想失去信用证 M-x )。然后,打开两个窗口,每个窗口显示不同的缓冲区(例如a和B):

    1. F10 isearch-for
    2. 从minibuffer切换到显示以下内容的窗口: C-x o
    3. 从显示A的窗口切换到显示B的窗口: C-xo
    4. “重新承载”来自缓冲区B的命令: F10
    5. 现在回到minibuffer,完成命令 ward RET

    这只会取代 M-x 功能,而不是从中调用的命令 M-x . 此外,此版本不支持前缀参数。

        5
  •  2
  •   EoghanM    17 年前

    谁能在以下方面有所改进?

    我已经放弃,只想在打开新的迷你缓冲区之前设置\C-w以取消以前的任何迷你缓冲区(如执行\C-g\C-w)

    (defun cancel-completing-read ()
      (if (> (minibuffer-depth) 0) (exit-minibuffer))
       (completing-read "My-x " obarray 'commandp t nil 'extended-command-history nil nil))
    
    (defun cancel-and-execute-command (command)
      (interactive (list (cancel-completing-read)))
      (call-interactively (symbol-function (intern command))))
    
    (global-set-key "\M-x" 'cancel-and-execute-command)
    

    我应该使用什么命令来代替 exit-minibuffer 在上面

    我试过了

    keyboard-escape-quit
    exit-minibuffer
    keyboard-quit
    
        6
  •  2
  •   cyisfor    10 年前

    干得好:

    ;; automatically cancel the minibuffer when you switch to it, to avoid
    ;; "attempted to use minibuffer" error.
    ;; cy was here
    
    (provide 'cancel-minibuffer)
    
    (defun cancel-minibuffer-first (sub-read &rest args)
        (let ((active (active-minibuffer-window)))
            (if active
                    (progn
                        ;; we have to trampoline, since we're IN the minibuffer right now.
                        (apply 'run-at-time 0 nil sub-read args)
                        (abort-recursive-edit))
                (apply sub-read args))))
    
    (advice-add 'read-from-minibuffer :around #'cancel-minibuffer-first)