From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Filippo Argiolas Newsgroups: gmane.emacs.devel Subject: Re: [NonGNU ELPA] new package: eglot-inactive-regions Date: Mon, 02 Dec 2024 18:31:55 +0100 Message-ID: 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="35640"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, Gerd =?utf-8?Q?M=C3=B6llmann?= , Stefan Kangas To: Philip Kaludercic Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 02 18:32:59 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 1tIAI6-00098f-U4 for ged-emacs-devel@m.gmane-mx.org; Mon, 02 Dec 2024 18:32:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIAHN-0007Ow-AJ; Mon, 02 Dec 2024 12:32:14 -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 1tIAHG-0007LV-C5 for emacs-devel@gnu.org; Mon, 02 Dec 2024 12:32:06 -0500 Original-Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIAHD-0001iS-6X for emacs-devel@gnu.org; Mon, 02 Dec 2024 12:32:05 -0500 Original-Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-385e06af753so1749448f8f.2 for ; Mon, 02 Dec 2024 09:32:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733160719; x=1733765519; darn=gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=dpD9JdqFe79ln+wWki2IKgojuKCz3H5kINSgMpWkUYQ=; b=HIYiVL4TRyIdwrEphdlUV6ni3QzGFrK6BXSS8dUYuheL1TNSQYFFhYUcmsbBGdeCjY xAodhif97vIhdgQpb3WOu3fXIk4idqdt+5DOiESw6TKKTOwgG7GwtF1rtyFIKXys4yPU aOPP/HflHW92MFJc+KegYR3vG0qF/0W1rUurL7yIa/d7an7s//tNQ87scNjQawfbQImD 3FRM/y5ChNQxuk7nhtJ0jxpK4Fuh1dqck4BUfkXsRJ3zVo8yrAJZhHvGOq9WgAABarAf YjSZkVoqFvgevLmCXUYbEaruZqnMQZYTECk8lsPLHV8Tn0avYFfH1C+jz/QimL+sodno iDHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733160719; x=1733765519; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dpD9JdqFe79ln+wWki2IKgojuKCz3H5kINSgMpWkUYQ=; b=dCiDTSj+Ip1CfnuoiN3noKjIAbDUKsCE3nAHMTQi22jzSu4lwUakDEIZ2YdqPKgt33 6yTibUVoLvVBo6/hJ/8jgpSNqphx6wW5XXbxlsMx8y3VUV0qdEcdKHvMh9CXaLEwVT+U zpZcWnZI1P1fdw0+QHfQcV09G+FFnuBn6uE9iKgzXqnGy1gyOQLKb4H/66fn5mDXVtHf QBN+OQupVXpdQRbKiYvgMjYEsKj9JJp3tRHnFfHMkZK4VEui7qXnahgN3vgUZBIlqDYF sxUOvLmMVJ2Ag30BIY9s1iZuP1V6EH8eX3rbZvzPSlqT7iDg7Kspq+vmfdT5Bs93VTFU nmdw== X-Gm-Message-State: AOJu0YwOIUbfgRx4oy2L7wD2OA1hHA1FqeO2C0mJtSM4vZCXOxD5T3rX g3chihvGtPr+raABcHe2XubwOwb3FmC3Smm/UHATIYry8dfmHHHoi2khwyzj X-Gm-Gg: ASbGncsJoNw9/BRND+VkpGPGp8ks+A4+yveixHGRsRFL205eSY9KleLUuxb65OW5Amd nd7mr3NzexNIujLa26ZX4uS/ynYR9By0z9KImMuaKSiUAIdQFTA5eY0wcywy3qA3BKELxcUYE+8 XZFleKxXgMoht6WicnCY1l/VMkc91zb1HdCIwGIrMfH/HVOMNw/UNTiLTc7KANIGM5bau0I6DCR 8wsbtTwSUuflThM+fvMD+63LSgubG55SAQ9zo1LMi2N9mL0TIZv0dikblI= X-Google-Smtp-Source: AGHT+IHLwJ7snIFv8k1DDeH/5hI8bNcnla+6VemK3EM11X7iNjnZP2q9IPpLX7PJPhoegv6jK/XX8A== X-Received: by 2002:a5d:6d0a:0:b0:385:f66c:a4b with SMTP id ffacd0b85a97d-385f66c0fb1mr2930009f8f.47.1733160718275; Mon, 02 Dec 2024 09:31:58 -0800 (PST) Original-Received: from mba ([151.81.191.240]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434b0dc63b6sm158722365e9.22.2024.12.02.09.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 09:31:57 -0800 (PST) In-Reply-To: <874j3nrri7.fsf@posteo.net> Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=filippo.argiolas@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:325950 Archived-At: 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? > @@ -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. > @@ -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. > @@ -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? > @@ -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? > If anything is unclear or I misunderstood something, just ask! Thanks again! Filippo