我有一个常用于摘抄笔记时包裹代码的函数:
(defconst mp-org/src-code-types
'("emacs-lisp" "python" "c" "shell" "java" "js2" "clojure" "c++" "css" "go" "rust" "sh" "sass" "sql" "awk" "haskell" "latex" "lisp" "matlab" "org" "perl" "ruby" "scheme" "sqlite" "yaml"))
(defun mp-org/org-insert-src-code-block (src-code-type)
"Insert a `SRC-CODE-TYPE' type source code block in org-mode.
Go files should disable fly-check."
(interactive (list (ivy-completing-read "Source code type: " mp-org/src-code-types)))
(progn
(newline-and-indent)
(insert (format "#+BEGIN_SRC %s\n" src-code-type))
(newline-and-indent)
(insert "#+END_SRC\n")
(previous-line 2)
(org-edit-src-code)))
它先通过 ivy-completion-read 获取用户包裹的代码的类型,然后插入orgmode src注释。最近我发现一篇文章中的代码常常是同一类型的,每次调用这个函数都需要选择,过于麻烦。希望能简化它。
我当前是在该函数中保存选择到全局变量,然后用另一个函数直接使用该全局变量去执行。
现在,我想尝试直接让 ivy-completing-read 自己预先选择,求实现方式。