ben*_*hsu 5 zsh emacs tab-completion
我正在学习 zsh 更强大的制表符补全和扩展功能,当我在带有 Mx shell 的 emacs 下运行 zsh 时,它们似乎不起作用:
cat $PATH<TAB>在终端中展开 tab 变量,但在 shell 模式下它只会发出蜂鸣声。
我浏览了 emacs 环境,发现如下:
TAB(翻译自 )运行completion-at-point 命令,这是“minibuffer.el”中的一个交互式编译的Lisp 函数。
它绑定到 TAB, 。
(完成点)
对点周围的文本执行补全。完成方法由“completion-at-point-functions”确定。
Completion-at-point-functions 是“minibuffer.el”中定义的变量。它的值为(tags-completion-at-point-function)
所以我猜测我需要向完成点函数添加一个函数,但是是哪一个呢?
您不能在 内部使用 shell 补全M-x shell。当您按 时,Emacs 一次将一行输入发送到 shell RET。当您按下 时TAB,会触发 Emacs 的内置完成功能。在 shell 模式下,Emacs 尝试跟踪当前目录并完成文件名,但仅此而已。
根据您所交互的程序,shell 模式可能很好(因为您可以获得 Emacs 的所有版本功能,而不是 shell 或其他程序提供的任何有限功能),也可能不太好(因为您无法获得任何漂亮的功能) shell 或其他程序提供的。当运行 zsh 时,您属于后一类。在 Emacs 内,您可以运行在M-x termEmacs 内运行更完整的终端模拟器,您可以在其中直接与底层程序交互。您获得了一些,但您也损失一些:Term模式的回滚能力很差。
您可以在同一缓冲区中在 Term 模式和 Shell 模式之间切换。您必须在 Term 模式下启动缓冲区,然后您可以使用这些函数在两者之间切换。(注:这些函数最初不是我写的,它是贡献给 Emacs Wiki 的,我还没有追踪到源代码。我稍微修改了它;警告:我还没有测试过这段代码。)
(defun term-switch-to-shell-mode ()
(interactive)
(shell-mode)
(set-process-filter
(get-buffer-process (current-buffer)) 'comint-output-filter )
(compilation-shell-minor-mode 1)
(comint-send-input))
(defun shell-switch-to-term-mode ()
(compilation-shell-minor-mode -1)
(font-lock-mode -1)
(set-process-filter
(get-buffer-process (current-buffer)) 'term-emulate-terminal)
(term-mode)
(term-char-mode)
(term-send-raw-string (kbd "C-l")))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5078 次 |
| 最近记录: |