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.devel Subject: Re: [NonGNU ELPA] new package: eglot-inactive-regions Date: Tue, 03 Dec 2024 19:35:53 +0000 Message-ID: <878qswlfty.fsf@posteo.net> References: <874j3nrri7.fsf@posteo.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="7532"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, Gerd =?utf-8?Q?M=C3=B6llmann?= , Stefan Kangas To: Filippo Argiolas Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 03 20:37:38 2024 Return-path: Envelope-to: ged-emacs-devel@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 1tIYiH-0001qU-Ue for ged-emacs-devel@m.gmane-mx.org; Tue, 03 Dec 2024 20:37:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIYgm-0006Fh-9u; Tue, 03 Dec 2024 14:36:04 -0500 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 1tIYgk-0006Em-4y for emacs-devel@gnu.org; Tue, 03 Dec 2024 14:36:02 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIYgh-000235-Fc for emacs-devel@gnu.org; Tue, 03 Dec 2024 14:36:01 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id ABD34240027 for ; Tue, 3 Dec 2024 20:35:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1733254555; bh=B1prr6YMFcXc01O/9M3G66KK9J/SIzZBeHxiwROzrJk=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=F4tCnon4+Q93TaykzOlb6YIvG+seZrxED+dlqMUh1sn/nyDGNg2qkCZsVuXVDG5zp 9oVbz/d90S4MmHxwa1r0cWnaeF+SpUfjFd14dMlZsFK+Y+f14RTx8zHLA6pHgI5jjH bwRA0RuJVGGZdrpmXzRbs8Td1jgGU9GJMZ9Dw54sCINRqCWOLCsvqwPa/HO/fJE8Xc zif1nNXnOz2ZKIEVMdXWrbS+zPGOhBB7QeownphETV52bhJDiDooadd9032xb7ZLIT v2UkbrJT098JdvjCn8IwQ1QLN46SBHxwqwj9tPU4TgMx/NBCRycrzl3vdjL4UjfXVM TJtOb5pdwnLiw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Y2rVL3FRZz6tyw; Tue, 3 Dec 2024 20:35:54 +0100 (CET) In-Reply-To: (Filippo Argiolas's message of "Mon, 02 Dec 2024 18:31:55 +0100") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM OpenPGP: id=philipk@posteo.net; url="https://keys.openpgp.org/vks/v1/by-email/philipk@posteo.net"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:326002 Archived-At: Filippo Argiolas writes: > Philip Kaludercic writes: > >> Filippo Argiolas writes: >> >>> Hi all, >>> >>> a couple of weeks ago I submitted my clangd-inactive-regions package >>> NonGNU ELPA inclusion. Previous discussion led to renaming the package >>> to make it more general, so I am submitting it again. >>> >>> For whom who missed it, it's a little Eglot extension to visually style >>> inactive preprocessor branches in c/cpp code in a LSP powered way. >>> >>> You can find more at: >>> https://github.com/fargiolas/eglot-inactive-regions >> >> Here are a few comments and alternatives that you might be interested >> in: > > Thanks for the review, much appreciated! > Just a few comments below. > >> @@ -65,17 +66,15 @@ >> Used to mix foreground and background colors and apply to the foreground >> face of the inactive region. The lower the blending factor the more >> text will look dim." >> - :type '(float :tag "Opacity" :min 0.0 :max 1.0) >> - :set #'eglot-inactive-regions--set-and-refresh >> - :group 'inactive-regions) >> + :type '(float :tag "Opacity" :min 0.0 :max 1.0) ;:min and :max >> have no effect, but you can use :validate >> + :set #'eglot-inactive-regions--set-and-refresh) > > No idea how I came up with those, I was sure to have used another mode > as inspiration but it seems those are pure allucinations :) > >> @@ -157,13 +152,13 @@ Only applies to `shade-background' style." >> "Linearly interpolate between two colors. >> Blend colors FROM-COLOR and TO-COLOR with ALPHA interpolation >> factor." >> - (if-let ((from-rgb (color-name-to-rgb from-color)) >> - (to-rgb (color-name-to-rgb to-color)) >> - (alpha (min 1.0 (max 0.0 alpha)))) >> - (apply 'color-rgb-to-hex >> - (cl-mapcar #'(lambda (a b) (+ (* a alpha) (* b (- 1.0 alpha)))) >> + (if-let* ((from-rgb (color-name-to-rgb from-color)) >> + (to-rgb (color-name-to-rgb to-color)) >> + (alpha (min 1.0 (max 0.0 alpha)))) >> + (apply #'color-rgb-to-hex >> + (cl-mapcar (lambda (a b) (+ (* a alpha) (* b (- 1.0 alpha)))) >> from-rgb to-rgb)) >> - 'unspecified)) >> + 'unspecified)) > > Why the star variant if I don't need to bind variables sequentially? is > it just for future-proofness? The star-less version has been recently deprecated on the master branch. And despite not using the variables in subsequent terms, I like to imagine that if-let* makes more sense since the terms are still explicitly evaluated in the order in which they are listed. Furthermore, if you take a look at if-let, you will see that it is implemented in terms of if-let* which means that the bindings remain visible even if the name doesn't indicate that. >> @@ -197,7 +192,10 @@ If the correspondend \"eglot-inactive\" face doesn't not exist yet create it." >> (eglot-inactive-face (intern eglot-inactive-face-name)) >> (eglot-inactive-doc (concat (face-documentation parent-face) doc-suffix))) >> (unless (facep eglot-inactive-face) >> - (eval `(defface ,eglot-inactive-face '((t nil)) ,eglot-inactive-doc))) >> + (custom-declare-face >> + eglot-inactive-face >> + '((t nil)) >> + eglot-inactive-doc)) >> (set-face-foreground eglot-inactive-face eglot-inactive-fg) >> eglot-inactive-face)) > > Nice, I always struggle with eval quoting, definitely better with your version. Just double check that it works as intended. >> @@ -207,10 +205,14 @@ Some mode use `default' face for both generic keywords and >> whitespace while some other uses nil for whitespace. Either way >> we don't want to include whitespace in fontification." >> (let* ((prev-face (get-text-property (point) 'face)) >> - (_ (forward-char)) >> - (next-face (get-text-property (point) 'face))) >> + (next-face (progn >> + (forward-char) >> + (get-text-property (point) 'face)))) >> (while (and (eq prev-face next-face) >> - (not (thing-at-point 'whitespace))) >> + ;; what are you trying to do here? if you want to >> + ;; check if you are not on whitespace, consider >> + ;; something like (looking-at-p "[^[:space:]]"). >> + (not (thing-at-point 'whitespace))) >> (setq prev-face (get-text-property (point) 'face)) >> (forward-char) >> (setq next-face (get-text-property (point) 'face))))) > > Idea here is to jump to the next face change or whitespace. I believe I > wanted to avoid applying shaded faces to empty space. Probably I could > use a mix of `next-single-property-change' and `looking-at-p'. It's old > code I never got to review, will take a better look in the next few > days. Maybe there's no point of skipping whitespace after all. I would suspect that it would be easier and more efficient not to have to think about having multiple separate properties. >> @@ -280,16 +282,16 @@ Useful to update colors after a face or theme change." >> (dolist (range eglot-inactive-regions--ranges) >> (let ((beg (car range)) >> (end (cdr range))) >> - (cond >> - ((eq eglot-inactive-regions-style 'darken-foreground) >> + (pcase-exhaustive eglot-inactive-regions-style >> + ('darken-foreground >> (with-silent-modifications >> (put-text-property beg end 'eglot-inactive-region t)) >> (font-lock-flush)) >> - ((eq eglot-inactive-regions-style 'shadow-face) >> + ('shadow-face >> (let ((ov (make-overlay beg end))) >> (overlay-put ov 'face 'eglot-inactive-regions-shadow-face) >> (push ov eglot-inactive-regions--overlays))) >> - ((eq eglot-inactive-regions-style 'shade-background) >> + ('shade-background >> (let ((ov (make-overlay beg (1+ end)))) >> (overlay-put ov 'face 'eglot-inactive-regions-shade-face) >> (push ov eglot-inactive-regions--overlays)))))))) > > Isn't pcase overkill if no complex pattern matching is involved? It compiles down to the same (byte)code, so there is no overhead (macroexpand-all '(pcase foo ('one 1) ('two 2))) ;=> (cond ((eq foo 'one) (let nil 1)) ((eq foo 'two) (let nil 2))) and `pcase-exhaustive' raises an error earlier if the variable is in an unexpected state. >> @@ -320,7 +322,7 @@ Useful to update colors after a face or theme change." >> >> (defun eglot-inactive-regions--handle-notification (uri regions) >> "Update inactive REGIONS for the buffer corresponding to URI." >> - (when-let* ((path (expand-file-name (eglot--uri-to-path uri))) >> + (when-let* ((path (expand-file-name (eglot--uri-to-path uri))) >> ;note that this function is deprecated! > > I know, I believe I was even involved in deprecating it. At first I was > using the new version but a user forked the repo to make it work in 29.1 > where both functions are still private. > > What's the proper way to handle this without losing backwards > compatibility? I would try something of the form like (if (fboundp 'new-function) (new-function ...) (old-function ...)) If on the other hand there has already been a new release of Eglot with these commands, then just depend on that version and the issue would resolve itself. >> If anything is unclear or I misunderstood something, just ask! > > Thanks again! > > Filippo