缩写为local,用于在Emacs中记录
我想在Emacs中定义一个文档本地的缩写,即:缩写为local,用于在Emacs中记录,emacs,abbreviation,Emacs,Abbreviation,我想在Emacs中定义一个文档本地的缩写,即: 它不会写入abbrev文件 它否决了在abbrev文件中具有相同密钥的任何abbrev,但仅适用于当前文档 到目前为止,我得到的是: %%% eval: (define-abbrev-table 'latex-mode-abbrev-table '(("tc" "triangular clique" nil 0))) 但这不符合我的要求…,这个怎么样: (defun set-local-abbrevs (abbrevs) "Add A
- 它不会写入abbrev文件
- 它否决了在abbrev文件中具有相同密钥的任何abbrev,但仅适用于当前文档李>
%%% eval: (define-abbrev-table 'latex-mode-abbrev-table '(("tc" "triangular clique" nil 0)))
但这不符合我的要求…,这个怎么样:
(defun set-local-abbrevs (abbrevs)
"Add ABBREVS to `local-abbrev-table' and make it buffer local.
ABBREVS should be a list of abbrevs as passed to `define-abbrev-table'.
The `local-abbrev-table' will be replaced by a copy with the new
abbrevs added, so that it is not the same as the abbrev table used
in other buffers with the same `major-mode'."
(let* ((bufname (buffer-name))
(prefix (substring (md5 bufname) 0 (length bufname)))
(tblsym (intern (concat prefix "-abbrev-table"))))
(set tblsym (copy-abbrev-table local-abbrev-table))
(dolist (abbrev abbrevs)
(define-abbrev (eval tblsym)
(car abbrev)
(cadr abbrev)
(caddr abbrev)))
(setq-local local-abbrev-table (eval tblsym))))
然后:
(set-local-abbrevs '(("tc" "triangular clique" nil)))
在使用
define abbrev
之前,您可能需要先使用(使用局部变量'latex mode abbrev table)
,但我不确定这是否有效。可能不起作用,但是您可以编写自己的expand abbrev
函数,临时绑定latex模式abbrev表
,并调用原始表。谢谢!我必须将(length(bufname))
更改为(length bufname)
,它才能工作(因为bufname
不是一个函数)。