unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Shynur Xie <one.last.kiss@outlook.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "63089@debbugs.gnu.org" <63089@debbugs.gnu.org>
Subject: bug#63089: [PATCH] Display offscreen matched openparen
Date: Fri, 28 Apr 2023 12:36:03 +0000	[thread overview]
Message-ID: <SA0PR04MB7433EA61E4194F813DE14859D76B9@SA0PR04MB7433.namprd04.prod.outlook.com> (raw)
In-Reply-To: <834jp0seoq.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1257 bytes --]

>    From: Eli Zaretskii
> Subject: bug#63089: [PATCH] Display offscreen matched openparen
>    Date: Fri, 28 Apr 2023 09:28:53 +0300
>      To: Shynur Xie
>
> please add a user option to enable this behavior.

I think it can be defcustomed in file "lisp/paren.el".  New version of
the patch is complete, please see the attached.

> don't unnecessarily introduce whitespace differences into the code

Got it.

> Why not use the 'shadow' face instead?

Thanks.  Have used the face 'shadow'.

> The original code didn't use backticks, so why do you need it in the
> new version?

My _original_ modification made some lines too long with `list' and
`cons', so I used all backticks in that function.  Since there's no
such problem in the subsequent modifications, I will use `list' and
`cons' if you think backticks are unnecessary (or weird).

>> +            (1+openparen-idx (1+ openparen-idx)))
>                ^^^^^^^^^^^^^^^
> This is a strange and confusing notation, please find a better name
> for this variable.

Have changed it to 'openparen-next-char-idx'.

> What is the status of your legal paperwork?

My assignment process with the FSF is complete.

Thanks again for your review of my patch!

--
shynur

[-- Attachment #2: 0001-Display-offscreen-matched-openparen.patch --]
[-- Type: application/octet-stream, Size: 6207 bytes --]

From 8644fa78a05ffe9a06d611dae0d4d45a413a34a0 Mon Sep 17 00:00:00 2001
From: Shynur <one.last.kiss@outlook.com>
Date: Fri, 28 Apr 2023 20:23:16 +0800
Subject: [PATCH] Display offscreen matched openparen

Propertize the matched openparen displayed in the echo area in order to make
it prominent; use light font for non-context characters (i.e., 'Matches').
* lisp/simple.el (blink-matching-open): Set face shadow for 'Matches'.
* lisp/simple.el (blink-paren-open-paren-line-string): Propertize the macthed
openparen's face by user option `show-paren-openparen-face-in-message'.
* lisp/paren.el (show-paren-openparen-face-in-message): Add a user option
which determines the face of the matched offscreen openparen shown in the
echo area.
---
 lisp/paren.el  |  8 ++++++
 lisp/simple.el | 68 ++++++++++++++++++++++++++++++++++----------------
 2 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/lisp/paren.el b/lisp/paren.el
index 4c91fd29490..b9ce3cbd45d 100644
--- a/lisp/paren.el
+++ b/lisp/paren.el
@@ -81,6 +81,14 @@ show-paren-when-point-in-periphery
   :type 'boolean
   :version "25.1")
 
+(defcustom show-paren-openparen-face-in-message '(:foreground "green")
+  "Set face for the matched offscreen openparen shown in the echo area.
+By default, the line containing the matched offscreen openparen is
+shown in the echo area, where the openparen's face will be propertized
+by this option."
+  :type '(choice face sexp (const nil))
+  :version "30.0")
+
 (defcustom show-paren-highlight-openparen t
   "Non-nil turns on openparen highlighting when matching forward.
 When nil, and point stands just before an open paren, the paren
diff --git a/lisp/simple.el b/lisp/simple.el
index b621e1603bd..997c600b6b6 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9312,47 +9312,73 @@ blink-matching-open
                  (delete-overlay blink-matching--overlay)))))
        ((not show-paren-context-when-offscreen)
         (minibuffer-message
-         "Matches %s"
-         (substring-no-properties
-          (blink-paren-open-paren-line-string blinkpos))))))))
+         #("Matches %s"
+           ;; Make the following text (i.e., %s) prominent.
+           0 7 (face shadow))
+         (blink-paren-open-paren-line-string blinkpos)))))))
 
 (defun blink-paren-open-paren-line-string (pos)
-  "Return the line string that contains the openparen at POS."
+  "Return the line string that contains the openparen at POS.
+Remove the line string's properties but give the openparen a face."
   (save-excursion
     (goto-char pos)
     ;; Capture the regions in terms of (beg . end) conses whose
     ;; buffer-substrings we want to show as a context string.  Ensure
     ;; they are font-locked (bug#59527).
-    (let (regions)
-      ;; Show what precedes the open in its line, if anything.
+    (let (regions
+          openparen-idx)
       (cond
+       ;; Show what precedes the open in its line, if anything.
        ((save-excursion (skip-chars-backward " \t") (not (bolp)))
-        (setq regions (list (cons (line-beginning-position)
-                                  (1+ pos)))))
+        (let ((bol (line-beginning-position)))
+          (setq regions `((,bol . ,(1+ pos)))
+                openparen-idx (- pos bol))))
        ;; Show what follows the open in its line, if anything.
        ((save-excursion
           (forward-char 1)
           (skip-chars-forward " \t")
           (not (eolp)))
-        (setq regions (list (cons pos (line-end-position)))))
+        (setq regions `((,pos . ,(line-end-position)))
+              openparen-idx 0))
        ;; Otherwise show the previous nonblank line,
        ;; if there is one.
        ((save-excursion (skip-chars-backward "\n \t") (not (bobp)))
-        (setq regions (list (cons (progn
-                                    (skip-chars-backward "\n \t")
-                                    (line-beginning-position))
-                                  (progn (end-of-line)
-                                         (skip-chars-backward " \t")
-                                         (point)))
-                            (cons pos (1+ pos)))))
+        (setq regions `((,(let (bol)
+                            (skip-chars-backward "\n \t")
+                            (setq bol (line-beginning-position)
+                                  openparen-idx (- bol))
+                            bol)
+                         . ,(let (eol)
+                              (end-of-line)
+                              (skip-chars-backward " \t")
+                              (setq eol (point)
+                                    openparen-idx (+ openparen-idx
+                                                     eol
+                                                     ;; (length "...")
+                                                     3))
+                              eol))
+                        (,pos . ,(1+ pos)))))
        ;; There is nothing to show except the char itself.
-       (t (setq regions (list (cons pos (1+ pos))))))
+       (t (setq regions `((,pos . ,(1+ pos)))
+                openparen-idx 0)))
       ;; Ensure we've font-locked the context region.
       (font-lock-ensure (caar regions) (cdar (last regions)))
-      (mapconcat (lambda (region)
-                   (buffer-substring (car region) (cdr region)))
-                 regions
-                 "..."))))
+      (let ((line-string
+             (mapconcat
+              (lambda (region)
+                (buffer-substring (car region) (cdr region)))
+              regions
+              "..."))
+            (openparen-next-char-idx (1+ openparen-idx)))
+        (setq line-string (substring-no-properties line-string))
+        (concat
+         (substring line-string
+                    0 openparen-idx)
+         (propertize (substring line-string
+                                openparen-idx openparen-next-char-idx)
+                     'face show-paren-openparen-face-in-message)
+         (substring line-string
+                    openparen-next-char-idx))))))
 
 (defvar blink-paren-function 'blink-matching-open
   "Function called, if non-nil, whenever a close parenthesis is inserted.
-- 
2.34.1


  reply	other threads:[~2023-04-28 12:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26 13:39 bug#63089: [PATCH] Display offscreen matched openparen Shynur Xie
2023-04-28  6:28 ` Eli Zaretskii
2023-04-28 12:36   ` Shynur Xie [this message]
2023-04-29 11:05     ` Eli Zaretskii
2023-04-30 10:09       ` Shynur Xie
2023-05-01 13:17         ` Eli Zaretskii
2023-05-01 17:52           ` Shynur Xie
2023-05-02 18:38             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SA0PR04MB7433EA61E4194F813DE14859D76B9@SA0PR04MB7433.namprd04.prod.outlook.com \
    --to=one.last.kiss@outlook.com \
    --cc=63089@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).