有一堆交互式函数将字符串输入作为参数:
(defun zb/run-cmd-X (arg1 argN)
(interactive "Marg1: Marg2: ")
;;; some logic
如何使每个这样的函数zb/run-cmd-1
..zb/run-cmd-N
有自己独立的输入参数历史arg1...argN
?如果这段历史在 Emacs 启动之间保持不变(理想情况下在外部文件的某个位置;用于同步),那将是完美的。
有没有现成的解决方案?
谢谢
基本上,您想阅读有关每个函数接受的参数read-from-minibuffer
的文档。当然还有其他功能支持历史记录,但这两个是标准/基本选项。completing-read
HIST
持久性由savehist
库提供,它写入文件中savehist-file
(默认情况下是~/.emacs.d/history
,但~/.emacs-history
如果该文件存在,将使用旧文件代替 - 在这种情况下,您可能希望将其重命名为现代首选路径)。
这是一个例子:
(defvar my-ssh-history nil)
(eval-after-load "savehist"
'(add-to-list 'savehist-additional-variables 'my-ssh-history))
(defun my-ssh (args)
"Connect to a remote host by SSH."
(interactive
(list (read-from-minibuffer "ssh " nil nil nil 'my-ssh-history)))
(let* ((switches (split-string-and-unquote args))
(name (concat "ssh " args))
(termbuf (apply 'make-term name "ssh" nil switches)))
(set-buffer termbuf)
(term-mode)
(term-char-mode)
(switch-to-buffer termbuf)))
(savehist-mode 1)