unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Allen Li <darkfeline@felesatra.moe>
To: Noam Postavsky <npostavs@gmail.com>
Cc: Allen Li <vianchielfaura@gmail.com>, 29923@debbugs.gnu.org
Subject: bug#29923: [PATCH] Skip writing empty abbrev tables
Date: Tue, 18 Sep 2018 19:55:38 -0700	[thread overview]
Message-ID: <CADbSrJwD=g4Y3HNwze5ZjBzG8f6Hq4mZw6ywR3oQt9_k5pR9BQ@mail.gmail.com> (raw)
In-Reply-To: <874lemquwr.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

On Tue, Sep 18, 2018 at 3:53 PM Noam Postavsky <npostavs@gmail.com> wrote:
>
> Allen Li <darkfeline@felesatra.moe> writes:
>
> > The system abbrev omitting worked (if readable is nil); it's
> > implemented in abbrev--write.
> > However, that doesn't allow us to skip writing a table if it only
> > contains system abbrevs;
> > we'll still see a table with abbrevs, write the opening of the
> > define-abbrev-table form,
> > and then realize in abbrev-write that all of the abbrevs are system abbrevs.
>
> Ah, it would be good to have this information in the commit message, as
> the patch is a bit confusing to read otherwise.

Done.  I have also removed the system abbrev check in abbrev--write since
it is redundant now and this is the only place it is called.

[-- Attachment #2: 0001-Skip-writing-empty-abbrev-tables.patch --]
[-- Type: text/x-patch, Size: 4258 bytes --]

From 29b64ffe68890ece089d5e1050c55eb7c2547d36 Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
Date: Sun, 31 Dec 2017 20:33:21 -0800
Subject: [PATCH] Skip 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 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.
* lisp/abbrev.el (abbrev--write): Remove system abbrev check.
---
 lisp/abbrev.el | 75 ++++++++++++++++++++++++++------------------------
 1 file changed, 39 insertions(+), 36 deletions(-)

diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index cddce8f529..fd44cce4ae 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -896,24 +896,22 @@ unexpand-abbrev
 
 (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)
@@ -938,27 +936,32 @@ insert-abbrev-table-description
 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."
+If READABLE is nil, abbrevs marked as \"system abbrevs\" and
+empty abbrev tables 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) (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)
-- 
2.19.0


  reply	other threads:[~2018-09-19  2:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-01  3:44 bug#29923: 25.3; write-abbrev-file inserts many empty tables Allen Li
2018-01-01  4:36 ` bug#29923: [PATCH] Skip writing empty abbrev tables Allen Li
2018-09-09 20:43   ` Noam Postavsky
2018-09-15  1:22     ` Allen Li
2018-09-18 22:53       ` Noam Postavsky
2018-09-19  2:55         ` Allen Li [this message]
2018-09-19  6:04           ` Andreas Röhler
2018-09-26  9:03             ` Allen Li
2018-09-19  6:44           ` Eli Zaretskii
2018-09-26  9:01             ` Allen Li
2018-09-29  7:29               ` Eli Zaretskii
2018-09-09  0:31 ` bug#29923: 25.3; write-abbrev-file inserts many empty tables Allen Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADbSrJwD=g4Y3HNwze5ZjBzG8f6Hq4mZw6ywR3oQt9_k5pR9BQ@mail.gmail.com' \
    --to=darkfeline@felesatra.moe \
    --cc=29923@debbugs.gnu.org \
    --cc=npostavs@gmail.com \
    --cc=vianchielfaura@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).