0

I have created a bunch of abbreviations for long account names in beancount-mode. The abbrevs are pretty volatile in my short term memory, so I thought of using consult--read to help display the available abbrevs and quickly select the desired one. I am using consult and marginalia.

To create a command for inserting abbrev, I wrote the following function:

(defun insert-abbrev-partiallyworking (abbr)
  "Insert an abbreviation from the local abbrev table of the current buffer"
  (interactive
   (list (consult--read
      (mapcar #'symbol-name
          (abbrev--table-symbols
           'local-abbrev-table))
      :prompt "Abbrev: "
      :annotate (lambda (abbr) (concat "\t\t\t" (abbrev-expansion abbr) "  EOS")))))
  (insert abbr))

That does not work. What shows up is this: competion buffer screenshot

So after some hacking, I came up with the following tweak by capturing the local-abbrev-table and providing it to abbrev-expansion:

(defun my/insert-abbrev (abbr)
  "Insert an abbreviation from the local abbrev table of the current buffer"
  (interactive
   (let ((tbl local-abbrev-table))
     (list (consult--read
        (mapcar #'symbol-name
            (abbrev--table-symbols
             'tbl))
        :prompt "Abbrev: "
        :annotate (lambda (abbr) (concat "\t\t\t" (abbrev-expansion abbr tbl)))))))
  (insert abbr))

And then the completion buffer shows the expansion as annotation: completion buffer screenshot

I would like to understand why the first one deos not work while the second one does

0 Answers0