【发布时间】:2009-01-18 15:50:21
【问题描述】:
我经常使用 shell 命令(默认绑定到 M-!),但我经常对我当前正在编辑的缓冲区做一些事情。与其键入缓冲区名称(在 shell 命令中没有文件名补全功能,唉!),最好有一个快捷键,比如 f3,以便在我按下该键时为我插入该名称。
问题是我不想全局绑定密钥(我在其他上下文中将 f3 用于其他事情),仅在 shell 命令提示时在 minibuffer 中。编写一个 lisp 函数来插入当前缓冲区名称很容易,但是我应该修改什么模式的键映射以将键绑定到该函数?
或者,是否有任何 lisp 代码/包在 shell 命令中提供文件名补全,类似于 bash 的做法?我知道普通的 M-x shell 可以完成,但是在 minibuffer 中输入命令的便利性很难放弃;)
编辑:
这就是我想要的,取自 huaiyuan 的回答,其中一些修复灵感来自 http://osdir.com/ml/emacs.sources/2002-04/msg00022.html 的启发/被盗
(define-key minibuffer-local-map
[f3] (lambda () (interactive)
(insert (buffer-name (current-buffer-not-mini)))))
(defun current-buffer-not-mini ()
"Return current-buffer if current buffer is not the *mini-buffer*
else return buffer before minibuf is activated."
(if (not (window-minibuffer-p)) (current-buffer)
(if (eq (get-lru-window) (next-window))
(window-buffer (previous-window)) (window-buffer (next-window)))))
【问题讨论】:
标签: emacs