help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax parsing of non-contiguous regions


From: Andreas Politz
Subject: Re: syntax parsing of non-contiguous regions
Date: Sun, 20 Sep 2009 21:53:54 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]