From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Newsgroups: gmane.emacs.bugs Subject: bug#5937: 23.1.95; why saving empty abbrev tables Date: Sun, 27 Mar 2011 13:09:42 +0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1301204243 11165 80.91.229.12 (27 Mar 2011 05:37:23 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 27 Mar 2011 05:37:23 +0000 (UTC) Cc: 5937@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Mar 27 07:37:18 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 1Q3if7-0006eX-Sg for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 Mar 2011 07:37:18 +0200 Original-Received: from localhost ([127.0.0.1]:44607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3if7-0008PX-AR for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 Mar 2011 01:37:17 -0400 Original-Received: from [140.186.70.92] (port=37001 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3iez-0008PS-Sp for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 01:37:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q3iey-00082t-Im for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 01:37:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:50767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q3iey-00082p-Fx for bug-gnu-emacs@gnu.org; Sun, 27 Mar 2011 01:37:08 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q3iFi-0007uh-En; Sun, 27 Mar 2011 01:11:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo 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 05:11:02 +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 5937-submit@debbugs.gnu.org id=B5937.130120260630354 (code B ref 5937); Sun, 27 Mar 2011 05:11:02 +0000 Original-Received: (at 5937) by debbugs.gnu.org; 27 Mar 2011 05:10:06 +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 1Q3iEn-0007tW-JE for submit@debbugs.gnu.org; Sun, 27 Mar 2011 01:10:06 -0400 Original-Received: from mail-iw0-f172.google.com ([209.85.214.172]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q3iEk-0007sx-G0 for 5937@debbugs.gnu.org; Sun, 27 Mar 2011 01:10:03 -0400 Original-Received: by iwn39 with SMTP id 39so1889835iwn.3 for <5937@debbugs.gnu.org>; Sat, 26 Mar 2011 22:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=JtY59skK0TzErIvGAGOBzMr0+x+X/TX3qHfPmzeAxHY=; b=TinUYfE0sEITqNoprsrAHL0mWNoRaR54Wmmfo8ucxzc5rDKdBnkEtvauuRPL2RegHB DiJhhmocG7giyM+S6PGppJFPckryKzMbrVsQdd+ygEvt4b0KmUNbbt1o+Cq380z5UtqQ /yPwNWlo9JqFPAvkD1EMPbONmHiMqtZomOnDw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=m2COue1XRxcZGXWeXCvt0TZFWAsH5dB7jsqTEMj/Hb6OxO7xwqTyYYiKrglg8WYSJU jN/FBmZ/vaiwOIBQA7PxzaI4Zd+lI5ozHFdvuC/CQQw48Co/fivUK4vake9X0kMPWPxo wYti8RmHHWoghc/fFxzWffCq0A28usIO6z+oM= Original-Received: by 10.43.55.141 with SMTP id vy13mr2341379icb.188.1301202596742; Sat, 26 Mar 2011 22:09:56 -0700 (PDT) Original-Received: from Victoria.local ([114.249.26.81]) by mx.google.com with ESMTPS id 19sm1927491ibx.52.2011.03.26.22.09.49 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 26 Mar 2011 22:09:55 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Mon, 26 Apr 2010 23:49:07 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3.50 (Mac OS X 10.6.7) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sun, 27 Mar 2011 01:11:02 -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:45391 Archived-At: --=-=-= 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment Content-Description: abbrev 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 --=-=-=--