From: Allen Li <darkfeline@felesatra.moe>
To: eliz@gnu.org
Cc: Allen Li <vianchielfaura@gmail.com>,
Noam Postavsky <npostavs@gmail.com>,
29923@debbugs.gnu.org
Subject: bug#29923: [PATCH] Skip writing empty abbrev tables
Date: Wed, 26 Sep 2018 09:01:45 +0000 [thread overview]
Message-ID: <CADbSrJzL-UFRH1+7WEVzuyiHsXW2CavwLLqge==p-yKanE-cdg@mail.gmail.com> (raw)
In-Reply-To: <834lemf0lg.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 812 bytes --]
Attached new patch
On Wed, Sep 19, 2018 at 6:44 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Allen Li <darkfeline@felesatra.moe>
> > Date: Tue, 18 Sep 2018 19:55:38 -0700
> > Cc: Allen Li <vianchielfaura@gmail.com>, 29923@debbugs.gnu.org
> >
> > > 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.
>
> I think this change in behavior warrants a NEWS entry, and I think the
> description in the ELisp manual should also be updated.
>
> > To implement this, we need to filter out out system abbrevs before
> ^^^^^^^
> A typo.
Done
>
> Thanks.
[-- Attachment #2: 0001-Skip-writing-empty-abbrev-tables.patch --]
[-- Type: text/x-patch, Size: 6979 bytes --]
From 1510152169b6cc8b5cb1d0daa59578cec1373f13 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 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.
---
doc/lispref/abbrevs.texi | 16 ++++----
etc/NEWS | 6 +++
lisp/abbrev.el | 85 +++++++++++++++++++++-------------------
3 files changed, 60 insertions(+), 47 deletions(-)
diff --git a/doc/lispref/abbrevs.texi b/doc/lispref/abbrevs.texi
index 087e694520..32d1d8d036 100644
--- a/doc/lispref/abbrevs.texi
+++ b/doc/lispref/abbrevs.texi
@@ -112,17 +112,19 @@ Abbrev Tables
@code{define-abbrev-table} adds the new abbrev table name to this list.
@end defvar
-@defun insert-abbrev-table-description name &optional human
+@defun insert-abbrev-table-description name &optional readable
This function inserts before point a description of the abbrev table
named @var{name}. The argument @var{name} is a symbol whose value is an
abbrev table. @c The return value is always @code{nil}.
-If @var{human} is non-@code{nil}, the description is human-oriented.
-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.)
+If @var{readable} is non-@code{nil}, the description is
+human-oriented. 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).
+However, if the resulting expression would not define any abbrevs,
+nothing is inserted.
@end defun
@node Defining Abbrevs
diff --git a/etc/NEWS b/etc/NEWS
index bc6791b05b..9032f90643 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -246,6 +246,12 @@ case does not match.
'write-abbrev-file' now writes special properties like ':case-fixed'
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
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index cddce8f529..e1fd366ba9 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)
@@ -934,31 +932,38 @@ insert-abbrev-table-description
"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)
--
2.19.0
next prev parent reply other threads:[~2018-09-26 9:01 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
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 [this message]
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='CADbSrJzL-UFRH1+7WEVzuyiHsXW2CavwLLqge==p-yKanE-cdg@mail.gmail.com' \
--to=darkfeline@felesatra.moe \
--cc=29923@debbugs.gnu.org \
--cc=eliz@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).