如何在ESS中将缓冲区顶部的R当前提示设置为与R控制台中的Control + L一样

时间:2013-01-13 08:05:34

标签: 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 "\C-x c") 'clear-shell)

它有效,但它也删除了我之前输入的所有命令。所以这不是我想要的。我只想要当前的提示>在缓冲区的顶部,不要删除我之前输入的任何命令。

有人知道吗?

3 个答案:

答案 0 :(得分:2)

对我来说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手册中的this page

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

答案 1 :(得分:0)

这似乎完成了工作(虽然我实际上并不确定这是否是你所追求的):

(defun clean-shell ()
 (interactive)

 ; if you call this from your .r script, it will switch to the next window
 (when (eq major-mode 'ess-mode) (other-window 1))   

 (mark-whole-buffer)
 (exchange-point-and-mark)
 (move-beginning-of-line 1)
 (delete-region (region-beginning) (region-end))
 (end-of-line)
)
编辑:或许这个?

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

答案 2 :(得分:0)

C-l C-l 有什么问题?它适用于任何缓冲区。