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 14:36:42 +0000 Message-ID: <874jvig2rp.fsf@posteo.net> References: <87sfj8umwb.fsf@posteo.net> <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> <87h6zihq3q.fsf@posteo.net> <877d0ehlnb.fsf@posteo.net> <87edumg4fd.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6094"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 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@gnu.org Tue Nov 01 18:26:57 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 1opv2O-0001M3-SM for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Nov 2022 18:26:57 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opsO1-0003lr-4l; Tue, 01 Nov 2022 10:37:05 -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 1opsNy-0003lC-Uz for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 10:37: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 1opsNy-0003c1-Ma for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 10:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opsNy-00047g-4H for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 10:37: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 14:37: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.166731341415836 (code B ref 58839); Tue, 01 Nov 2022 14:37:02 +0000 Original-Received: (at 58839) by debbugs.gnu.org; 1 Nov 2022 14:36:54 +0000 Original-Received: from localhost ([127.0.0.1]:43975 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opsNq-00047K-1l for submit@debbugs.gnu.org; Tue, 01 Nov 2022 10:36:54 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:39209) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opsNo-000478-6S for 58839@debbugs.gnu.org; Tue, 01 Nov 2022 10:36:53 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id A658D240028 for <58839@debbugs.gnu.org>; Tue, 1 Nov 2022 15:36:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1667313406; bh=jvwBwx3y90+U9jOkSychBOnmFaZEDA+3leADCfEbYJU=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=bM+tmHl2xk9NbRSKNWww2Xljb9rMFcBYBVrJuhw0CLo3oiolQTy4lwZOkTwr5uOfF BGU/qd2rNUJlMH3Qh1hm2OhAM968rK+Id7/Nim8g5B24xqlF3X752YmEiyZjScND3B w8br5QAU/GZ9mRiRqiJe4lmkXnlpt2xGamm9FYheSub6UbtVMU63MFuhwldDVlL3CL 1EvDbBmNzB2ZppIvamX3Gf4byGThzHwcDG6IGdFPJyzl0X/vOOhLvqL5IbqYyi06Q1 uyoWWHdHmWx9ot8W3/AwSx3dkP5OCKqusECyo2oozQ/U+BqIr6IpjoYD4SEnRvyfxZ oSiHwCX6xvTkA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4N1szK0bFHz9rxV; Tue, 1 Nov 2022 15:36:42 +0100 (CET) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Tue, 1 Nov 2022 14:11:35 +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@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246791 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > On Tue, Nov 1, 2022 at 2:00 PM Philip Kaludercic wro= te: > > >> > My idea of using the byte-compiler to do this is different: it entails >> > translating the mini-language to elisp first and then byte-compiling >> > that. But it is a technique that I think your code isn't applying >> > or at least not correctly (though I haven't read all of it: I will soo= n). >> >> What I am doing is translating it into lambda expressions, but I could >> also try out translating it into an s-expression and passing that to >> `eval'... >> > > Yes, do that, but use byte-compile instead, not eval. I have tried both, and it doesn't appear to be a particular advantage one way or another. That being said, this approach is *a lot* faster, to the point that I first assumed it was broken: --8<---------------cut here---------------start------------->8--- (benchmark-run 1000 (match-buffers/compiled sample-condition)) ;; (0.469515746 5 0.3328363100000047) --8<---------------cut here---------------end--------------->8--- but it works: --8<---------------cut here---------------start------------->8--- (equal (match-buffers sample-condition) (match-buffers/compiled sample-cond= ition)) ;; =3D> t --8<---------------cut here---------------end--------------->8--- So this is certainly something worth considering as a replacement! Here is the implementation: --8<---------------cut here---------------start------------->8--- (defvar translate-buffer-condition-buffer-sym (make-symbol "buffer")) (defvar translate-buffer-condition-arg-sym (make-symbol "arg")) (defun translate-buffer-condition (condition) "Compile a CONDITION into a predicate function." (pcase-exhaustive condition ((or 't 'nil) condition) ((pred stringp) `(string-match-p ,condition (buffer-name ,translate-buffer-condition-b= uffer-sym))) ((pred functionp) (if (eq 1 (cdr (func-arity condition))) ;; FIXME: is `funcall' necessary here? `(funcall #',condition ,translate-buffer-condition-buffer-sym) `(funcall ,condition ,translate-buffer-condition-buffer-sym ,translate-buffer-condition-arg-sym))) (`(major-mode . ,mode) `(eq (buffer-local-value 'major-mode ,translate-buffer-condition-buffe= r-sym) ',mode)) (`(derived-mode . ,mode) `(provided-mode-derived-p (buffer-local-value 'major-mode ,translate-buffer-condition-buffer-s= ym) ',mode)) (`(not . ,cond) `(not ,(translate-buffer-condition cond))) (`(or . ,conds) `(or ,@(mapcar #'translate-buffer-condition conds))) (`(and . ,conds) `(and ,@(mapcar #'translate-buffer-condition conds))))) (defvar buffer-match-p-cache (make-hash-table :test 'eq)) (defun buffer-match-p/evaled (condition buffer-or-name &optional arg) "Return non-nil if BUFFER-OR-NAME matches CONDITION. CONDITION is either: - the symbol t, to always match, - the symbol nil, which never matches, - a regular expression, to match a buffer name, - a predicate function that takes a buffer object and ARG as arguments, and returns non-nil if the buffer matches, - a cons-cell, where the car describes how to interpret the cdr. The car can be one of the following: * `derived-mode': the buffer matches if the buffer's major mode is derived from the major mode in the cons-cell's cdr. * `major-mode': the buffer matches if the buffer's major mode is eq to the cons-cell's cdr. Prefer using `derived-mode' instead when both can work. * `not': the cdr is interpreted as a negation of a condition. * `and': the cdr is a list of recursive conditions, that all have to be met. * `or': the cdr is a list of recursive condition, of which at least one has to be met." (eval (or (gethash condition buffer-match-p-cache) (puthash condition (translate-buffer-condition condition) buffer-match-p-cache)) `((,translate-buffer-condition-buffer-sym . ,(get-buffer buffer-or-name)) (,translate-buffer-condition-arg-sym . ,arg)))) ;; Alternative implementation using `byte-compile': ;; ;; (funcall (or (gethash condition buffer-match-p-cache) ;; (puthash condition ;; (byte-compile ;; `(lambda (,translate-buffer-condition-buffer-sym ;; ,translate-buffer-condition-arg-sym) ;; ,(translate-buffer-condition condition))) ;; buffer-match-p-cache)) ;; (get-buffer buffer-or-name) arg) --8<---------------cut here---------------end--------------->8--- In the end, the second implementation using `byte-compile' might be preferable as it avoids using `eval'. > Jo=C3=A3o T=C3=A1vora