emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug?


From: Shynur Xie
Subject: Re: Bug?
Date: Fri, 5 May 2023 16:18:54 +0000

>    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 via email to

[Prev in Thread] Current Thread [Next in Thread]