为什么我的term-mode-hook没有选择行模式?

Dic*_*eed 4 emacs elisp

我写了这个elisp函数:

(defun run (command)
  "Open a terminal running a command."
  (interactive "sCommand: ")
  (if (buffer-exists (concat "*" command "*" )) (kill-buffer (concat "*" command "*")))
  (let ((term-mode-hook (cons (lambda () (term-line-mode)) term-mode-hook)))
    (ansi-term (cons "sh" (cons "-i" (list "-c" command))) command)))
Run Code Online (Sandbox Code Playgroud)

这很好用,除了新的ansi-term缓冲区仍然是char模式(这是默认值),所以据我所知,term-line-mode调用没有做任何事情.如果我用(消息"foo")替换(term-line-mode),我确实在消息缓冲区中看到了消息.

lisp/term.el中term-line-mode的定义是:

(defun term-line-mode  ()
  "Switch to line (\"cooked\") sub-mode of term mode.
This means that Emacs editing commands work as normally, until
you type \\[term-send-input] which sends the current line to the inferior."
  (interactive)
  (when (term-in-char-mode)
    (use-local-map term-old-mode-map)
    (term-update-mode-line)))
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

zev*_*zev 5

我无法在任何术语钩子中使用"term-line-mode"来工作; 但是,如果您建议"ansi-term"功能,它确实有效:

(defadvice ansi-term (after advice-term-line-mode activate)
  (term-line-mode))
Run Code Online (Sandbox Code Playgroud)