正如文档所说, RET 将comint-send-input
在 shell 模式下的任何地方。问题是,如果您错误地在任何行上按了 Enter 键,并且您没有收到提示,它将执行整个随机文本,直到下一个提示。我怎样才能防止这种情况发生?如果点击Enter
提示之外的任何地方会将您发送到底部的新提示,那就太好了。
像这样的东西?
(defun my-comint-send-input-maybe ()
"Only `comint-send-input' when point is after the latest prompt.
Otherwise move to the end of the buffer."
(interactive)
(let ((proc (get-buffer-process (current-buffer))))
(if (and proc (>= (point) (marker-position (process-mark proc))))
(comint-send-input)
(goto-char (point-max)))))
(with-eval-after-load "comint"
(define-key shell-mode-map [remap comint-send-input] 'my-comint-send-input-maybe))
Run Code Online (Sandbox Code Playgroud)
你可以替换(goto-char (point-max))
使用(comint-copy-old-input)
,以插入但不派在新的提示旧输入; 但是当插入的输入看起来像输出时,这仍然容易引起问题。
然而,也注意到在评论和链接C-hf comint-send-input
有关comint-get-old-input
-这可以被用来实现自定义的逻辑建立在“旧输入”应该是什么comint-send-input
与进程标记之前点调用。
归档时间: |
|
查看次数: |
275 次 |
最近记录: |