From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#25049: ibuffer bug when saving existing filter, with patches Date: Thu, 01 Dec 2016 00:03:37 +0900 Message-ID: <87d1hdf1rq.fsf@gmail.com> References: <8737ianx4s.fsf@gmail.com> <8737i9etj1.fsf@gmail.com> <87d1hd8n6q.fsf@gmail.com> <87twapgiy6.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1480518434 15825 195.159.176.226 (30 Nov 2016 15:07:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 30 Nov 2016 15:07:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: Christopher Genovese , 25049@debbugs.gnu.org, Tino Calancha To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 30 16:07:05 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cC6TQ-0002ib-R4 for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Nov 2016 16:07:05 +0100 Original-Received: from localhost ([::1]:44550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cC6TU-0006sV-Ka for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Nov 2016 10:07:08 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cC6QZ-0005OA-7k for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2016 10:04:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cC6QU-000414-1h for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2016 10:04:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60473) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cC6QT-00040z-TV for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2016 10:04:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cC6QT-0000KV-M7 for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2016 10:04:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Nov 2016 15:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25049 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25049-submit@debbugs.gnu.org id=B25049.14805182311251 (code B ref 25049); Wed, 30 Nov 2016 15:04:01 +0000 Original-Received: (at 25049) by debbugs.gnu.org; 30 Nov 2016 15:03:51 +0000 Original-Received: from localhost ([127.0.0.1]:47639 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cC6QI-0000K7-KB for submit@debbugs.gnu.org; Wed, 30 Nov 2016 10:03:51 -0500 Original-Received: from mail-pg0-f66.google.com ([74.125.83.66]:35679) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cC6QH-0000Ju-F4 for 25049@debbugs.gnu.org; Wed, 30 Nov 2016 10:03:50 -0500 Original-Received: by mail-pg0-f66.google.com with SMTP id p66so1576068pga.2 for <25049@debbugs.gnu.org>; Wed, 30 Nov 2016 07:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=I5J0MyK9p+C/uNZWK6IwqUHsGTQMdMhwYonyf18bM28=; b=ucNKBQVf04+a94PPRqZ0C2VH1W+V2YezCrVgZsEZZ9oKdUyb7hZGxr8hV01LzFBYlN oY+ctelwTjWWIT8vtYG2etG8fN8333AhR8gch+8sk3ET+LOWStKBxGKmgMMc7VAe949c 9X3WpLMe8Jf4M80IbDXh0JMEP4D6GtQwhJ7nTaexJhDOZmVcqjYQWYdPeZf2HtJfKGni 5dVgf/ta+jqCu9dZ9EbDx+qdJR5eZ5wyrc03cjDx4SuuXGSxdwoXnj2osrchL6tDTn/P qLrxGfpsN3Y6sPjBzMG9QiEwC1gVU26kGFaAIKviRScpo0Cf55wuJCirAULpkdQqr2cb IMag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=I5J0MyK9p+C/uNZWK6IwqUHsGTQMdMhwYonyf18bM28=; b=ByuArU4JdV0+Rl60/Arg/zuxSqBISscKLFtWW9DWQrGrI+r5MVDITcOvMp/T6Bri6t YC7gs7/bOjH7ty6MsgZZ1LzSw8CFB2bn4kz8HdFUMTfKvpSZ99lO7q+p0LD/cU8ByhDt 7e9eivuGT1iuURQeOM+xWzjuY/vk7TQhU7FuxDIUdPtO2vDyjj/6WLCfkA7kXJ2yBqjp b+icslYVjxwDQz7ck804zDPt/OTRQV/oDMaTz6hl0A6uNmAIOEo/T06jmurD04cFUum7 nciZeKHkJzV1pf8ciqIGDJQLNuNfUJ3EqlUMeht/JSahgxb4/p4OGNd1wCJHtTDv1vzT 8LoA== X-Gm-Message-State: AKaTC02OiPCWXxkxH1IG/h/a1T5YVhNRZJamz33tQB1SpXTJmzh3lanv4GQqn9Twdqrm0w== X-Received: by 10.99.241.21 with SMTP id f21mr60653844pgi.110.1480518223462; Wed, 30 Nov 2016 07:03:43 -0800 (PST) Original-Received: from calancha-pc (177.192.218.133.dy.bbexcite.jp. [133.218.192.177]) by smtp.gmail.com with ESMTPSA id c2sm103654862pfl.66.2016.11.30.07.03.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Nov 2016 07:03:42 -0800 (PST) In-Reply-To: <87twapgiy6.fsf@users.sourceforge.net> (npostavs's message of "Wed, 30 Nov 2016 09:07:13 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:126307 Archived-At: npostavs@users.sourceforge.net writes: Hi Noa, thanks for your time reading the report and for bringing those points! > Tino Calancha writes: > >> Christopher Genovese writes: >> >>> I've attached a modified patch file that includes >>> all your suggested changes. I did some squashing >>> and editing, so this patch has the same three parts >>> as before, with properly formatted Change Logs in >>> each. > > You don't need the "Change Log: 2016-11-27 Christopher R. Genovese > " part, that information is extracted automatically > from the commit metadata. See the below patch. It doesn't include ChangeLog in the commit message. >> Thank you very much fr your prompt replay! >> >> I) >> + 'follow-link t >> + 'help-echo "Click or RET: save new value in customize" >> + 'action (lambda (b) >> + (if (not (fboundp 'customize-save-variable)) >> + (message "Customize not available; value not saved") >> + (customize-save-variable 'ibuffer-saved-filters >> + ibuffer-saved-filters) >> + (message "Saved updated ibuffer-saved-filters.")))) >> The lambda form above doesn't use its 'b' argument, so i have dropped >> it. > > By "drop" I hope you meant "replaced it with `_'". The action function > receives 1 argument, so it has to accept it Thank you, i didn't know that. I updated to 'action (lambda (_b) > I don't really agree with this switching *Warnings* to help-mode. > First, it's out of place for a particular warning to start manipulating > the *Warnings* buffer like that. And second, it would make more sense > to have a warnings-mode, that could provide more specialized bindings > (e.g., ignore warning at point). But that's a subject for another > thread. I don't think this patch should do anything about it. OK. I switched back to the OP version, i.e., without `help-mode' in the buffer displaying the warning. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From b01ef57f393d24e3ed81630b8dfa69e19a9e6f98 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Wed, 30 Nov 2016 23:49:53 +0900 Subject: [PATCH] ibuffer-saved-filters: Remove extra nesting level * lisp/ibuf-ext.el (ibuffer-saved-filters): Remove extra nesting level; add transparent setter to adjust old-format values; update doc string. (ibuffer-save-filters): Remove extra level of nesting in ibuffer-saved-filters values when saving new filters (Bug#25049). (ibuffer-old-saved-filters-warning): New variable with clickable message with repair options to be displayed as a warning if 'ibuffer-repair-saved-filters' detects a format mismatch. (ibuffer-repair-saved-filters): Add new command to check and repair saved filters format. (ibuffer-included-in-filter-p, ibuffer-decompose-filter): Change access of saved filter data (cadr->cdr) to account for reduced nesting. * test/lisp/ibuffer-tests.el (ibuffer-save-filters): New test; check that filters are saved in the proper format. --- lisp/ibuf-ext.el | 156 +++++++++++++++++++++++++++++++++++---------- test/lisp/ibuffer-tests.el | 29 +++++++++ 2 files changed, 150 insertions(+), 35 deletions(-) diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el index 5ef0746..dbaafa6 100644 --- a/lisp/ibuf-ext.el +++ b/lisp/ibuf-ext.el @@ -35,7 +35,8 @@ (eval-when-compile (require 'ibuf-macs) - (require 'cl-lib)) + (require 'cl-lib) + (require 'subr-x)) ;;; Utility functions (defun ibuffer-delete-alist (key alist) @@ -119,32 +120,100 @@ ibuffer-tmp-show-regexps (defvar ibuffer-auto-buffers-changed nil) -(defcustom ibuffer-saved-filters '(("gnus" - ((or (mode . message-mode) - (mode . mail-mode) - (mode . gnus-group-mode) - (mode . gnus-summary-mode) - (mode . gnus-article-mode)))) - ("programming" - ((or (mode . emacs-lisp-mode) - (mode . cperl-mode) - (mode . c-mode) - (mode . java-mode) - (mode . idl-mode) - (mode . lisp-mode))))) - - "An alist of filter qualifiers to switch between. +(defun ibuffer-update-saved-filters-format (filters) + "Transforms alist from old to new `ibuffer-saved-filters' format. + +Specifically, converts old-format alist with values of the +form (STRING (FILTER-SPECS...)) to alist with values of the +form (STRING FILTER-SPECS...), where each filter spec should be a +cons cell with a symbol in the car. Any elements in the latter +form are kept as is. + +Returns (OLD-FORMAT-DETECTED . UPDATED-SAVED-FILTERS-LIST)." + (when filters + (let* ((old-format-detected nil) + (fix-filter (lambda (filter-spec) + (if (symbolp (car (cadr filter-spec))) + filter-spec + (setq old-format-detected t) ; side-effect + (cons (car filter-spec) (cadr filter-spec))))) + (fixed (mapcar fix-filter filters))) + (cons old-format-detected fixed)))) -This variable should look like ((\"STRING\" QUALIFIERS) - (\"STRING\" QUALIFIERS) ...), where -QUALIFIERS is a list of the same form as -`ibuffer-filtering-qualifiers'. -See also the variables `ibuffer-filtering-qualifiers', -`ibuffer-filtering-alist', and the functions -`ibuffer-switch-to-saved-filters', `ibuffer-save-filters'." - :type '(repeat sexp) +(defcustom ibuffer-saved-filters '(("gnus" + (or (mode . message-mode) + (mode . mail-mode) + (mode . gnus-group-mode) + (mode . gnus-summary-mode) + (mode . gnus-article-mode))) + ("programming" + (or (mode . emacs-lisp-mode) + (mode . cperl-mode) + (mode . c-mode) + (mode . java-mode) + (mode . idl-mode) + (mode . lisp-mode)))) + + "An alist mapping saved filter names to filter specifications. + +Each element should look like (\"NAME\" . FILTER-LIST), where +FILTER-LIST has the same structure as the variable +`ibuffer-filtering-qualifiers', which see. The filters defined +here are joined with an implicit logical `and' and associated +with NAME. The combined specification can be used by name in +other filter specifications via the `saved' qualifier (again, see +`ibuffer-filtering-qualifiers'). They can also be switched to by +name (see the functions `ibuffer-switch-to-saved-filters' and +`ibuffer-save-filters'). The variable `ibuffer-save-with-custom' +affects how this information is saved for future sessions. This +variable can be set directly from lisp code." + :version "26.1" + :type '(alist :key-type (string :tag "Filter name") + :value-type (repeat :tag "Filter specification" sexp)) + :set (lambda (symbol value) + ;; Just set-default but update legacy old-style format + (set-default symbol (cdr (ibuffer-update-saved-filters-format value)))) :group 'ibuffer) +(defvar ibuffer-old-saved-filters-warning + (concat "Deprecated format detected for variable `ibuffer-saved-filters'. + +The format has been repaired and the variable modified accordingly. +You can save the current value through the customize system by +either clicking or hitting return " + (make-text-button + "here" nil + 'face '(:weight bold :inherit button) + 'mouse-face '(:weight normal :background "gray50" :inherit button) + 'follow-link t + 'help-echo "Click or RET: save new value in customize" + 'action (lambda (_b) + (if (not (fboundp 'customize-save-variable)) + (message "Customize not available; value not saved") + (customize-save-variable 'ibuffer-saved-filters + ibuffer-saved-filters) + (message "Saved updated ibuffer-saved-filters.")))) + ". See below for +an explanation and alternative ways to save the repaired value. + +Explanation: For the list variable `ibuffer-saved-filters', +elements of the form (STRING (FILTER-SPECS...)) are deprecated +and should instead have the form (STRING FILTER-SPECS...), where +each filter spec is a cons cell with a symbol in the car. See +`ibuffer-saved-filters' for details. The repaired value fixes +this format without changing the meaning of the saved filters. + +Alternative ways to save the repaired value: + + 1. Do M-x customize-variable and entering `ibuffer-saved-filters' + when prompted. + + 2. Set the updated value manually by copying the + following emacs-lisp form to your emacs init file. + +%s +")) + (defvar ibuffer-filtering-qualifiers nil "A list like (SYMBOL . QUALIFIER) which filters the current buffer list. See also `ibuffer-filtering-alist'.") @@ -224,6 +293,28 @@ ibuffer-save-with-custom :type 'boolean :group 'ibuffer) +(defun ibuffer-repair-saved-filters () + "Updates `ibuffer-saved-filters' to its new-style format, if needed. + +If this list has any elements of the old-style format, a +deprecation warning is raised, with a button allowing persistent +update. Any updated filters retain their meaning in the new +format. See `ibuffer-update-saved-filters-format' and +`ibuffer-saved-filters' for details of the old and new formats." + (interactive) + (when (and (boundp 'ibuffer-saved-filters) ibuffer-saved-filters) + (let ((fixed (ibuffer-update-saved-filters-format ibuffer-saved-filters))) + (prog1 + (setq ibuffer-saved-filters (cdr fixed)) + (when-let (old-format-detected? (car fixed)) + (let ((warning-series t) + (updated-form + (with-output-to-string + (pp `(setq ibuffer-saved-filters ',ibuffer-saved-filters))))) + (display-warning + 'ibuffer + (format ibuffer-old-saved-filters-warning updated-form)))))))) + (defun ibuffer-ext-visible-p (buf all &optional ibuffer-buf) (or (ibuffer-buf-matches-predicates buf ibuffer-tmp-show-regexps) @@ -535,13 +626,11 @@ ibuffer-included-in-filter-p-1 (ibuffer-included-in-filter-p buf x)) (cdr filter)))) (`saved - (let ((data - (assoc (cdr filter) - ibuffer-saved-filters))) + (let ((data (assoc (cdr filter) ibuffer-saved-filters))) (unless data (ibuffer-filter-disable t) (error "Unknown saved filter %s" (cdr filter))) - (ibuffer-included-in-filters-p buf (cadr data)))) + (ibuffer-included-in-filters-p buf (cadr data)))) (_ (pcase-let ((`(,_type ,_desc ,func) (assq (car filter) ibuffer-filtering-alist))) @@ -849,15 +938,12 @@ ibuffer-decompose-filter (cdr lim) ibuffer-filtering-qualifiers))) (`saved - (let ((data - (assoc (cdr lim) - ibuffer-saved-filters))) + (let ((data (assoc (cdr lim) ibuffer-saved-filters))) (unless data (ibuffer-filter-disable) (error "Unknown saved filter %s" (cdr lim))) - (setq ibuffer-filtering-qualifiers (append - (cadr data) - ibuffer-filtering-qualifiers)))) + (setq ibuffer-filtering-qualifiers + (append (cdr data) ibuffer-filtering-qualifiers)))) (`not (push (cdr lim) ibuffer-filtering-qualifiers)) @@ -936,7 +1022,7 @@ ibuffer-save-filters ibuffer-filtering-qualifiers))) (ibuffer-aif (assoc name ibuffer-saved-filters) (setcdr it filters) - (push (list name filters) ibuffer-saved-filters)) + (push (cons name filters) ibuffer-saved-filters)) (ibuffer-maybe-save-stuff)) ;;;###autoload diff --git a/test/lisp/ibuffer-tests.el b/test/lisp/ibuffer-tests.el index 3a4def3..6d5187a 100644 --- a/test/lisp/ibuffer-tests.el +++ b/test/lisp/ibuffer-tests.el @@ -66,5 +66,34 @@ (mapc (lambda (buf) (when (buffer-live-p buf) (kill-buffer buf))) (list buf1 buf2))))) +(ert-deftest ibuffer-save-filters () + "Tests that `ibuffer-save-filters' saves in the proper format." + (skip-unless (featurep 'ibuf-ext)) + (let ((ibuffer-save-with-custom nil) + (ibuffer-saved-filters nil) + (test1 '((mode . org-mode) + (or (size-gt . 10000) + (and (not (starred-name)) + (directory . "\"))))) + (test2 '((or (mode . emacs-lisp-mode) (file-extension . "elc?") + (and (starred-name) (name . "elisp")) + (mode . lisp-interaction-mode)))) + (test3 '((size-lt . 100) (derived-mode . prog-mode) + (or (filename . "scratch") + (filename . "bonz") + (filename . "temp"))))) + (ibuffer-save-filters "test1" test1) + (should (equal (car ibuffer-saved-filters) (cons "test1" test1))) + (ibuffer-save-filters "test2" test2) + (should (equal (car ibuffer-saved-filters) (cons "test2" test2))) + (should (equal (cadr ibuffer-saved-filters) (cons "test1" test1))) + (ibuffer-save-filters "test3" test3) + (should (equal (car ibuffer-saved-filters) (cons "test3" test3))) + (should (equal (cadr ibuffer-saved-filters) (cons "test2" test2))) + (should (equal (car (cddr ibuffer-saved-filters)) (cons "test1" test1))) + (should (equal (cdr (assoc "test1" ibuffer-saved-filters)) test1)) + (should (equal (cdr (assoc "test2" ibuffer-saved-filters)) test2)) + (should (equal (cdr (assoc "test3" ibuffer-saved-filters)) test3)))) + (provide 'ibuffer-tests) ;; ibuffer-tests.el ends here -- 2.10.2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.4) of 2016-11-30 Repository revision: a283d655db88cdcc8cb53d8e2578e1cdf751c84b