gpt4 book ai didi

r - ESS:从以 ESS[R] 劣等模式或脚本输入的命令检索命令历史记录

转载 作者:行者123 更新时间:2023-12-03 23:25:06 24 4
gpt4 key购买 nike

在劣等模式下使用 ESS[R] 时,我可以使用 C-c C-p 检索最近的命令输出,将光标移动到上一个命令输出。或者,我可以使用 C-up,它基本上从劣等进程复制最近输入的命令(类似于 readline 的工作方式)。我更喜欢 C-up 方法,但不幸的是它不会检索使用任何 ess-eval 命令从脚本输入的命令。对于在劣等模式和 ess-eval 中输入的命令,是否可以获得 C-up 的功能?

最佳答案

您的解决方案适用于单行命令,但需要稍作调整来处理多行语句:

(defun ess-readline ()
"Move to previous command entered from script *or* R-process and copy
to prompt for execution or editing"
(interactive)
;; See how many times function was called
(if (eq last-command 'ess-readline)
(setq ess-readline-count (1+ ess-readline-count))
(setq ess-readline-count 1))
;; Move to prompt and delete current input
(comint-goto-process-mark)
(end-of-buffer nil) ;; tweak here
(comint-kill-input)
;; Copy n'th command in history where n = ess-readline-count
(comint-previous-prompt ess-readline-count)
(comint-copy-old-input)
;; Below is needed to update counter for sequential calls
(setq this-command 'ess-readline)
)
(global-set-key (kbd "\C-cp") 'ess-readline)

这使您可以向上移动以前的命令;以下功能使您可以再次向下移动,因此您可以上下移动以找到您所追求的命令:
(defun ess-readnextline ()
"Move to next command after the one currently copied to prompt and copy
to prompt for execution or editing"
(interactive)
;; Move to prompt and delete current input
(comint-goto-process-mark)
(end-of-buffer nil)
(comint-kill-input)
;; Copy (n - 1)'th command in history where n = ess-readline-count
(setq ess-readline-count (max 0 (1- ess-readline-count)))
(when (> ess-readline-count 0)
(comint-previous-prompt ess-readline-count)
(comint-copy-old-input))
;; Update counter for sequential calls
(setq this-command 'ess-readline)
)
(global-set-key (kbd "\C-cn") 'ess-readnextline)

关于r - ESS:从以 ESS[R] 劣等模式或脚本输入的命令检索命令历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27307757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com