Why is my term-mode-hook not selecting line mode?

ⅰ亾dé卋堺 提交于 2019-12-23 12:28:47

问题


I wrote this elisp function:

(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)))

This works nicely except that the new ansi-term buffers remains in char mode (which is the default), so as far as I can tell the term-line-mode call is not doing anything. If I replace (term-line-mode) with (message "foo") I do see the message in the messages buffer.

The definition of term-line-mode in lisp/term.el is:

(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)))

What am I doing wrong?


回答1:


I wasn't able to get "term-line-mode" to work as you want in any of the term hooks; however, it does work if you advise the "ansi-term" function:

(defadvice ansi-term (after advice-term-line-mode activate)
  (term-line-mode))


来源:https://stackoverflow.com/questions/6816877/why-is-my-term-mode-hook-not-selecting-line-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!