[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: |
Fri, 03 Sep 2010 12:48:35 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
>> I just implemented the single-quote string support based
>> on code I previously wrote for perl-mode, where it's used for
>> string-like thingies that often span multiple lines. I.e. it came "for
>> free".
> The thing is that Matlab has a quirk where a' means the transpose of a
> and 'a' means the string containing a, and Octave inherits this
> syntax. That's the trickiest thing about single-quote strings in
> Octave (and why Octave sources encourage using double-quote strings
> all the time).
Right.
> I still don't get why this is related to multiline issues, though.
It's not directly related.
> Where is your patch?
In Emacs's trunk. See below.
BTW, where can I find a definition of the syntax of single-quoted
strings (i.e. how does Octave distinguish a transpose from a single-quote
starting a string)?
The Octave docs I have don't say anything about it, AFAICT.
Stefan
=== modified file 'lisp/progmodes/octave-mod.el'
--- lisp/progmodes/octave-mod.el 2010-08-12 14:44:16 +0000
+++ lisp/progmodes/octave-mod.el 2010-08-17 15:49:30 +0000
@@ -181,6 +179,30 @@
'(3 font-lock-function-name-face nil t)))
"Additional Octave expressions to highlight.")
+(defvar octave-font-lock-syntactic-keywords
+ ;; Try to distinguish the string-quotes from the transpose-quotes.
+ '(("[[({,; ]\\('\\)" (1 "\"'"))
+ (octave-font-lock-close-quotes)))
+
+(defun octave-font-lock-close-quotes (limit)
+ "Fix the syntax-table of the closing quotes of single-quote strings."
+ ;; Freely inspired from perl-font-lock-special-syntactic-constructs.
+ (let ((state (syntax-ppss)))
+ (while (< (point) limit)
+ (cond
+ ((eq (nth 3 state) ?\')
+ ;; A '..' string.
+ (save-excursion
+ (when (and (or (looking-at "\\('\\)")
+ (re-search-forward "[^\\]\\(?:\\\\\\\\\\)*\\('\\)"
+ nil t))
+ (not (eobp)))
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'syntax-table (string-to-syntax "\"'"))))))
+
+ (setq state (parse-partial-sexp (point) limit nil nil state
+ 'syntax-table)))))
+
(defcustom inferior-octave-buffer "*Inferior Octave*"
"Name of buffer for running an inferior Octave process."
:type 'string