emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 3bbe9e6: Avoid writing empty abbrev tables


From: Eli Zaretskii
Subject: [Emacs-diffs] master 3bbe9e6: Avoid writing empty abbrev tables
Date: Sat, 29 Sep 2018 03:28:41 -0400 (EDT)

branch: master
commit 3bbe9e609138ae88a4c98bcee0da8fcf8b4a3e80
Author: Allen Li <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Avoid writing empty abbrev tables
    
    Fixes bug#29923
    
    'insert-abbrev-table-description' with a non-nil READABLE inserts Lisp
    forms suitable for evaluation to restore the defined abbrevs.  We
    don't have to insert a form for tables that do not have any abbrevs.
    
    To implement this, we need to filter out system abbrevs before
    checking if a table is empty, because system abbrevs were previously
    skipped in the 'abbrev--write' call, at which point we would already
    have started inserting the beginning of a table definition form.
    
    * lisp/abbrev.el (insert-abbrev-table-description):
    Skip inserting empty tables when READABLE is non-nil.
    Clarify behavior in documentation string.
    (abbrev--write): Remove system abbrev check.
    
    * doc/lispref/abbrevs.texi (Abbrev Tables): Document behavior
    with empty tables.
    
    * etc/NEWS: Mention the change in behavior of
    'insert-abbrev-table-description'.
---
 doc/lispref/abbrevs.texi |  4 ++-
 etc/NEWS                 |  6 ++++
 lisp/abbrev.el           | 85 +++++++++++++++++++++++++-----------------------
 3 files changed, 54 insertions(+), 41 deletions(-)

diff --git a/doc/lispref/abbrevs.texi b/doc/lispref/abbrevs.texi
index 087e694..4c9e653 100644
--- a/doc/lispref/abbrevs.texi
+++ b/doc/lispref/abbrevs.texi
@@ -122,7 +122,9 @@ System abbrevs are listed and identified as such.  
Otherwise the
 description is a Lisp expression---a call to @code{define-abbrev-table}
 that would define @var{name} as it is currently defined, but without
 the system abbrevs.  (The mode or package using @var{name} is supposed
-to add these to @var{name} separately.)
+to add these to @var{name} separately.)  If the Lisp expression would
+not define any abbrevs (i.e.@: it defines an empty abbrev table), this
+function inserts nothing.
 @end defun
 
 @node Defining Abbrevs
diff --git a/etc/NEWS b/etc/NEWS
index 354072f..474af16 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -247,6 +247,12 @@ case does not match.
 for abbrevs that have them.
 
 +++
+** 'insert-abbrev-table-description' skips empty tables.
+'insert-abbrev-table-description' skips inserting empty tables when
+inserting non-readable tables.  By extension, this makes
+'write-abbrev-file' skip writing empty tables.
+
++++
 ** The new functions and commands 'text-property-search-forward' and
 'text-property-search-backward' have been added.  These provide an
 interface that's more like functions like @code{search-forward}.
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index cddce8f..e1fd366 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -896,24 +896,22 @@ is not undone."
 
 (defun abbrev--write (sym)
   "Write the abbrev in a `read'able form.
-Only writes the non-system abbrevs.
 Presumes that `standard-output' points to `current-buffer'."
-  (unless (or (null (symbol-value sym)) (abbrev-get sym :system))
-    (insert "    (")
-    (prin1 (symbol-name sym))
-    (insert " ")
-    (prin1 (symbol-value sym))
-    (insert " ")
-    (prin1 (symbol-function sym))
-    (insert " :count ")
-    (prin1 (abbrev-get sym :count))
-    (when (abbrev-get sym :case-fixed)
-      (insert " :case-fixed ")
-      (prin1 (abbrev-get sym :case-fixed)))
-    (when (abbrev-get sym :enable-function)
-      (insert " :enable-function ")
-      (prin1 (abbrev-get sym :enable-function)))
-    (insert ")\n")))
+  (insert "    (")
+  (prin1 (symbol-name sym))
+  (insert " ")
+  (prin1 (symbol-value sym))
+  (insert " ")
+  (prin1 (symbol-function sym))
+  (insert " :count ")
+  (prin1 (abbrev-get sym :count))
+  (when (abbrev-get sym :case-fixed)
+    (insert " :case-fixed ")
+    (prin1 (abbrev-get sym :case-fixed)))
+  (when (abbrev-get sym :enable-function)
+    (insert " :enable-function ")
+    (prin1 (abbrev-get sym :enable-function)))
+  (insert ")\n"))
 
 (defun abbrev--describe (sym)
   (when (symbol-value sym)
@@ -934,31 +932,38 @@ Presumes that `standard-output' points to 
`current-buffer'."
   "Insert before point a full description of abbrev table named NAME.
 NAME is a symbol whose value is an abbrev table.
 If optional 2nd arg READABLE is non-nil, a human-readable description
-is inserted.  Otherwise the description is an expression,
-a call to `define-abbrev-table', which would
-define the abbrev table NAME exactly as it is currently defined.
-
-Abbrevs marked as \"system abbrevs\" are omitted."
+is inserted.
+
+If READABLE is nil, an expression is inserted.  The expression is
+a call to `define-abbrev-table' that when evaluated will define
+the abbrev table NAME exactly as it is currently defined.
+Abbrevs marked as \"system abbrevs\" are ignored.  If the
+resulting expression would not define any abbrevs, nothing is
+inserted."
   (let ((table (symbol-value name))
         (symbols ()))
-    (mapatoms (lambda (sym) (if (symbol-value sym) (push sym symbols))) table)
-    (setq symbols (sort symbols 'string-lessp))
-    (let ((standard-output (current-buffer)))
-      (if readable
-         (progn
-           (insert "(")
-           (prin1 name)
-           (insert ")\n\n")
-           (mapc 'abbrev--describe symbols)
-           (insert "\n\n"))
-       (insert "(define-abbrev-table '")
-       (prin1 name)
-       (if (null symbols)
-           (insert " '())\n\n")
-         (insert "\n  '(\n")
-         (mapc 'abbrev--write symbols)
-         (insert "   ))\n\n")))
-      nil)))
+    (mapatoms (lambda (sym)
+                (if (and (symbol-value sym) (or readable (not (abbrev-get sym 
:system))))
+                    (push sym symbols)))
+              table)
+    (when symbols
+      (setq symbols (sort symbols 'string-lessp))
+      (let ((standard-output (current-buffer)))
+        (if readable
+            (progn
+              (insert "(")
+              (prin1 name)
+              (insert ")\n\n")
+              (mapc 'abbrev--describe symbols)
+              (insert "\n\n"))
+          (insert "(define-abbrev-table '")
+          (prin1 name)
+          (if (null symbols)
+              (insert " '())\n\n")
+            (insert "\n  '(\n")
+            (mapc 'abbrev--write symbols)
+            (insert "   ))\n\n")))
+        nil))))
 
 (defun define-abbrev-table (tablename definitions
                                       &optional docstring &rest props)



reply via email to

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