aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllen Li2017-12-31 20:33:21 -0800
committerEli Zaretskii2018-09-29 10:27:11 +0300
commit3bbe9e609138ae88a4c98bcee0da8fcf8b4a3e80 (patch)
treedddace7db216a1ca095fc3ebfd19c5935818c16e
parent48ff4c0b2f78f1812fa12e3a56ee5f2a0bc712f7 (diff)
downloademacs-3bbe9e609138ae88a4c98bcee0da8fcf8b4a3e80.tar.gz
emacs-3bbe9e609138ae88a4c98bcee0da8fcf8b4a3e80.zip
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'.
-rw-r--r--doc/lispref/abbrevs.texi4
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/abbrev.el85
3 files changed, 54 insertions, 41 deletions
diff --git a/doc/lispref/abbrevs.texi b/doc/lispref/abbrevs.texi
index 087e6945203..4c9e653cb19 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
122description is a Lisp expression---a call to @code{define-abbrev-table} 122description is a Lisp expression---a call to @code{define-abbrev-table}
123that would define @var{name} as it is currently defined, but without 123that would define @var{name} as it is currently defined, but without
124the system abbrevs. (The mode or package using @var{name} is supposed 124the system abbrevs. (The mode or package using @var{name} is supposed
125to add these to @var{name} separately.) 125to add these to @var{name} separately.) If the Lisp expression would
126not define any abbrevs (i.e.@: it defines an empty abbrev table), this
127function inserts nothing.
126@end defun 128@end defun
127 129
128@node Defining Abbrevs 130@node Defining Abbrevs
diff --git a/etc/NEWS b/etc/NEWS
index 354072fc814..474af167e83 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -247,6 +247,12 @@ case does not match.
247for abbrevs that have them. 247for abbrevs that have them.
248 248
249+++ 249+++
250** 'insert-abbrev-table-description' skips empty tables.
251'insert-abbrev-table-description' skips inserting empty tables when
252inserting non-readable tables. By extension, this makes
253'write-abbrev-file' skip writing empty tables.
254
255+++
250** The new functions and commands 'text-property-search-forward' and 256** The new functions and commands 'text-property-search-forward' and
251'text-property-search-backward' have been added. These provide an 257'text-property-search-backward' have been added. These provide an
252interface that's more like functions like @code{search-forward}. 258interface that's more like functions like @code{search-forward}.
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index cddce8f5294..e1fd366ba9e 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -896,24 +896,22 @@ is not undone."
896 896
897(defun abbrev--write (sym) 897(defun abbrev--write (sym)
898 "Write the abbrev in a `read'able form. 898 "Write the abbrev in a `read'able form.
899Only writes the non-system abbrevs.
900Presumes that `standard-output' points to `current-buffer'." 899Presumes that `standard-output' points to `current-buffer'."
901 (unless (or (null (symbol-value sym)) (abbrev-get sym :system)) 900 (insert " (")
902 (insert " (") 901 (prin1 (symbol-name sym))
903 (prin1 (symbol-name sym)) 902 (insert " ")
904 (insert " ") 903 (prin1 (symbol-value sym))
905 (prin1 (symbol-value sym)) 904 (insert " ")
906 (insert " ") 905 (prin1 (symbol-function sym))
907 (prin1 (symbol-function sym)) 906 (insert " :count ")
908 (insert " :count ") 907 (prin1 (abbrev-get sym :count))
909 (prin1 (abbrev-get sym :count)) 908 (when (abbrev-get sym :case-fixed)
910 (when (abbrev-get sym :case-fixed) 909 (insert " :case-fixed ")
911 (insert " :case-fixed ") 910 (prin1 (abbrev-get sym :case-fixed)))
912 (prin1 (abbrev-get sym :case-fixed))) 911 (when (abbrev-get sym :enable-function)
913 (when (abbrev-get sym :enable-function) 912 (insert " :enable-function ")
914 (insert " :enable-function ") 913 (prin1 (abbrev-get sym :enable-function)))
915 (prin1 (abbrev-get sym :enable-function))) 914 (insert ")\n"))
916 (insert ")\n")))
917 915
918(defun abbrev--describe (sym) 916(defun abbrev--describe (sym)
919 (when (symbol-value sym) 917 (when (symbol-value sym)
@@ -934,31 +932,38 @@ Presumes that `standard-output' points to `current-buffer'."
934 "Insert before point a full description of abbrev table named NAME. 932 "Insert before point a full description of abbrev table named NAME.
935NAME is a symbol whose value is an abbrev table. 933NAME is a symbol whose value is an abbrev table.
936If optional 2nd arg READABLE is non-nil, a human-readable description 934If optional 2nd arg READABLE is non-nil, a human-readable description
937is inserted. Otherwise the description is an expression, 935is inserted.
938a call to `define-abbrev-table', which would 936
939define the abbrev table NAME exactly as it is currently defined. 937If READABLE is nil, an expression is inserted. The expression is
940 938a call to `define-abbrev-table' that when evaluated will define
941Abbrevs marked as \"system abbrevs\" are omitted." 939the abbrev table NAME exactly as it is currently defined.
940Abbrevs marked as \"system abbrevs\" are ignored. If the
941resulting expression would not define any abbrevs, nothing is
942inserted."
942 (let ((table (symbol-value name)) 943 (let ((table (symbol-value name))
943 (symbols ())) 944 (symbols ()))
944 (mapatoms (lambda (sym) (if (symbol-value sym) (push sym symbols))) table) 945 (mapatoms (lambda (sym)
945 (setq symbols (sort symbols 'string-lessp)) 946 (if (and (symbol-value sym) (or readable (not (abbrev-get sym :system))))
946 (let ((standard-output (current-buffer))) 947 (push sym symbols)))
947 (if readable 948 table)
948 (progn 949 (when symbols
949 (insert "(") 950 (setq symbols (sort symbols 'string-lessp))
950 (prin1 name) 951 (let ((standard-output (current-buffer)))
951 (insert ")\n\n") 952 (if readable
952 (mapc 'abbrev--describe symbols) 953 (progn
953 (insert "\n\n")) 954 (insert "(")
954 (insert "(define-abbrev-table '") 955 (prin1 name)
955 (prin1 name) 956 (insert ")\n\n")
956 (if (null symbols) 957 (mapc 'abbrev--describe symbols)
957 (insert " '())\n\n") 958 (insert "\n\n"))
958 (insert "\n '(\n") 959 (insert "(define-abbrev-table '")
959 (mapc 'abbrev--write symbols) 960 (prin1 name)
960 (insert " ))\n\n"))) 961 (if (null symbols)
961 nil))) 962 (insert " '())\n\n")
963 (insert "\n '(\n")
964 (mapc 'abbrev--write symbols)
965 (insert " ))\n\n")))
966 nil))))
962 967
963(defun define-abbrev-table (tablename definitions 968(defun define-abbrev-table (tablename definitions
964 &optional docstring &rest props) 969 &optional docstring &rest props)