diff options
| author | Allen Li | 2018-09-29 15:19:04 -0700 |
|---|---|---|
| committer | Eli Zaretskii | 2018-10-12 11:44:15 +0300 |
| commit | f5896e2cbf0e537ec6b79ba139220239f934c840 (patch) | |
| tree | 51604349e1190449caf75043d689694a84212441 /lisp | |
| parent | 5bd8cfc14d4b0c78c07e65a583f42a10c4cbc06d (diff) | |
| download | emacs-f5896e2cbf0e537ec6b79ba139220239f934c840.tar.gz emacs-f5896e2cbf0e537ec6b79ba139220239f934c840.zip | |
Rework empty abbrev table omitting
There were two problems with the original implementation:
1. It changed the behavior of insert-abbrev-table-description when
READABLE is nil to sometimes insert one Emacs Lisp expression and
sometimes insert nothing.
2. It broke the tests.
This commit reworks this so that insert-abbrev-table-description
always inserts an expressions even if no abbrevs need to be saved and
making only write-abbrev-file check that a table has any abbrevs to
save before calling insert-abbrev-table-description. This duplicates
the work of filtering the table for savable abbrevs, but the benefit
of keeping the API is worth it.
* doc/lispref/abbrevs.texi (Abbrev Tables): Update documentation.
* lisp/abbrev.el (write-abbrev-file): Skip tables without user abbrevs
(insert-abbrev-table-description): Always insert the define
expression.
(abbrev--table-symbols): New function.
* test/lisp/abbrev-tests.el (abbrev--table-symbols-test):
Add test for abbrev--table-symbols.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/abbrev.el | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/lisp/abbrev.el b/lisp/abbrev.el index e1fd366ba9e..20a967d7d61 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el | |||
| @@ -251,7 +251,8 @@ have been saved." | |||
| 251 | (lambda (s1 s2) | 251 | (lambda (s1 s2) |
| 252 | (string< (symbol-name s1) | 252 | (string< (symbol-name s1) |
| 253 | (symbol-name s2))))) | 253 | (symbol-name s2))))) |
| 254 | (insert-abbrev-table-description table nil)) | 254 | (if (abbrev--table-symbols table) |
| 255 | (insert-abbrev-table-description table nil))) | ||
| 255 | (when (unencodable-char-position (point-min) (point-max) 'utf-8) | 256 | (when (unencodable-char-position (point-min) (point-max) 'utf-8) |
| 256 | (setq coding-system-for-write | 257 | (setq coding-system-for-write |
| 257 | (if (> emacs-major-version 24) | 258 | (if (> emacs-major-version 24) |
| @@ -937,33 +938,38 @@ is inserted. | |||
| 937 | If READABLE is nil, an expression is inserted. The expression is | 938 | If READABLE is nil, an expression is inserted. The expression is |
| 938 | a call to `define-abbrev-table' that when evaluated will define | 939 | a call to `define-abbrev-table' that when evaluated will define |
| 939 | the abbrev table NAME exactly as it is currently defined. | 940 | the abbrev table NAME exactly as it is currently defined. |
| 940 | Abbrevs marked as \"system abbrevs\" are ignored. If the | 941 | Abbrevs marked as \"system abbrevs\" are ignored." |
| 941 | resulting expression would not define any abbrevs, nothing is | 942 | (let ((table (symbol-value name)) |
| 942 | inserted." | 943 | (symbols (abbrev--table-symbols name readable))) |
| 944 | (setq symbols (sort symbols 'string-lessp)) | ||
| 945 | (let ((standard-output (current-buffer))) | ||
| 946 | (if readable | ||
| 947 | (progn | ||
| 948 | (insert "(") | ||
| 949 | (prin1 name) | ||
| 950 | (insert ")\n\n") | ||
| 951 | (mapc 'abbrev--describe symbols) | ||
| 952 | (insert "\n\n")) | ||
| 953 | (insert "(define-abbrev-table '") | ||
| 954 | (prin1 name) | ||
| 955 | (if (null symbols) | ||
| 956 | (insert " '())\n\n") | ||
| 957 | (insert "\n '(\n") | ||
| 958 | (mapc 'abbrev--write symbols) | ||
| 959 | (insert " ))\n\n"))) | ||
| 960 | nil))) | ||
| 961 | |||
| 962 | (defun abbrev--table-symbols (name &optional system) | ||
| 963 | "Return the user abbrev symbols in the abbrev table named NAME. | ||
| 964 | NAME is a symbol whose value is an abbrev table. System abbrevs | ||
| 965 | are omitted unless SYSTEM is non-nil." | ||
| 943 | (let ((table (symbol-value name)) | 966 | (let ((table (symbol-value name)) |
| 944 | (symbols ())) | 967 | (symbols ())) |
| 945 | (mapatoms (lambda (sym) | 968 | (mapatoms (lambda (sym) |
| 946 | (if (and (symbol-value sym) (or readable (not (abbrev-get sym :system)))) | 969 | (if (and (symbol-value sym) (or system (not (abbrev-get sym :system)))) |
| 947 | (push sym symbols))) | 970 | (push sym symbols))) |
| 948 | table) | 971 | table) |
| 949 | (when symbols | 972 | symbols)) |
| 950 | (setq symbols (sort symbols 'string-lessp)) | ||
| 951 | (let ((standard-output (current-buffer))) | ||
| 952 | (if readable | ||
| 953 | (progn | ||
| 954 | (insert "(") | ||
| 955 | (prin1 name) | ||
| 956 | (insert ")\n\n") | ||
| 957 | (mapc 'abbrev--describe symbols) | ||
| 958 | (insert "\n\n")) | ||
| 959 | (insert "(define-abbrev-table '") | ||
| 960 | (prin1 name) | ||
| 961 | (if (null symbols) | ||
| 962 | (insert " '())\n\n") | ||
| 963 | (insert "\n '(\n") | ||
| 964 | (mapc 'abbrev--write symbols) | ||
| 965 | (insert " ))\n\n"))) | ||
| 966 | nil)))) | ||
| 967 | 973 | ||
| 968 | (defun define-abbrev-table (tablename definitions | 974 | (defun define-abbrev-table (tablename definitions |
| 969 | &optional docstring &rest props) | 975 | &optional docstring &rest props) |