[Top][All Lists]

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

Re: [PATCH] let octave-mode understand single-quoted strings

From: Stefan Monnier
Subject: Re: [PATCH] let octave-mode understand single-quoted strings
Date: Thu, 07 Oct 2010 10:41:39 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

>>>>> John W. Eaton <address@hidden> writes:
> A single-quote character is recognized as a transpose operator if it
> Does that help?

Yes, it does, thank you.

> The Octave manual has a more complete description of how
> "command-style" parsing works (yes, this is ugly; it was implemented
> because it is required for compatibility with Matlab).

Could you give me a pointer to it?  I haven't found it.

>>>>> "Eric" == Eric M Ludlam <address@hidden> writes:
> If not, the basic idea behind it is to use font-lock's functional matching
> stuff.  Look to these functions:

> matlab-font-lock-string-match-normal
> matlab-font-lock-string-match-unterminated
> matlab-font-lock-comment-match

Thanks.  octave-mod.el uses syntax-table text-properties instead (since
it has the advantage of making buffer navigation functions work
correctly as well), so it's necessarily a bit different.

> The strings and comments have to be done together, so you end up having to
> use these functions in a particular order, checking to see what faces are
> left behind while looking at comment chars to make sure it isn't in
> a string.

FWIW, I've appended the code I use now in octave-mod.el, since I think
it's a good bit simpler.  It uses the new syntax-propertize feature, but
you could use font-lock-syntactic-keywords instead.


(defun octave-syntax-propertize-function (start end)
  (goto-char start)
  (octave-syntax-propertize-sqs end)
  (funcall (syntax-propertize-rules
            ;; Try to distinguish the string-quotes from the transpose-quotes.
            ("[[({,; ]\\('\\)"
             (1 (prog1 "\"'" (octave-syntax-propertize-sqs end)))))
           (point) end))

(defun octave-syntax-propertize-sqs (end)
  "Propertize the content/end of single-quote strings."
  (when (eq (nth 3 (syntax-ppss)) ?\')
    ;; A '..' string.
    (when (re-search-forward
           "\\(?:\\=\\|[^']\\)\\(?:''\\)*\\('\\)\\($\\|[^']\\)" end 'move)
      (goto-char (match-beginning 2))
            (when (eq (char-before (match-beginning 1)) ?\\)
              ;; Backslash cannot escape a single quote.
              (put-text-property (1- (match-beginning 1)) (match-beginning 1)
                                 'syntax-table (string-to-syntax ".")))
            (put-text-property (match-beginning 1) (match-end 1)
                         'syntax-table (string-to-syntax "\"'")))))

reply via email to

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