From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#46374: 28.0.50; Ask me to save buffers only if they are under callers dir Date: Sun, 18 Apr 2021 16:27:33 +0200 Message-ID: <87wnsz7jmy.fsf@gmail.com> References: <878s7z4ihk.fsf@gmail.com> <87a6sdzeh6.fsf@mail.linkov.net> <87ft16g0u2.fsf@gmail.com> <87tupmisel.fsf@mail.linkov.net> <1952f2d9-51b6-a4ba-6c9e-98594222f017@gmail.com> <87r1kpemnr.fsf@mail.linkov.net> <87mtv6yloe.fsf@gmail.com> <871rcgr4qp.fsf@mail.linkov.net> <87zgz3gfqo.fsf@mail.linkov.net> <87blbhhghk.fsf@mail.linkov.net> <87pmzsgzh3.fsf@gmail.com> <87o8fc5jq0.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16763"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 46374@debbugs.gnu.org, Stefan Monnier , =?UTF-8?Q?Qu=C3=A1ch_?= =?UTF-8?Q?M=E1=BB=B9_?= =?UTF-8?Q?Uy=C3=AAn?= Nhi To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 18 16:28:10 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lY8PB-0004GV-9z for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Apr 2021 16:28:09 +0200 Original-Received: from localhost ([::1]:51912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lY8PA-0002St-AF for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Apr 2021 10:28:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lY8P4-0002Sb-35 for bug-gnu-emacs@gnu.org; Sun, 18 Apr 2021 10:28:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lY8P3-0007sM-S1 for bug-gnu-emacs@gnu.org; Sun, 18 Apr 2021 10:28:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lY8P3-00024t-P0 for bug-gnu-emacs@gnu.org; Sun, 18 Apr 2021 10:28:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Apr 2021 14:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46374 X-GNU-PR-Package: emacs Original-Received: via spool by 46374-submit@debbugs.gnu.org id=B46374.16187560637954 (code B ref 46374); Sun, 18 Apr 2021 14:28:01 +0000 Original-Received: (at 46374) by debbugs.gnu.org; 18 Apr 2021 14:27:43 +0000 Original-Received: from localhost ([127.0.0.1]:47378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lY8Ol-00024D-6Y for submit@debbugs.gnu.org; Sun, 18 Apr 2021 10:27:43 -0400 Original-Received: from mail-wr1-f53.google.com ([209.85.221.53]:36802) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lY8Oj-00023v-C8 for 46374@debbugs.gnu.org; Sun, 18 Apr 2021 10:27:41 -0400 Original-Received: by mail-wr1-f53.google.com with SMTP id m9so18562500wrx.3 for <46374@debbugs.gnu.org>; Sun, 18 Apr 2021 07:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=zlyHAoi4SDiOweTVg2MqDCkESCYmDig2Jn9VMAXqsE0=; b=RhI+/khcnq3iiDaIjN5Ja2qeBdf8iLyAUlahUJc7AapqpoIki0Xb5oEQJXGG2t8MWl zCINpvqthNAKO8gJYxhemDNAGvHtBUkb8ItL5zMc/d7gJE1Zdu8o5muRVGmQwl6qGVJQ hnJ94s7CpXe9i7fTblW7QRpCXPVrDzzndBK4eZqLSqk0thErlgWu63/JDkpdqPCtTwbi PrdknMnFKjTSo0eNWE/HT5oNeiHSdavS9BaM8n8TgG/doU8T7QUrXvfTMjnD+HgUUwDN pHQvPweq0oZ9e+C9d/D/CemzLlFXRiaRP5V6Ye2pIWQNp5Pxrd4fb2BEPrI8SlEUYuj4 cHOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=zlyHAoi4SDiOweTVg2MqDCkESCYmDig2Jn9VMAXqsE0=; b=nhWEtZebRbX20RIen+r5Eq/TDrOKn6ZuAREtWHXJdktDr+vYu6XLoXMgMP/tIPNrv5 Lm2EreJQKg0p/q7nFB20dzdK2P1KDzuIEPhwwdCJxl2NI1iSRAgtD7Buv8bBlJZo4vqa riTOqs5/mCsWCiBNyfAhWgRHlVqssWVHv+v8mIyiy/AE8vNKtQRjp2bbM2wyBKTObyyz EAN33bWkQTUhCc1RZfNR9qbE+czzN4ueBAWDxNS1eAo1WllPgSgKKMto5nqS1engPm+N xVupVM0p264jLcLEcCqHEmUGG+sAo9E6WG1Jto95adMH/bQH0T9oNd0zF+3B21mUFYxz X+PA== X-Gm-Message-State: AOAM533PoKIUtIRkCrVn1fQNZ8Eg78b8lCurq3YJUmmuo8gJjRknX5nZ vISe+aTPVxOnOHILd6YYMU8= X-Google-Smtp-Source: ABdhPJx2bz4kp5R9mBstfOv6K8N0PtZ/ZI31JNyd5RszKpfvCPLXj44zUWVB2qyFTeGoKnE7JyXetQ== X-Received: by 2002:a05:6000:1084:: with SMTP id y4mr9491967wrw.364.1618756055477; Sun, 18 Apr 2021 07:27:35 -0700 (PDT) Original-Received: from localhost.example.com ([31.7.242.222]) by smtp.gmail.com with ESMTPSA id t6sm18513672wrx.38.2021.04.18.07.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 07:27:34 -0700 (PDT) In-Reply-To: <87o8fc5jq0.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 21 Mar 2021 22:10:04 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:204336 Archived-At: Juri Linkov writes: >> I have noticed that I haven't enabled lexical-binding in my .emacs file, >> which it is crucial for my use case. >> To avoid surprises, I have mentioned this issue in the docstring. > > Unfortunately, your patch is truncated. Could you send a complete patch? Here is: --8<-----------------------------cut here---------------start------------->8--- commit 73b2ff479ab1f9af399e6d09ceff85bb8eaa66b0 Author: Tino Calancha Date: Sun Apr 18 16:14:13 2021 +0200 patch for Bug#46374 On top of commit 2822246b5d8154d0166e17ffd28a1d85b57d68aa diff --git a/lisp/files.el b/lisp/files.el index 7440c11a21..56ef949eeb 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5520,6 +5520,28 @@ save-some-buffers-default-predicate :type '(choice (const :tag "Default" nil) function) :version "26.1") +(defvar save-some-buffers-fun-function (lambda () save-some-buffers-default-predicate) + "Overrides the behavior of `save-some-buffers-default-predicate'. +This variable's value should be a function, which will be called +by `save-some-buffers' with no arguments to override the default predicate. +This allow you to capture variables in the environment of `save-some-buffers', +and use them to decide which buffers must be saved. +For instance, the following expression restricts to save only buffers inside +the project from where `save-some-buffers' is invoked, or under the +caller's `default-directory' if no project is found: + +\(lambda () + (let ((project-dir + (or (and (project-current) (project-root (project-current))) + default-directory))) + (lambda () (file-in-directory-p default-directory project-dir)))) + +Note that, the example above requires that you evaluate this expression +in a file or buffer with lexical binding enabled.") + +(defun save-some-buffers-fun () + (funcall save-some-buffers-fun-function)) + (defun save-some-buffers (&optional arg pred) "Save some modified file-visiting buffers. Asks user about each one. You can answer `y' or SPC to save, `n' or DEL not to save, `C-r' @@ -5547,7 +5569,7 @@ save-some-buffers change the additional actions you can take on files." (interactive "P") (unless pred - (setq pred save-some-buffers-default-predicate)) + (setq pred (save-some-buffers-fun))) (let* ((switched-buffer nil) (save-some-buffers--switch-window-callback (lambda (buffer) --8<-----------------------------cut here---------------end--------------->8---