GNU bug report logs - #46374
28.0.50; Ask me to save buffers only if they are under callers dir

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Sun, 7 Feb 2021 22:33:01 UTC

Severity: wishlist

Tags: fixed

Merged with 50380

Fixed in version 28.0.60

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


Message #102 received at 46374 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Hauke Rehfeld <hauke <at> haukerehfeld.de>
Cc: 46374 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Tino Calancha <tino.calancha <at> gmail.com>
Subject: Re: bug#46374: Regression: erronous calls to PRED switch major-mode
 of unrelated modified buffers
Date: Sun, 29 Aug 2021 19:38:20 +0300
> Hmmm, I'm pretty sure the changes to `save-some-buffers` here
> regarding the predicate indirection caused a regression and/or
> very unexpected behavior that causes bugs in previously working
> code.

Thanks, this is a very interesting case, so Cc'ing Stefan and Tino.

> Consider
>
> `(save-some-buffers t (lambda () (derived-mode-p 'org-mode)))'
>
> called from an org-mode buffer. It runs through the part of
> `save-some-buffers' that is trying to resolve the PRED
> indirection:
>
> ``` emacs-lisp
>  ;; Allow `pred' to be a function that returns a predicate
>  ;; with lexical bindings in its original environment
>  (bug#46374).
>  (let ((pred-fun (and (functionp pred) (funcall pred))))
>    (when (functionp pred-fun)
>      (setq pred pred-fun)))
> ```
> which evaluates the predicate to check if it returns a function --
> which `(derived-mode-p)' does, as it simply returns the major-mode
> symbol on success! In this case, it would be `#'org-mode'. So then
> `org-mode' is called on any unsaved buffers as a PREDICATE,
> switching those buffers to org-mode.

Indeed, the predicate returns a function, just to add more fun:

  (funcall (lambda () (derived-mode-p 'lisp-interaction-mode)))
  => lisp-interaction-mode

This means we need to invent some ad-hoc format to distinguish between
these cases.  For example, to create a lexically-bound predicate
at the beginning, it could be called with e.g.

  (save-some-buffers t '(eval . save-some-buffers-root))

and defcustom will look like:

(defcustom save-some-buffers-default-predicate nil
  :type '(choice (const :tag "Default" nil)
                 (function :tag "Only in subdirs of root"
                           (eval . save-some-buffers-root))
                 (function :tag "Custom function"))

Quite ugly, but I see no more natural way.




This bug report was last modified 3 years and 191 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.