bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#5937: 23.1.95; why saving empty abbrev tables


From: Leo
Subject: bug#5937: 23.1.95; why saving empty abbrev tables
Date: Thu, 15 Apr 2010 11:26:55 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

On 2010-04-12 19:32 +0100, Stefan Monnier wrote:
>> Why empty abbrev tables are saved to file?
>
> Don't know.
>
>> It seems to make it more difficult for editing (edit-abbrevs) because
>> the buffer is full of empty abbrev.  I wonder if saving only non-empty
>> tables is better and user friendlier.
>
> It does sound like a good idea.  Any objection?

I have been using this in my init file and I like it. It makes it easier
to see what's actually defined.

(defun abbrev-table-empty-p (table)
  "Return nil if there are no abbrev symbols in abbrev table object
  TABLE."
  (unless (abbrev-table-p table)
    (error "Non abbrev table object"))
  (not (catch 'some
         (mapatoms (lambda (sym)
                     (when (abbrev-symbol (symbol-name sym) table)
                       (throw 'some t)))
                   table))))
(defadvice prepare-abbrev-list-buffer (around nonempty-abbrev-tables
  activate)
  "Ignore empty abbrev tables."
  (let ((abbrev-table-name-list
         (loop for table in abbrev-table-name-list
               unless (abbrev-table-empty-p (symbol-value table))
               collect table)))
    ad-do-it))
(defadvice write-abbrev-file (around nonempty-abbrev-tables activate)
  "Ignore empty abbrev tables when writing to FILE."
  (let ((abbrev-table-name-list
         (loop for table in abbrev-table-name-list
               unless (abbrev-table-empty-p (symbol-value table))
               collect table)))
    ad-do-it))

[...]
> Obviously, defadvice wouldn't be the right approach for us.
> And rather than (abbrev-symbol (symbol-name sym) table), we can use
> (symbol-value sym).
> We should also eliminate abbrev tables that only contain "system
> abbrevs".

Regarding the :system property, I have experienced some oddity but I
by-passed that instead of looking into it for lack of time.

Here's what happened.

When I use define-abbrev to define some system abbrevs and then M-x
edit-abbrevs and move to the table where those abbrevs are defined then
paste some non-system abbrevs from, for example, another abbrev file.
Those pasted abbrevs are treated as system abbrevs and not saved.
Sometimes when the table already have non-system abbrevs, they are
turned into system ones and get lost.

I had a backup of the abbrev file so that didn't cause me any trouble.

>
>         Stefan

Leo






reply via email to

[Prev in Thread] Current Thread [Next in Thread]