有很多交互式函数将字符串输入作为参数:
(defun zb/run-cmd-X (arg1 argN)
(interactive "Marg1: Marg2: ")
;;; some logic
如何制作每个这样的功能zb/run-cmd-1
..zb/run-cmd-N
have own输入参数的独立历史arg1...argN
?如果此历史记录在 Emacs 启动之间保持不变(最好是在外部文件中的某个位置;用于同步),那就完美了。
有没有现成的解决方案?
Thanks
基本上你想阅读文档read-from-minibuffer
and 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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)