Question

I would like to define an abbrev in Emacs local to a document, that is:

  • it doesn't get written to the abbrev file
  • it overrules any abbrev with the same key in the abbrev file, but only for the present document.

So far what I have is this:

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

but this does not satisfy my requirements...,

Était-ce utile?

La solution

How about this:

(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))))

and then:

(set-local-abbrevs '(("tc" "triangular clique" nil)))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top