From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: syntax parsing of non-contiguous regions
Date: Sun, 20 Sep 2009 21:53:54 +0200 [thread overview]
Message-ID: <87tyyxie99.fsf@fh-trier.de> (raw)
In-Reply-To: 4AB53B94.2070307@googlemail.com
Emacs offers the possibility of setting the character-syntax on the fly.
(info "(elisp) Setting Syntax Properties")
Out of boredom, I actually tried to implement something like this.
(defun foo-mode ()
(interactive)
(kill-all-local-variables)
(set-syntax-table
(let ((tb (make-syntax-table)))
(modify-syntax-entry ?{ ". 1" tb)
(modify-syntax-entry ?% ". 23" tb)
(modify-syntax-entry ?} ". 4" tb)
tb))
(setq font-lock-defaults
'(nil nil nil nil nil
(font-lock-syntactic-keywords
.
((foo-find-other-comment
; generic comment syntax prohibits regular comments
; inside it
(1 "!")
(2 "!")))))))
(defun foo-find-other-comment (limit)
"Starting at point, find the next occurence of '!' not inside a
string or comment."
(let (success)
(while (and (not success)
(re-search-forward
"\\(!\\).*\\(\n?\\)" limit t))
(setq success (let ((st (syntax-ppss (match-beginning 0))))
(not (or (nth 4 st) ;comment
(nth 5 st))))) ;string
(unless (eobp)
(forward-char))
(when success
(goto-char (match-end 0))))
success))
-ap
next prev parent reply other threads:[~2009-09-20 19:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-19 20:14 syntax parsing of non-contiguous regions Alexander Katovsky
2009-09-20 19:53 ` Andreas Politz [this message]
2009-09-20 20:21 ` Andreas Röhler
2009-09-21 19:28 ` Alexander Katovsky
2009-09-21 20:13 ` Andreas Röhler
2009-09-21 21:55 ` Lennart Borgman
-- strict thread matches above, loose matches on Subject: below --
2009-09-21 22:18 Alexander Katovsky
2009-09-22 5:42 ` Andreas Röhler
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=87tyyxie99.fsf@fh-trier.de \
--to=politza@fh-trier.de \
--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).