From fa3e3ed1f55fd2d973826dbd21b5b59072b86504 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Sun, 31 Dec 2017 20:33:21 -0800 Subject: [PATCH] Skip writing empty abbrev tables Fixes bug#29923 * lisp/abbrev.el (write-abbrev-file): Pass SKIPEMPTY to insert-abbrev-table-description. (insert-abbrev-table-description): Add SKIPEMPTY optional parameter. Skip inserting empty tables if SKIPEMPTY is non-nil. --- lisp/abbrev.el | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/lisp/abbrev.el b/lisp/abbrev.el index 5faffd4e17..9ba114e6a0 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -34,6 +34,7 @@ (eval-when-compile (require 'cl-lib)) (require 'obarray) +(require 'seq) (defgroup abbrev-mode nil "Word abbreviations mode." @@ -254,7 +255,7 @@ write-abbrev-file (lambda (s1 s2) (string< (symbol-name s1) (symbol-name s2))))) - (insert-abbrev-table-description table nil)) + (insert-abbrev-table-description table nil t)) (when (unencodable-char-position (point-min) (point-max) 'utf-8) (setq coding-system-for-write (if (> emacs-major-version 24) @@ -933,35 +934,40 @@ abbrev--describe (prin1 (symbol-function sym))) (terpri))) -(defun insert-abbrev-table-description (name &optional readable) +(defun insert-abbrev-table-description (name &optional readable skipempty) "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. +If optional arg SKIPEMPTY is non-nil, skip insertion if table is empty. Abbrevs marked as \"system abbrevs\" are omitted." (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) (not (abbrev-get sym :system))) + (push sym symbols))) + table) + (when (or symbols (not skipempty)) + (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) -- 2.15.1