Subject: bug#5937: closed (Re: bug#5937: 23.1.95; why saving empty abbrev tables)

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 30 Mar 2011 01:09:02 +0000

Your bug report

#5937: 23.1.95; why saving empty abbrev tables

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
5937: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=5937
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#5937: 23.1.95; why saving empty abbrev tables
From: Leo <[email-masked]>
To: [email-masked]
Date: Wed, 30 Mar 2011 09:08:18 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 24.1

Subject: 23.1.95; why saving empty abbrev tables
From: Leo <[email-masked]>
To: [email-masked]
Date: Mon, 12 Apr 2010 16:23:44 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Why empty abbrev tables are saved to file? 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. For example, any harm of doing something like this:

(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 write-abbrev-file (around nonempty-abbrev-tables activate)
  "Ignore empty abbrev tables when writing to FILE."
  (let ((file (ad-get-arg 0))
        (coding-system-for-write 'emacs-mule)
        (tables (loop for table in abbrev-table-name-list
                      unless (abbrev-table-empty-p (symbol-value table))
                      collect table)))
    (or (and file (> (length file) 0)) (setq file abbrev-file-name))
    (with-temp-file file
      (insert ";;-*-coding: emacs-mule;-*-\n")
      (dolist (table (sort tables
                           (lambda (s1 s2)
                             (string< (symbol-name s1)
                                      (symbol-name s2)))))
        (insert-abbrev-table-description table nil)))))