emacs 有没有这样的包: 保存常用 snippet 然后 consult 之类的搜索立即可以粘贴

  1. yasnippet 不一定非得 【输入->TAB->展开】,通过 completion read 就是【搜索->回车->插入】。

  2. yas-new-snippet 就是快速创建 snippet 的方式。你完全可以创建一个原样输出的纯文本 snippet。

  3. consult-yasnippet 稍微改装一下就可以搜索内容(注意关键字前面要加一个空格):

$ emacsq.sh -P use-package,yasnippet,vertico,consult,consult-yasnippet --eval "\
 (progn
   (use-package vertico
     :init
     (vertico-mode))
 
   (use-package consult)
 
   (use-package yasnippet
     :config
     (yas-reload-all)
     (yas-global-mode))
 
   (use-package consult-yasnippet
     :after (consult yasnippet)
     :bind ((\"M-,\" . consult-yasnippet))
     :config
     (advice-add 'consult-yasnippet--candidates
                 :override
                 (defun consult-yasnippet--candidates@add-content (templates)
                   \"Convert TEMPLATES into candidates for `completing-read'.\"
                   (mapcar
                    (lambda (template)
                      (cons (concat
                             (propertize (concat (yas--table-name (yas--template-table template))
                                                 \" \")
                                         'invisible t)
                             (yas--template-name template)
                             \" [\"
                             (propertize (or (yas--template-key template)
                                             (and (functionp 'yas--template-regexp-key)
                                                  (yas--template-regexp-key template)))
                                         'face 'consult-key)
                             \"] \" (yas--template-content template)) ;; +++
                            template))
                    templates)))))" -nw

我猜你可能觉得 yasnippet 累赘,它的一个 snippet 最少包含 (name key content) 三个字段,你可能只想要 content 部分。但是如果有多个相似的 content,你很难在狭小的屏幕上快速区分。所以 name/key 字段就显得很有必要了。


3 个赞