自己写的第一个lisp功能
缘起
写文档的时候会写到 elisp-symbol 这样的内容,通过cape完成了补全。但是如果在symbol的开始加了 = 则无法自动补全,之前是弄了个 (backward-symbol)
写功能
第一版
思路
越来越觉得,编程的难点之一是将想法通过代码实现。但是对主要的难点还是将要解决的问题通过流程的思路来解决,也就是将现实的问题进行分解,提出解决的思路,或者说用高级的说法:算法。
我的想法就是在我通过 corfu 等补全输入相关的内容后,直接完成前后两个等号的输入。因为动作的起点是完成代码内容后,所以第一个动作应该是输入一个 = ,也就是最后的那个 =
- 输入句末的
= - 回到 symbol 的开始。
- 再输入一个
= - 回到句末,再输入一个空格。
经过分析之后,我发觉以我目前的知识能力完成可以完成这个代码的编辑。因此有了下面这个代码。
代码
(defun wrap-equation () "wrap the code with '='" (interactive) (insert "=") (forward-symbol -1) (insert "=") (forward-symbol 1) (insert " "))
第二版
使用 forward-whitespace 来替代 forward-symbol 。 forward-whitespace 的或中通是回到上一个空格处。
(defun wrap-equation () "wrap the code with '='" (interactive) (insert "=") (forward-whitespace -1) (forward-char) (insert "=") (end-of-line) (insert " "))
然后马上有了第二个
第一版
(defun hugo-heading () "Create id for the current heading. Set a hugofilename property" (interactive) (setq hugo (read-string "Enter name:")) ;(message "String is %s" hugo) (org-id-get-create) (org-set-property "FILENAME" hugo))
第二版
(defun hugo-heading () "Create id for the current heading. Set a hugofilename property" (interactive) (let ( (hugo (read-string "Enter name:"))) ; (message "String is %s" hugo) (org-id-get-create) (org-set-property "FILENAME" hugo)))
第三版
(defun hugo-heading (filename) "Create id for the current heading. Set a hugofilename property" (interactive "MEnter file name:") (org-id-get-create) (org-set-property "EXPORT_FILE_NAME" filename))
第三个
第一版
(defun file2FileSys() (interactive) (search-backward "file:") (forward-word) (insert "+sys") (end-of-line) )
第二版
(defun file2FileSys() (interactive) (save-excursion (search-backward "file:") (forward-word) (insert "+sys")) )