unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Shynur Xie <one.last.kiss@outlook.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "mattiase@acm.org" <mattiase@acm.org>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: Bug?
Date: Fri, 5 May 2023 16:18:54 +0000	[thread overview]
Message-ID: <SA0PR04MB743308ECC42B25547317C4DCD7729@SA0PR04MB7433.namprd04.prod.outlook.com> (raw)
In-Reply-To: <83v8h7jsph.fsf@gnu.org>

>    From: Eli Zaretskii
> Subject: Re: Bug?
>    Date: Fri, 05 May 2023 07:41:14 +0300
>      To: Shynur Xie
>
> didn't you tell that the problem reported above is not a bug, but
> the expected and long-time behavior of blink-matching-paren?

Yes, it is not a bug to the original author of this function.  But now
`show-paren-mode' also uses this function, which leads to a bug, or at
least a counterintuitive behavior:
> From: Mattias Engdegård
> For example, in shell-script-mode, when `esac` matches `case`, only
> the `c` in `case` is high-lit.

_____________________________

Let me explain it in details.

At first (when emacs-version is 28.2), there was only the function
`blink-matching-open'.  Later, someone refactored this function, by
separating out a part of it, thus there is a function named
`blink-paren-open-paren-line-string' now.

Both of the above 2 functions are defined in <lisp/simple.el> to
implement the basic parenthesis matching feature (let's call it
`blink-matching` for now) mentioned in:
> (emacs)26.4.3
> Emacs _briefly_indicates_ the location of the matching opening
> delimiter, ... If it is not on the screen, Emacs displays some of
> the text near it in the echo area."

The goal of `blink-matching` is just to _briefly_indicate_ the
location of delimiter (such as '(' in Lisp and 'case' in Bash), so it
is reasonable to _treat_only_the_1st_character_of_a_delimiter_
specially -- `blink-matching` highlights only the 1st character (to
observe this, you need to disable `show-paren-mode' first) when the
matched delimiter is on-screen; when it's off-screen, only the 1st
character is made sure to be contained in the message that is shown in
the echo area.  For example, in `shell-script-mode', when off-screen:
    case case  <- off-screen
         ^
         ...   <- many empty lines
         esac* <- cursor here
only "case c" is shown in the echo area.  Thus my first patch can only
highlights "c" because "ase" is not contained at all.  So
> From: Mattias Engdegård
> I also noticed that when the closing bracket is comprised of
> multiple characters, only the first character is high-lit using that
> face.

_____________________

> From: Eli Zaretskii
> Shynur, could you please fix this deficiency?

Deficiency, yes, it is, and belongs to `show-paren-mode'.

Let's take a look at what `show-paren-mode' provides first:
> (emacs)26.4.3
> Show Paren mode is a minor mode that provides a _more_powerful_ kind
> of automatic matching.
So this mode treats the entire matched delimiter specially, instead of
only the 1st character.  For example, in `shell-script-mode', when
on-screen:
    case  <- on-screen
    ^^^^
    esac* <- cursor here
the entire "case" is highlit.

But when off-screen, if `show-paren-context-when-offscreen' (an option
of `show-paren-mode') is t, the job of showing the matched off-screen
delimiter in the echo area is taken by `show-paren-mode' instead of
`blink-matching`.

I notice that `show-paren-mode` does this job
_simply_by_invoking_`blink-paren-open-paren-line-string'_, which
assumes that only the 1st character of the matched delimiter needs to
be treated specially -- same example as the first one I mentioned:
    case case  <- off-screen
         ^
         ...   <- many empty lines
         esac* <- cursor here
"case c" is shown in the area.

> From: Eli Zaretskii
> This seems to be about show-paren-mode, not about
> blink-matching-paren.

About both, IMO.  They both use `blink-paren-open-paren-line-string'
but this function only guarantees the returned string containes the
1st character of a delimiter, which is suitable for `blink-matching`
but not for `show-paren-mode'.

_____________________

> From: Eli Zaretskii
> what exactly does this patch fix?

It fixes cases such as "case c".  Thus, if
`show-paren-context-when-offscreen' is t, "case case", which contains
the entire matched delimiter -- "case", will be shown in the echo
area.  And if `blink-matching-paren-highlight-offscreen' is also t,
    "Matches case case"
                  ^^^^
the entire delimiter, instead of only its 1st character,  will be
highlit.

--
shynur


  reply	other threads:[~2023-05-05 16:18 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <875y9aciir.fsf.ref@yahoo.com>
2023-05-03  1:26 ` Bug? Po Lu
2023-05-03  9:40   ` Bug? Mattias Engdegård
2023-05-03 10:12     ` Bug? Mattias Engdegård
2023-05-03 11:24       ` Bug? Shynur Xie
2023-05-03 12:27         ` Bug? Mattias Engdegård
2023-05-03 17:22           ` Bug? Juri Linkov
2023-05-03 11:24       ` Bug? Eli Zaretskii
2023-05-03 11:26         ` Bug? Shynur Xie
2023-05-04  8:35         ` Bug? Shynur Xie
2023-05-04 20:57         ` Bug? Shynur Xie
2023-05-05  4:41           ` Bug? Eli Zaretskii
2023-05-05 16:18             ` Shynur Xie [this message]
2023-05-06 10:44           ` Bug? Mattias Engdegård
2023-05-06 14:58             ` Bug? Shynur Xie
2023-05-06 15:24               ` Bug? Eli Zaretskii
2023-05-07 11:08               ` Bug? Mattias Engdegård
2023-05-07 12:05                 ` Bug? Po Lu
2023-05-07 12:17                   ` Bug? Eli Zaretskii
2023-05-07 12:54                     ` Bug? Po Lu
2023-05-07 13:36                     ` Bug? Shynur Xie
2023-05-07 13:51                       ` Bug? Mattias Engdegård
2023-05-07 14:42                         ` Bug? Shynur Xie
2023-05-07 15:06                           ` Bug? Eli Zaretskii
2023-05-03 11:23     ` Bug? 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=SA0PR04MB743308ECC42B25547317C4DCD7729@SA0PR04MB7433.namprd04.prod.outlook.com \
    --to=one.last.kiss@outlook.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.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).