From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#58839: [Patch] Re: bug#58839: 29.0.50; project-kill-buffer fails when Eglot is running Date: Tue, 01 Nov 2022 11:27:21 +0000 Message-ID: <87h6zihq3q.fsf@posteo.net> References: <87sfj8umwb.fsf@posteo.net> <87a65f3j40.fsf@posteo.net> <213f3549-de4e-25a7-5e27-d13893e557bc@yandex.ru> <87zgdfwkle.fsf@gmail.com> <8e31a89d-e35e-6dd0-a8e3-f0b9684c8bfa@yandex.ru> <87v8o3wgq1.fsf@gmail.com> <87ilk2x1si.fsf@gmail.com> <871qqq7l9p.fsf@posteo.net> <87eduqwekz.fsf@gmail.com> <87wn8invbx.fsf@posteo.net> <877d0iw8iq.fsf@gmail.com> <837d0hhlke.fsf@gnu.org> <46ff0065-5645-ef1e-2621-242fb6a73f98@yandex.ru> <87v8o0uxn5.fsf@gmail.com> <787a4362-7ff5-7dbb-9118-16e4bee5f328@yandex.ru> <87edunvhf2.fsf@gmail.com> <6d4d9e72-1bae-4d64-b7c1-c2b9c11e396f@yandex.ru> <87tu3jgdbv.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26379"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , manuel.uberti@inventati.org, 58839@debbugs.gnu.org, Dmitry Gutov To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 01 12:28:20 2022 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 1oppRK-0006Yo-Iq for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Nov 2022 12:28:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oppR6-0001G2-PL; Tue, 01 Nov 2022 07:28:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oppR5-0001Fc-3N for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 07:28:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oppR4-0005hb-S9 for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 07:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oppR4-0004nc-Cg for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 07:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Nov 2022 11:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58839 X-GNU-PR-Package: emacs Original-Received: via spool by 58839-submit@debbugs.gnu.org id=B58839.166730205218401 (code B ref 58839); Tue, 01 Nov 2022 11:28:02 +0000 Original-Received: (at 58839) by debbugs.gnu.org; 1 Nov 2022 11:27:32 +0000 Original-Received: from localhost ([127.0.0.1]:42862 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oppQa-0004mg-8e for submit@debbugs.gnu.org; Tue, 01 Nov 2022 07:27:32 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:42545) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oppQY-0004mP-8O for 58839@debbugs.gnu.org; Tue, 01 Nov 2022 07:27:31 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 7F33B240026 for <58839@debbugs.gnu.org>; Tue, 1 Nov 2022 12:27:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1667302044; bh=HL9xnZhzIT055WSzsrYrsZTjAKiUULttndU5fbMF5Rs=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=qlU61K/fextzQMqdFnoZzIOhfGe4ZbCEEAXq5Z5hiEKftn3TTCeADoT7T+R1GwavW S9+flxUE1aWLph3QPfJ+tj4BCdHP0Pl35+Phj3aikQKLGnbZdneVBH9a/0yq1WdpjO EmdLdX5Fw9G4HIxKrjwQXjHj9fD1fMsJu29o5Ic+aWintVRILlYxpIkm6l9pqO5Jt2 cAXlSoZn70mD8dtoXFiO0hxc/3zp/rE8WJ/g2cf2uQkvXYf4uSnr11ZqWLdaoojZQV 3OqZkRoCLVspw+UVk1rMbmSqDoxNqVmyfpAuG5NUY5cE/qVJ6lSxmB61BVjGCztt9Q jazZv9c3jPlNQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4N1nmp1w35z6tpn; Tue, 1 Nov 2022 12:27:22 +0100 (CET) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Tue, 1 Nov 2022 10:59:41 +0000") Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB 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: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246765 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Jo=C3=A3o T=C3=A1vora writes: > On Tue, Nov 1, 2022 at 10:48 AM Philip Kaludercic > wrote: > >> >> BTW, if there are major objections to the language, I should point out >> that the new `buffer-match-p' in Emacs 29 uses the same language and has >> already found usage in a number of spots in core Emacs. There would >> still be time to address any issues you might have, and avoid a >> long-term mistake. >> > > For me, it looks like match-buffers is reinventing > cl-remove-if-not and match-buffer-p is reinventing ... unary predicate > function of a buffer? You could say that, though I would argue it is an easier way to express common predicates, while not making anything else more complicated. E.g. `display-buffer-alist' makes use of it to associate display-buffer rules with buffers. Now you can add ((major-mode . help-mode) display-buffer-in-side-window) instead of trying to match being a regular expression to catch all *Help* buffer names of a function along the lines of (lambda (buf _alist) (with-current-buffer buf (derived-mode-p 'help-mode))) > I'm not fond of these mini-languages because they're less expressive, they > end up being only minimally less complicated and bug-prone, they can't > automatically be byte-compiled for efficiency, and they can't automatical= ly > be byte-compiled for correctness/diagnostics. If one makes a mistake, > the backtrace is much more complicated. I agree in principle, but this should be alleviated by using a lambda function as a predicate. The above check still works and can be used anywhere you would use `buffer-match-p'. > So these mini-languages may make sense to define filters in thunderbird or > something, but throwing Elisp away here generally doesn't make sense to m= e. > > But there may be exceptions (although this project.el one doesn't seem one > of them) so why don't you show examples of use of these new helpers and > so we can compare side by side with the Elisp-only alternative. I am biased, but I believe that the language could even find more use in project.el, by having `project-buffers' just call `match-buffers' with a special `buffer-match-p' predicate. Here is a sketch of how that could look like (I haven't tested it yet): --=-=-= Content-Type: text/plain Content-Disposition: inline diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index ac278edd40..b55c245368 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -352,15 +352,28 @@ project--remote-file-names (concat remote-id file)) local-files)))) +(defun project-includes-buffer-p (buffer dir) + "Return non-nil if the `default-directory' of BUFFER is below DIR." + (file-in-directory-p + (buffer-local-value 'default-directory buffer) + dir)) + +(defcustom project-buffer-conditions + '(and (or buffer-file-name + (derived-mode . compilation-mode) + (derived-mode . dired-mode) + (derived-mode . diff-mode) + (derived-mode . comint-mode) + (derived-mode . eshell-mode) + (derived-mode . change-log-mode)) + project-includes-buffer-p) + "A buffer predicate for matching what buffers belong to a project." + :type 'buffer-predicate) + (cl-defgeneric project-buffers (project) "Return the list of all live buffers that belong to PROJECT." - (let ((root (expand-file-name (file-name-as-directory (project-root project)))) - bufs) - (dolist (buf (buffer-list)) - (when (string-prefix-p root (expand-file-name - (buffer-local-value 'default-directory buf))) - (push buf bufs))) - (nreverse bufs))) + (let ((root (expand-file-name (file-name-as-directory (project-root project))))) + (match-buffers project-buffer-conditions nil root))) (defgroup project-vc nil "Project implementation based on the VC package." @@ -679,7 +692,7 @@ project-buffers (project--git-submodules)))) dd bufs) - (dolist (buf (buffer-list)) + (dolist (buf (cl-call-next-method)) (setq dd (expand-file-name (buffer-local-value 'default-directory buf))) (when (and (string-prefix-p root dd) (not (cl-find-if (lambda (module) (string-prefix-p module dd)) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 DQo+IEpvw6NvDQo= --=-=-=--