如何使ESS中缓冲区顶部的R的当前提示与Control+;L在R控制台中
我已尝试将以下内容放入如何使ESS中缓冲区顶部的R的当前提示与Control+;L在R控制台中,r,emacs,elisp,ess,R,Emacs,Elisp,Ess,我已尝试将以下内容放入my.emacs文件中 (defun clear-shell () (interactive) (let ((old-max comint-buffer-maximum-size)) (setq comint-buffer-maximum-size 0) (comint-truncate-buffer) (setq comint-buffer-maximum-size old-max))) (global-set-key (kbd
my.emacs
文件中
(defun clear-shell ()
(interactive)
(let ((old-max comint-buffer-maximum-size))
(setq comint-buffer-maximum-size 0)
(comint-truncate-buffer)
(setq comint-buffer-maximum-size old-max)))
(global-set-key (kbd "\C-x c") 'clear-shell)
它工作了,但它也删除了我以前键入的所有命令。所以这不是我想要的。我只希望当前提示符>位于缓冲区的顶部,而不是删除我以前键入的任何命令
有人知道吗?对我来说
Esc-0 Ctr-l
似乎有效
`Ctrl-h k'输出为:
C-l runs the command recenter-top-bottom,
which is an interactive compiled Lisp function in window.el'.
根据Emacs手册:
Scroll the selected window so the current line is the
center-most text line; on subsequent consecutive invocations,
make the current line the top line, the bottom line, and so on in
cyclic order. Possibly redisplay the screen too (recenter-top-bottom).
这似乎完成了工作(尽管我实际上不确定这是否是你想要的): 编辑:或者这个
(defun clean-shell ()
(interactive)
(when (eq major-mode 'ess-mode) (other-window 1))
(mark-whole-buffer)
(exchange-point-and-mark)
(move-beginning-of-line 0)
(delete-region (region-beginning) (region-end))
(end-of-line)
)
C-l C-l有什么问题?它可以在任何缓冲区中工作 你是说Meta-0 Ctrl-l吗?不,在我的例子中,它实际上是
Esc
。但是是的,M-0 Ctrl-l
也可以。对我来说不起作用。。。但是对于OP,顺便说一句,这个命令绑定了什么?在你的ess模式下,Ctrl-l绑定了什么?顺便说一句,我认为这个Esc-0的定义并不重要,对大多数人来说,它与M-0或C-0一样(它只是一个数字参数
)。C-l运行命令recenter top-bottom,这是window.el中一个交互式编译的Lisp函数。`谢谢你的回答。但这不是我想要的。也许我没有说清楚。当我运行您提供的命令时,尽管提示符返回到缓冲区的顶部,但我看不到在运行命令之前键入的命令。换句话说。运行clean shell后提示的行号为1。但我希望它与运行clean shell之前的一样。谢谢。那到底需要清理什么呢?当我运行这个,并且在最后一行键入了一些内容时,在清理之后它仍然会在那里。或者你想让之前运行的东西也在那里?那么,最后一件事应该在那里?是的。我希望在此之前运行的东西也在那里。为了记录在案,您的代码的let
部分可以重写(let((comint buffer maximum size 0))(comint truncate buffer))
。如果您更改重新居中位置,则不会。我不是说它实际上没有删除任何东西。
(defun clean-shell ()
(interactive)
(when (eq major-mode 'ess-mode) (other-window 1))
(mark-whole-buffer)
(exchange-point-and-mark)
(move-beginning-of-line 0)
(delete-region (region-beginning) (region-end))
(end-of-line)
)