From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas =?UTF-8?Q?R=C3=B6hler?= Newsgroups: gmane.emacs.bugs Subject: bug#5937: 23.1.95; why saving empty abbrev tables Date: Sun, 27 Mar 2011 19:34:36 +0200 Message-ID: <4D8F752C.2000605@easy-emacs.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1301247440 8736 80.91.229.12 (27 Mar 2011 17:37:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 27 Mar 2011 17:37:20 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Mar 27 19:37:16 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q3ttr-0004mE-8i for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 Mar 2011 19:37:15 +0200 Original-Received: from localhost ([127.0.0.1]:42295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3ttq-0006Yb-NL for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 Mar 2011 13:37:14 -0400 Original-Received: from [140.186.70.92] (port=38326 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3ttm-0006YW-2M for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 13:37:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q3ttk-0003i2-Pt for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 13:37:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:39997) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q3ttk-0003hy-Jy for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 13:37:08 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q3tlt-0000Tz-Pc; Sun, 27 Mar 2011 13:29:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 27 Mar 2011 17:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5937 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by submit@debbugs.gnu.org id=B.13012468931797 (code B ref -1); Sun, 27 Mar 2011 17:29:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Mar 2011 17:28:13 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q3tl7-0000Sw-B6 for submit@debbugs.gnu.org; Sun, 27 Mar 2011 13:28:13 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q3tl4-0000Sk-AA for submit@debbugs.gnu.org; Sun, 27 Mar 2011 13:28:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q3tkx-0002VY-Lg for submit@debbugs.gnu.org; Sun, 27 Mar 2011 13:28:04 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:34201) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q3tkx-0002VU-Ii for submit@debbugs.gnu.org; Sun, 27 Mar 2011 13:28:03 -0400 Original-Received: from [140.186.70.92] (port=39168 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3tkw-0001pz-9I for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 13:28:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q3tku-0002VC-BT for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 13:28:01 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.171]:58041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q3tku-0002UN-0d for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 13:28:00 -0400 Original-Received: from [192.168.178.29] (brln-4dbc6fd4.pool.mediaWays.net [77.188.111.212]) by mrelayeu.kundenserver.de (node=mreu3) with ESMTP (Nemesis) id 0LnYoV-1PV6Ys0mr9-00hw28; Sun, 27 Mar 2011 19:27:57 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: X-Provags-ID: V02:K0:85wLPba0eX3iq4mdPYvZ15tpTcHCiIxVSsC+Si2k/YL Xsf0ltv0cf5wEdGWBSQLdkpQ8CLB0dk4eAC8pC2qemmiEZf7CZ fOAkPSeVoeYlzeEu6/Vzz314uAgeaMujyb0G3JIlJGRcezF2QO ioNpmHTxkeylGvkuaTKvNk+YlLjicmv/x6//AfJJycudSykRV1 PhnFhbBNnFDKPSJvVWivPYFg/1g+CoXiaEbvdUTmeg= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sun, 27 Mar 2011 13:29:01 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:45397 Archived-At: Am 27.03.2011 07:09, schrieb Leo: > On 2010-04-27 11:49 +0800, Stefan Monnier wrote: >> Actually, having tried it now for a while I do have an objection: it >> makes it harder to add entries to an abbrev-table if that table >> is empty. >> >> So I think a better option is to sort the tables such that empty tables >> are pushed to the end. >> >> >> Stefan > > Hello Stefan, > > I propose we allow C-u M-x edit-abbrevs to include all abbrev tables but > default to include only nonempty tables. > > Here is an updated patch. > > > > > === modified file 'lisp/abbrev.el' > --- lisp/abbrev.el 2011-03-22 15:38:40 +0000 > +++ lisp/abbrev.el 2011-03-27 04:56:22 +0000 > @@ -104,7 +104,7 @@ > prefix arg, display only local, i.e. mode-specific, abbrevs. > Otherwise display all abbrevs." > (interactive "P") > - (display-buffer (prepare-abbrev-list-buffer local))) > + (display-buffer (prepare-abbrev-list-buffer (and local 'local)))) > > (defun abbrev-table-name (table) > "Value is the name of abbrev table TABLE." > @@ -116,14 +116,28 @@ > (setq tables (cdr tables))) > found)) > > -(defun prepare-abbrev-list-buffer (&optional local) > - (let ((local-table local-abbrev-table)) > +(defun abbrev-nonempty-table-names (&optional ignore-system) > + "Return a list of nonempty abbrev table names. > +If IGNORE-SYSTEM is non-nil, system definitions are ignored." > + (delete nil > + (mapcar (lambda (tn) > + (unless (abbrev-table-empty-p > + (symbol-value tn) ignore-system) > + tn)) > + abbrev-table-name-list))) > + > +;; HOW takes value: nil, local or all. > +(defun prepare-abbrev-list-buffer (&optional how) > + (let ((local-table local-abbrev-table) > + (tables (if (eq how 'all) > + abbrev-table-name-list > + (abbrev-nonempty-table-names)))) > (with-current-buffer (get-buffer-create "*Abbrevs*") > (erase-buffer) > - (if local > + (if (eq how 'local) > (insert-abbrev-table-description > (abbrev-table-name local-table) t) > - (dolist (table abbrev-table-name-list) > + (dolist (table tables) > (insert-abbrev-table-description table t))) > (goto-char (point-min)) > (set-buffer-modified-p nil) > @@ -140,10 +154,11 @@ > (use-local-map edit-abbrevs-map) > (run-mode-hooks 'edit-abbrevs-mode-hook)) > > -(defun edit-abbrevs () > +(defun edit-abbrevs (&optional all) > "Alter abbrev definitions by editing a list of them. > Selects a buffer containing a list of abbrev definitions. > -You can edit them and type \\\\[edit-abbrevs-redefine] to redefine abbrevs > +Use \\[universal-argument] to include empty abbrev tables. You can edit > +them and type \\\\[edit-abbrevs-redefine] to redefine abbrevs > according to your editing. > Buffer contains a header line for each abbrev table, > which is the abbrev table name in parentheses. > @@ -152,8 +167,8 @@ > where NAME and EXPANSION are strings with quotes, > USECOUNT is an integer, and HOOK is any valid function > or may be omitted (it is usually omitted)." > - (interactive) > - (switch-to-buffer (prepare-abbrev-list-buffer))) > + (interactive "P") > + (switch-to-buffer (prepare-abbrev-list-buffer (and all 'all)))) > > (defun edit-abbrevs-redefine () > "Redefine abbrevs according to current buffer contents." > @@ -225,7 +240,8 @@ > abbrev-file-name))) > (or (and file (> (length file) 0)) > (setq file abbrev-file-name)) > - (let ((coding-system-for-write 'utf-8)) > + (let ((coding-system-for-write 'utf-8) > + (tables (abbrev-nonempty-table-names t))) > (with-temp-buffer > (dolist (table > ;; We sort the table in order to ease the automatic > @@ -234,10 +250,9 @@ > ;; user keeps their home directory in a revision > ;; control system, and is therefore keeping multiple > ;; slightly-differing copies loosely synchronized. > - (sort (copy-sequence abbrev-table-name-list) > - (lambda (s1 s2) > - (string< (symbol-name s1) > - (symbol-name s2))))) > + (sort tables (lambda (s1 s2) > + (string< (symbol-name s1) > + (symbol-name s2))))) > (insert-abbrev-table-description table nil)) > (when (unencodable-char-position (point-min) (point-max) 'utf-8) > (setq coding-system-for-write > @@ -420,6 +435,18 @@ > (and (vectorp object) > (numberp (abbrev-table-get object :abbrev-table-modiff)))) > > +(defun abbrev-table-empty-p (object&optional ignore-system) > + "Return nil if there are no abbrev symbols in OBJECT. > +If IGNORE-SYSTEM is non-nil, system definitions are ignored." > + (unless (abbrev-table-p object) > + (error "Non abbrev table object")) > + (not (catch 'some > + (mapatoms (lambda (abbrev) > + (unless (or (zerop (length (symbol-name abbrev))) > + (and ignore-system (abbrev-get abbrev :system))) > + (throw 'some t))) > + object)))) > + > (defvar global-abbrev-table (make-abbrev-table) > "The abbrev table whose abbrevs affect all buffers. > Each buffer may also have a local abbrev table. > > > > > > Leo Hi Leo, just an abstract reasoning: don't change things you are not compelled to. Or to say: unless there is a reason for it. An empty table doesn't take considerable space nor time. OTOH when changing a thing, always remains a certain risk to break something. As said, just abtract reasoning. Don't see a real danger here. Cheers Andreas