unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Niels Aan de Brugh <nielsadb@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Extending lua-mode syntax table (report from help-gnu-emacs)
Date: Sun, 11 Apr 2010 16:15:46 -0400	[thread overview]
Message-ID: <jwv1velzref.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <v2z3e7525f1004111117p5ab0cb11p8945fa79e106583d@mail.gmail.com> (Niels Aan de Brugh's message of "Sun, 11 Apr 2010 20:17:49 +0200")

> (defun lua-mode ()
>  ;; ....
>    (set (make-local-variable 'font-lock-defaults)
>                        '(lua-font-lock-keywords nil nil ((?_ . "w"))))


> (defvar lua-font-lock-keywords
>  (eval-when-compile
>    (list
>    ;; .....
>     ;; Long strings.
>     '("\\(?:^\\|[^[-]\\)\\(\\[\\(=*\\)\\[\\(?:.\\|\n\\)*?\\]\\2\\]\\)"
>       (1 "\""))

You want to use font-lock-syntactic-keywords.  E.g. (warning: 100%
guaranteed untested code ahead):

   (defun lua-mode ()
    ;; ....
    (set (make-local-variable 'font-lock-defaults)
         '(lua-font-lock-keywords nil nil ((?_ . "w")) nil
           (font-lock-syntactic-keywords . lua-font-lock-syntactic-keywords)))
  
  
   (defvar lua-font-lock-syntactic-keywords
    (eval-when-compile
      (list
      ;; .....
       ;; Long strings.
       '("\\(\\[\\)\\[\\|]\\(]\\)"
         (1 (if (null (nth 8 (syntax-ppss))) "\"") nil lax)
         (2 (if (nth 8 (syntax-ppss)) "\"") nil lax)))))

> (defun lua-syntax-status ()
>  "Returns the syntactic status of the character after the point."
>  (parse-partial-sexp (save-excursion (beginning-of-line) (point))
>                      (point)))

(save-excursion (beginning-of-line) (point)) can be replaced by
(line-beginning-position).

> (defun lua-string-p ()
>  "Returns true if the point is in a string."
>  (elt (lua-syntax-status) 3))

> As you can see, the parse-partial-sexp function gets a range of text
> from the start of the line until the point. The long strings can span
> multiple lines (in fact, that's the whole point). So I'm worried that
> the parse-partial-sexp doesn't have enough context to work with. Is
> this true? 

Yes.

> If so, is there a work-around (other than parsing from the start of
> the buffer), or do I need to implement something clever and specific?

You'll probably want to use (syntax-ppss) as a replacement for
(lua-syntax-status), which does exactly the same thing except that it
parses the whole buffer, but uses caching internally to try and make it
still fast enough.


        Stefan




      reply	other threads:[~2010-04-11 20:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-11 18:17 Extending lua-mode syntax table (report from help-gnu-emacs) Niels Aan de Brugh
2010-04-11 20:15 ` Stefan Monnier [this message]

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=jwv1velzref.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=nielsadb@gmail.com \
    /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).