Emacs中的文档本地缩写

时间:2014-02-17 18:23:57

标签: emacs abbreviation

我想在文档的本地Emacs中定义一个缩写,即:

  • 它不会写入缩写文件
  • 它在缩写文件中使用相同的键覆盖任何缩写,但仅适用于当前文档。

到目前为止,我所拥有的是:

%%% eval: (define-abbrev-table 'latex-mode-abbrev-table '(("tc" "triangular clique" nil 0)))

但这不符合我的要求......,

1 个答案:

答案 0 :(得分: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)))