我写了下面一段代码:
(defun current-buffer-abbrev-table-name()
(let* ((bufname (buffer-file-name (buffer-base-buffer)))
(prefix (substring (md5 bufname) 0 5))
(tblsym (intern (concat prefix "-abbrev-table")))) tblsym)
)
(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* ((tblsym (current-buffer-abbrev-table-name)))
(unless (and (boundp tblsym) (eval tblsym)) (set tblsym (make-abbrev-table :case-fixed)) (abbrev-table-put (eval tblsym) :case-fold t))
(dolist (abbrev abbrevs)
(define-abbrev (eval tblsym)
(car abbrev)
(cadr abbrev)
(caddr abbrev)))
(setq-local local-abbrev-table (eval tblsym))))
(defun clear-local-abbrev()
(let* ((tblsym (current-buffer-abbrev-table-name)))
(if (boundp tblsym) (set tblsym nil))
(setq-local local-abbrev-table nil))
)
这段代码的目的是创建一个 buffer-local 的 abbrev table, 添加参数指定的 abbrev, 把 local-abbrev-table 设置为这个创建的 buffer-local 的 abbrev table. 为了防止大写展开, 我特意在能加的地方都加上了 :case-fixed
.
(abbrev-mode);
(clear-local-abbrev);
(set-local-abbrevs '(("cc" "compute capability" nil) ("gm" "global memory" nil) ("sm" "shared memory" nil)));
然后 sm 空格, 展开了, 问题在于, SM 空格, 也会展开, 但我 不希望 SM 展开.
在 emacs -Q 也会有同样的问题. 我想是不是我对 :case-fixed
有误解. 我以为它能做到大写不展开.
目前我只好添加定义 ("SM" "SM" nil)
, 但是我不喜欢这样.