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

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

Re: syntax-propertize-function for multiline strings


From: Stefan Monnier
Subject: Re: syntax-propertize-function for multiline strings
Date: Mon, 06 Jan 2014 19:58:25 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

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

Usually, the best way to deal with it is along the following lines
(guaranteed 100% untested):

 (defun test-syntax-propertize-function (start end)
   (goto-char start)
   (test-syntax-verbatim-string end)
   (funcall (syntax-propertize-rules
             ("\\(@\\)\"" (1 (prog1 "|" (test-syntax-verbatim-string end)))))
            start end))

 (defun test-syntax-verbatim-string (end)
   (when (eq t (nth 3 (syntax-ppss)))
     (while
       (when (re-search-forward "\"\"?" end 'move)
         (if (> (- (match-end 0) (match-beginning 0)) 1)
             t ;; Skip this "" and keep looking further.
           (put-text-property (match-beginning 0) (match-end 0)
                              'syntax-table (string-to-syntax "|"))
           nil)))))

-- Stefan




reply via email to

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