我如果想打开列表中的一个文件,这个文件通过输入选择,这个输入选择lisp怎么写呢
(defun quick-open-svn-diff-config()
(interactive)
(find-file (list “d:/work/tools/SvnSyncTool/svn_diff_config.json” “d:/work/tools/SvnSyncTool/svn_diff_config1.json”))
)
例如上面代码:我想通过函数 quick-open-svn-diff-config来快速打开 列表中的某个文件,这个文件通过输入匹配的方式来选择,选择后触发find-file调用
用 helm source 或 ivy-read, 参考 如何把用户输入添加到 helm/ivy 候选列表中?
1 个赞
用 completing-read
:
(find-file (completing-read "Find File: " (list "file1" "file2")))
1 个赞
感谢大家回复结合 @xuchunyang @twlz0ne 如下
(defun quick-open-svn-diff-config()
(interactive)
(let ((default-candidates '("D:/work/client/sync_newbie/SvnSyncTool/svn_diff_config.json"
"d:/work/tools/SvnSyncTool/svn_diff_config.json"))
(user-input-indicator "[?] "))
(helm :sources
(helm-build-sync-source "Test"
:candidates default-candidates
:action
(lambda (candidate)
(find-file
(if (string-prefix-p user-input-indicator candidate)
helm-pattern
candidate))
:filtered-candidate-transformer
(lambda (candidates _source)
(if (not (string-empty-p helm-pattern))
(if (member helm-pattern default-candidates)
candidates
(cons (concat user-input-indicator helm-pattern) candidates))
candidates))
))))
)