bug#81661: 32.0.50; Offscreen context in show-paren-mode truncates multi-character keyword paren

Eli Zaretskii <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> Date: Wed, 19 Aug 2026 23:58:37 -0400
> From: Troy Brown via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email protected]>
> 
> Some languages, such as Ruby, highlight keywords when
> `show-paren-mode` is enabled.  The following demonstrates an example
> with a "do loop". Open the following in `ruby-mode`.
> 
> ```ruby
> 5.times do |i|
> 
> 
> 
> 
>   print "Number: #{i}"
> end
> ```
> 
> Either resize the window so the first line is not showing or insert
> more empty lines to force it off the screen.  Execute "M-: (setq
> show-paren-context-when-offscreen t) RET" to enable offscreen context
> display.  Move point to the end of the "end" keyword.  The echo area
> will show "Matches 5.times d".  The "do" keyword is truncated to the
> first character rather than showing the entire keyword.  This same
> problem manifests using other forms of offscreen context display as
> well, such as the "overlay" or "child-frame" settings.
> 
> The underlying issue appears to be the use of the
> `blink-paren-open-paren-line-string` function to construct the line of
> context which will be displayed in the echo area (or elsewhere).  That
> function only takes a single parameter consisting of the position in
> the buffer where the "paren" begins.  The function assumes the keyword
> "paren" is only a single character rather than possibly being multiple
> characters long.  The function attempts to truncate the context line
> such that the "paren" is the last part of the context, but assumes
> it's only a single character in length resulting in the keyword being
> truncated.

Thanks.

It would be nice if you (or someone else) could explain how Ruby mode
sets up this keyword highlighting in show-paren-mode.  It seems that
it customizes show-paren-data-function in some way, but I cannot find
where that happens and what is the code of the customized function, I
can only see its bytecode.

I can see what you describe, but I see no such problem in c-ts-mode,
which highlights preprocessor directives using a similar technique.
In the c-ts-mode case I see "Matches #ifdef FOO_BAR_BAZ", which shows
the full match, not just the first character.  So I wonder what is
different in how ruby-mode does this, but I've hit a brick wall
because I cannot find the code which implements this for Ruby.

Regarding blink-paren-open-paren-line-string: I'm not sure your
analysis is correct (and the c-ts-mode case seems to confirm my
conclusion): it doesn't always assume "paren" is a single character,
not for showing the context.  See these comments there:

       ;; Show what precedes the open in its line, if anything.

       ;; Show what follows the open in its line, if anything.

       ;; Otherwise show the previous nonblank line,
       ;; if there is one.

       ;; There is nothing to show except the char itself.

It's only in the last 2 cases that there's the 1-character assumption,
right?

Maybe Dmitry could help.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.