[英]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.