unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Robin Neatherway <robin.neatherway@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: syntax-propertize-function for multiline strings
Date: Mon, 6 Jan 2014 21:48:19 +0000	[thread overview]
Message-ID: <CAAWtsQzq=5L3yvHM4dwdvhHTjhADkfdjCMNK56iYpSGtoF9sEA@mail.gmail.com> (raw)

Hi,

I'm trying to improve the syntax highlighting for fsharp-mode [1]. F#
allow strings to be specified over multiple lines [2]. I'm trying to
define verbatim strings, which are preceded with '@' and in which
backslash is should not be treated as an escape character (and "" is
interpreted as "). The syntax highlighting hasn't been updated to use
syntax-propertize-function, so I am trying to use that. I've defined a
rule with a regexp, but with a string that ends with \" the
highlighting breaks if I insert newlines inside the verbatim string. I
think this is because the parsing is being restarted at the newline
and so the string is treated normally, with the backslash escaping the
double quote. I don't know what the recommended technique is to handle
this though.

A minimal working example follows. I define a major mode "test-mode"
that highlights just "//.*" style comments and give an example file.
To reproduce open the example file and switch to "test-mode". Then
insert newlines after the first line. The comment highlighting will
turn to string highlighting. Then insert a space at the end of the
first line. The highlighting will again be correct.

Thanks for any help,
Robin


(setq test-syntax-table
      (let ((synTable (make-syntax-table)))
        (modify-syntax-entry ?\/ ". 12" synTable)
        (modify-syntax-entry ?\n "> " synTable)
        synTable))

(defconst test-syntax-propertize-function
  (syntax-propertize-rules
   ("@\\(\"\\)\\(:?\"\"\\|[^\"]\\)*\\(\"\\)"
    (1 "\"") (2 "\""))))

(define-derived-mode test-mode prog-mode "test"
  :syntax-table test-syntax-table

  (setq font-lock-mode t)
  (setq syntax-propertize-function test-syntax-propertize-function)
  (setq mode-name "test")
  )

Example file:
let mystring = @"hello
   \"
// This is a comment

[1] https://github.com/fsharp/fsharpbinding/tree/master/emacs
[2] http://msdn.microsoft.com/en-us/library/dd323829.aspx



             reply	other threads:[~2014-01-06 21:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-06 21:48 Robin Neatherway [this message]
2014-01-07  0:58 ` syntax-propertize-function for multiline strings Stefan Monnier

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='CAAWtsQzq=5L3yvHM4dwdvhHTjhADkfdjCMNK56iYpSGtoF9sEA@mail.gmail.com' \
    --to=robin.neatherway@gmail.com \
    --cc=help-gnu-emacs@gnu.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.
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).