unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lynn Winebarger <owinebar@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: monnier@iro.umontreal.ca, acm@muc.de, gregory@heytings.org,
	 emacs-devel@gnu.org
Subject: Re: Major modes using `widen' is a good, even essential, programming practice.
Date: Mon, 8 Aug 2022 10:24:38 -0400	[thread overview]
Message-ID: <CAM=F=bDbOE_H3yEK2oNaACYOsQFTkRbYpuehVz+aYszwoMePCw@mail.gmail.com> (raw)
In-Reply-To: <834jynvtwi.fsf@gnu.org>

On Mon, Aug 8, 2022 at 7:48 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Lynn Winebarger <owinebar@gmail.com>
> > Date: Mon, 8 Aug 2022 07:16:44 -0400
> > Cc: Eli Zaretskii <eliz@gnu.org>, Alan Mackenzie <acm@muc.de>, gregory@heytings.org,
> >       emacs-devel <emacs-devel@gnu.org>
> >
> > I know CC mode relies on heuristics to identify syntactic structures, and not a full parser (whether from
> > semantic or LSP), but it seems the issue is that you don't have a parse state for the beginning of the
> > narrowed buffer, where an initial parse state is inappropriate.  Assuming that text outside the narrowing is
> > not allowed to change, determining the appropriate parse state should only be required once on narrowing.
> > So, could there be a pre-narrowing hook to run before narrowing takes effect to allow a major mode to
> > determine the appropriate parse state for the beginning of the narrowed buffer?
>
> Why do you need a hook?  When the mode is first enabled in the buffer,
> there will be no narrowing in effect yet, so the mode could do
> whatever it wants at that time.
>
> Of course, this won't help us to solve the issues discussed here,
> because scanning the entire buffer at any time is slow and
> non-scalable.
>
I think you answered your own question - the code (I believe we're
discussing jit-lock on arbitrarily long lines in the particular) doing
the narrowing would have to identify the starting and ending points
via some special variable prior to running the hook, so the thunks
would be able to determine the right state *before* narrowing is
actually done.


> > Also, as I'm not a big user of explicit narrowing, the only place I've noticed it happening is in info mode, where
> > the focus is narrowed to a particular syntactic unit.
> > Is there a way for a major mode to let the user signal the syntactic unit that they believe they are narrowing
> > to, either with command variants or an interrogative(with a list of options supplied by the mode) when
> > narrowing is performed by the user interactively?  With the fall-back of either having the mode determine the
> > correct initial state or turning off fontification during the narrowing?
>
> We are not talking about user narrowing here.

Maybe not explicit user narrowing, but I don't think we're discussing
a piece of code that is just randomly jumping around a buffer,
narrowing and then requiring fontification without user interaction.
So, one way of handling it would be to have the code doing the
narrowing take the place of the user in the above scenario in some
programmatic way, perhaps using some prespecified (by the mode)
regular expressions to make a best guess at what the user response
would be based solely on local conditions.  A mode that doesn't
specify a way to make a selection could be defaulted to turn off
fontifcation while narrowing.

An approach that doesn't require cooperation from the mode would be to
* open a new buffer in the same mode
*  insert the characters from the narrowed region linearly in electric
mode (or something that would create newlines in "appropriate" places
for the user's preferred style),
*  indent and fontify that buffer in some way so the indentation of
the first line is consistent with the indentation of the last line
(e.g. if the narrowed region is a series of '}' in CC mode, the first
"}" should be indented to reflect the level implied by the number of
"}"s therein - if necessary by inserting leading matching delimiters
in the reverse order)
*  copy the fontification back to the region in the original buffer

Or to do something equivalent to that without actually opening the
additional buffer.  This method would have the advantage of being
entirely local.

Of course, as a user, I would like to have a command that lets me take
a point that I *know* the correct syntactic classification of, and
specify that from a menu, then have the mode fontify with the
constraint that my assertion is held constant, at least until there is
a modification at the point I made the assertion.

Lynn



  reply	other threads:[~2022-08-08 14:24 UTC|newest]

Thread overview: 136+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-06 20:13 Major modes using `widen' is a good, even essential, programming practice Alan Mackenzie
2022-08-06 21:05 ` Stefan Monnier
2022-08-07  6:03 ` Eli Zaretskii
2022-08-07 13:31 ` Gregory Heytings
2022-08-07 14:13   ` Alan Mackenzie
2022-08-07 14:20     ` Eli Zaretskii
2022-08-07 14:59       ` Alan Mackenzie
2022-08-07 15:13         ` Eli Zaretskii
2022-08-07 17:01           ` Alan Mackenzie
2022-08-07 17:23             ` Eli Zaretskii
2022-08-07 17:53               ` Dmitry Gutov
2022-08-07 18:00                 ` Eli Zaretskii
2022-08-07 18:05                   ` Dmitry Gutov
2022-08-07 18:37                     ` Eli Zaretskii
2022-08-07 23:02                       ` Stefan Monnier
2022-08-07 18:49                   ` Óscar Fuentes
2022-08-07 18:59                     ` Eli Zaretskii
2022-08-07 18:56                   ` Lars Ingebrigtsen
2022-08-07 19:20               ` Alan Mackenzie
2022-08-07 19:26                 ` Dmitry Gutov
2022-08-08  2:36                 ` Eli Zaretskii
2022-08-08  9:58                   ` Alan Mackenzie
2022-08-08 11:39                     ` Eli Zaretskii
2022-08-08 15:05                       ` CC Mode with font-lock-maximum-decoration 2 [Was Major modes using `widen' is a good, even essential, programming practice.] Alan Mackenzie
2022-08-08 15:51                         ` Gregory Heytings
2022-08-08 16:05                           ` CC Mode with font-lock-maximum-decoration 2 Alan Mackenzie
2022-08-08 16:50                             ` Gregory Heytings
2022-08-09 19:49                               ` Gregory Heytings
2022-08-08 17:15                         ` CC Mode with font-lock-maximum-decoration 2 [Was Major modes using `widen' is a good, even essential, programming practice.] Eli Zaretskii
2022-08-08 17:41                           ` Eli Zaretskii
2022-08-08 18:41                             ` CC Mode with font-lock-maximum-decoration 2 Alan Mackenzie
2022-08-08 18:51                               ` Eli Zaretskii
2022-08-08 19:09                                 ` Alan Mackenzie
2022-08-09  2:24                                   ` Eli Zaretskii
2022-08-09  8:00                                     ` Alan Mackenzie
2022-08-09 11:07                                       ` Eli Zaretskii
2022-08-09 11:24                                         ` Alan Mackenzie
2022-08-09 11:57                                           ` Eli Zaretskii
2022-08-09 16:36                                             ` Alan Mackenzie
2022-08-09 16:59                                               ` Eli Zaretskii
2022-08-09 17:43                                                 ` Alan Mackenzie
2022-08-09 17:55                                                   ` Eli Zaretskii
2022-08-10  0:22                                                     ` Why tree-sitter instead of Semantic? (was Re: CC Mode with font-lock-maximum-decoration 2) Lynn Winebarger
2022-08-10  2:14                                                       ` Po Lu
2022-08-10  2:42                                                         ` Eli Zaretskii
2022-08-10 10:05                                                           ` Lynn Winebarger
2022-08-10 10:49                                                             ` Po Lu
2022-08-10 11:31                                                             ` Eli Zaretskii
2022-08-12 12:37                                                               ` Lynn Winebarger
2022-08-12 12:50                                                                 ` Eli Zaretskii
2022-08-12 21:50                                                                   ` Ideal performance of ELisp (was: Why tree-sitter instead of Semantic? (was Re: CC Mode with font-lock-maximum-decoration 2)) Stefan Monnier
2022-08-12 23:26                                                                     ` Lynn Winebarger
2022-08-13  2:11                                                                       ` Ideal performance of ELisp Stefan Monnier
2022-08-13 10:51                                                                         ` Lynn Winebarger
2022-08-13 11:13                                                                           ` Lynn Winebarger
2022-08-13 14:07                                                                           ` Stefan Monnier
2022-08-13 14:56                                                                             ` Lynn Winebarger
2022-08-16 16:46                                                                               ` Lynn Winebarger
2022-08-16 17:22                                                                                 ` Stefan Monnier
2022-08-17 12:41                                                                                   ` Lynn Winebarger
2022-08-17 14:04                                                                                     ` Stefan Monnier
2022-08-17 14:19                                                                                       ` Mattias Engdegård
2022-08-17 22:18                                                                                         ` Stefan Monnier
2022-08-17 14:25                                                                                       ` Lynn Winebarger
2022-08-13  4:39                                                                     ` Ideal performance of ELisp (was: Why tree-sitter instead of Semantic? (was Re: CC Mode with font-lock-maximum-decoration 2)) Ihor Radchenko
2022-08-13  7:45                                                                       ` Ideal performance of ELisp Philip Kaludercic
2022-08-13 11:58                                                                         ` Ihor Radchenko
2022-08-13 14:15                                                                       ` Stefan Monnier
2022-08-14  9:25                                                                         ` Andrea Corallo
2022-08-14  9:34                                                                           ` Ihor Radchenko
2022-08-14 13:01                                                                             ` Eli Zaretskii
2022-08-16 19:23                                                                             ` Andrea Corallo
2022-08-14 13:01                                                                           ` Stefan Monnier
2022-08-16  8:59                                                                             ` Andrea Corallo
2022-08-16  9:50                                                                               ` Ihor Radchenko
2022-08-16 18:21                                                                                 ` Andrea Corallo
2022-08-17  9:48                                                                                   ` Ihor Radchenko
2022-08-17 12:02                                                                                     ` Eli Zaretskii
2022-08-16 15:06                                                                               ` Lynn Winebarger
2022-08-16 18:24                                                                                 ` Andrea Corallo
2022-08-17 13:04                                                                                   ` Lynn Winebarger
2022-08-17 14:18                                                                                     ` Andrea Corallo
2022-08-18 12:17                                                                                       ` Lynn Winebarger
2022-08-12 16:00                                                                 ` Why tree-sitter instead of Semantic? (was Re: CC Mode with font-lock-maximum-decoration 2) Akib Azmain Turja
2022-08-12 19:06                                                                   ` tomas
2022-08-13  4:41                                                                     ` Akib Azmain Turja
2022-08-13  5:14                                                                       ` tomas
2022-08-13 11:57                                                                   ` Lynn Winebarger
2022-08-13 14:28                                                                     ` Akib Azmain Turja
2022-08-14 19:24                                                         ` Eric Ludlam
2022-08-16 10:42                                                           ` Lynn Winebarger
2022-08-17  1:56                                                             ` Eric Ludlam
2022-08-10 17:03                                                       ` Tassilo Horn
2022-08-13 14:40                                                       ` Jostein Kjønigsen
2022-08-14  1:23                                                         ` Po Lu
2022-08-16  9:06                                                           ` Lynn Winebarger
2022-08-16 11:05                                                             ` Po Lu
2022-08-16 11:41                                                             ` Eli Zaretskii
2022-08-16 16:33                                                               ` Lynn Winebarger
2022-08-16 17:19                                                                 ` Stefan Monnier
2022-08-16 17:40                                                                   ` Lynn Winebarger
2022-08-17  1:41                                                                     ` Eric Ludlam
2022-08-18 12:34                                                                       ` Lynn Winebarger
2022-08-20 13:15                                                                         ` Eric Ludlam
2022-08-08 18:20                           ` CC Mode with font-lock-maximum-decoration 2 Alan Mackenzie
2022-08-07 20:17     ` Major modes using `widen' is a good, even essential, programming practice Gregory Heytings
2022-08-07 20:46       ` Alan Mackenzie
2022-08-07 20:53         ` Gregory Heytings
2022-08-08  2:37         ` Eli Zaretskii
2022-08-08 10:33           ` Alan Mackenzie
2022-08-08 11:41             ` Eli Zaretskii
2022-08-07 23:21     ` Stefan Monnier
2022-08-08  2:29       ` Eli Zaretskii
2022-08-08  9:25         ` Stefan Monnier
2022-08-08 11:16           ` Lynn Winebarger
2022-08-08 11:47             ` Eli Zaretskii
2022-08-08 14:24               ` Lynn Winebarger [this message]
2022-08-08 11:30           ` Eli Zaretskii
2022-08-08 12:05             ` Stefan Monnier
2022-08-08 12:40               ` Eli Zaretskii
2022-08-08 17:22                 ` Stefan Monnier
2022-08-08 17:34                   ` Eli Zaretskii
2022-08-08 21:16             ` Dmitry Gutov
2022-08-09 11:30               ` Eli Zaretskii
2022-08-09 14:38                 ` Dmitry Gutov
2022-08-09 16:12                   ` Eli Zaretskii
2022-08-09 16:52                     ` Dmitry Gutov
2022-08-09 17:05                       ` Eli Zaretskii
2022-08-09 18:52                         ` Dmitry Gutov
2022-08-09 19:46                           ` Gregory Heytings
2022-08-08 10:38       ` Alan Mackenzie
2022-08-08 11:49         ` Eli Zaretskii
2022-08-08 10:41       ` Gregory Heytings
2022-08-07 17:57 ` Dmitry Gutov
2022-08-22 11:26   ` Alan Mackenzie
2022-08-22 23:59     ` Dmitry Gutov

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='CAM=F=bDbOE_H3yEK2oNaACYOsQFTkRbYpuehVz+aYszwoMePCw@mail.gmail.com' \
    --to=owinebar@gmail.com \
    --cc=acm@muc.de \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=gregory@heytings.org \
    --cc=monnier@iro.umontreal.ca \
    /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).