[英]Elisp interactive function with input history
有很多交互函数,它们将字符串输入作为参数:
(defun zb/run-cmd-X (arg1 argN)
(interactive "Marg1: Marg2: ")
;;; some logic
如何使每个这样的函数zb/run-cmd-1
.. zb/run-cmd-N
具有自己独立的输入参数arg1...argN
历史? 如果这段历史在Emacs启动之间保持不变(最好是在外部文件中的某个位置;用于同步),那将是完美的。
有没有现成的解决方案?
谢谢
基本上,您想completing-read
有关每个函数都接受的HIST
参数的HIST
completing-read
read-from-minibuffer
和read-from-minibuffer
read的文档。 当然,还有其他功能支持历史记录,但是这两个是标准/基本选项。
savehist
库提供了持久性,该库将在savehist-file
文件中savehist-file
(默认情况下为~/.emacs.d/history
,但是如果该文件存在,则将使用旧的~/.emacs-history
~/.emacs.d/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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.