unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: cc-mode: Make all parameters introduced in Emacs 26 optional
Date: Sat, 30 Mar 2019 19:42:04 +0000	[thread overview]
Message-ID: <20190330194204.GB6312@ACM> (raw)
In-Reply-To: <jwvtvfkz5qh.fsf-monnier+emacs@gnu.org>

Hello, Stefan.

On Sat, Mar 30, 2019 at 12:39:55 -0400, Stefan Monnier wrote:
> Hi Alan,

> > To set up a CC Mode derived mode to recognise strings 'like this', do the
> > following:
> > (i) Set the derived mode's value of `c-single-quotes-quote-strings' to t.
> > (This is done with `c-lang-defconst' in the derived mode's .el file).
> > (ii) Make sure the derived mode's value of
> > `c-get-state-before-change-function' does not include
> > `c-parse-quotes-before-change'.
> > (iii) Similarly ensure `c-before-font-lock-functions' doesn't contain
> > `c-parse-quotes-after-change'.
> > (iv) Ensure the derived mode's value of
> > `c-get-state-before-change-function' contains
> > `c-before-change-check-unbalanced-strings' and that of
> > `c-before-font-lock-functions' contains
> > 'c-after-change-mark-abnormal-strings'.
> > (v) Make sure `c-has-quoted-numbers' is nil.  (This is a pure C++
> > facility for writing numbers as 4'294'967'295.)
> > (vi) Ensure `c-multiline-string-start-char' (which allows strings to
> > continue over line ends without \) is set correctly for the mode.

> In non-CC modes, all it takes is

>     (modify-syntax-entry ?' "\"" st)
    
Maybe, but that doesn't give you the facilities that CC Mode offers,
namely that the delimiters of invalid constructs (such as unterminated
strings, or invalid character constants) get fontified with warning face.

> so is there somewhere in CC-mode's code where there's some comment or
> something that explains why this simple approach isn't sufficient?

There're comments which explain the strategems used to get the
font-lock-warning-face.

One question which has just occurred to me is why am I doing this in CC
Mode rather than the syntax and font-lock functionality handling it
directly?  Languages where strings don't extend over unescaped newlines
aren't exactly a rarity.

> I understand that things aren't always that simple:

> - you need to handle the 4'294'967'295 thingies in C++, but that should
>   only affect C++ and I'd assume that the C++ code handles it by
>   recognizing something like "[0-9]'" and changing the syntax-class of
>   those quotes so it shouldn't prevent multichar single-quoted strings.

More or less, although it checks there aren't two adjacent 's, and things
like that.

> - you apparently want to help the user catch the erroneous use of
>   single-quoted strings in those languages where single quotes are used
>   for chars rather than strings. but again this would seem to only
>   explain the need for c-single-quotes-quote-strings.

> But the above sounds surprisingly complex&scary,

It only looks like that because I've spelled it out so laboriously.  There
are two hook variables, each of which needs one function and the lack of
another.  There are two boolean constants which need setting.  It needs
to be done once when writing a mode, and only then when there's something
unusual, like 'strings like this'.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).



  reply	other threads:[~2019-03-30 19:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22  8:09 cc-mode: Make all parameters introduced in Emacs 26 optional Jostein Kjønigsen
2018-01-22 20:32 ` Alan Mackenzie
2018-02-03  5:59   ` Matthew Carter
2018-02-03  6:13     ` Matthew Carter
2018-02-03 11:44       ` Alan Mackenzie
2019-03-30 13:51         ` Alan Mackenzie
2019-03-30 16:39           ` Stefan Monnier
2019-03-30 19:42             ` Alan Mackenzie [this message]
2019-03-30 20:17               ` Stefan Monnier
2019-03-30 21:53                 ` Ergus
2018-03-12 20:16   ` Jostein Kjønigsen
2018-03-12 22:40     ` Stefan Monnier
2018-03-12 23:29       ` Clément Pit-Claudel
2018-03-13  1:00         ` Stefan Monnier
2018-03-13 20:08       ` Jostein Kjønigsen

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=20190330194204.GB6312@ACM \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.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).