[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] let octave-mode understand single-quoted strings
From: |
Daniel Colascione |
Subject: |
[PATCH] let octave-mode understand single-quoted strings |
Date: |
Sun, 30 May 2010 17:19:57 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 |
This lets octave-mode recognize single-quoted string syntax. It doesn't
handle newlines in strings, but hopefully those are rare.
[octave-mod.diff]
--- octave-mod.el.orig 2010-05-30 15:41:40.000000000 -0400
+++ octave-mod.el 2010-05-30 16:56:10.000000000 -0400
@@ -163,7 +163,24 @@
The string `function' and its name are given by the first and third
parenthetical grouping.")
-(defvar octave-font-lock-keywords
+(defconst octave-string-prefix "\\(?:^\\|[^]})a-zA-Z0-9_.']\\)"
+ "Regexp used to represent the character before the string char '.
+The ' character has restrictions on what starts a string which is needed
+when attempting to understand the current context.
+
+Contains no matching groups.")
+
+(defconst octave-whole-string-regexp
+ (concat octave-string-prefix "\\('\\)\\(?:''\\|[^']\\)*\\('\\)" )
+ "Regular expression that matches a whole single-quoted string.
+In Matlab/Octave single-quoted strings, `'' is escaped by using
+it twice.")
+
+(defconst octave-font-lock-syntactic-keywords
+ ;; Fontify regular expressions
+ `((,octave-whole-string-regexp (1 "|") (2 "|"))))
+
+(defconst octave-font-lock-keywords
(list
;; Fontify all builtin keywords.
(cons (concat "\\<\\("
@@ -299,6 +316,8 @@
(modify-syntax-entry ?\\ "\\" table)
(modify-syntax-entry ?\' "." table)
(modify-syntax-entry ?\` "w" table)
+ ;; single-quoted strings are handled separately because of
+ ;; ambiguity with the transpose operator
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?. "w" table)
(modify-syntax-entry ?_ "w" table)
@@ -531,13 +550,36 @@
(make-local-variable 'normal-auto-fill-function)
(setq normal-auto-fill-function 'octave-auto-fill)
- (make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults '(octave-font-lock-keywords nil nil))
+ (set (make-local-variable 'parse-sexp-ignore-comments) t)
+ (set (make-local-variable 'parse-sexp-lookup-properties) t)
+ (make-local-variable 'font-lock-defaults)
+ (setq font-lock-defaults
+ '(octave-font-lock-keywords ; keywords
+ nil ; keywords-only
+ nil ; case-fold
+ nil ; syntax-alist
+ nil ; syntax-begin
+ (font-lock-syntactic-keywords
+ . octave-font-lock-syntactic-keywords)))
+
(make-local-variable 'imenu-generic-expression)
(setq imenu-generic-expression octave-mode-imenu-generic-expression
imenu-case-fold-search nil)
+ ;; Important to fontify the whole buffer syntactically! If we don't,
+ ;; then we might have strings literals that aren't marked
+ ;; as strings, which will screw up parse-partial-sexp, scan-lists,
+ ;; etc. and and produce maddening "unbalanced parenthesis" errors.
+ ;; When we attempt to find the error and scroll to the portion of
+ ;; the buffer containing the problem, JIT-lock will apply the
+ ;; correct syntax to the regular expresion literal and the problem
+ ;; will mysteriously disappear.
+ (font-lock-set-defaults)
+
+ (let (font-lock-keywords) ; leaves syntactic keywords intact
+ (font-lock-fontify-buffer))
+
(octave-add-octave-menu)
(octave-initialize-completions)
(run-mode-hooks 'octave-mode-hook))
signature.asc
Description: OpenPGP digital signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] let octave-mode understand single-quoted strings,
Daniel Colascione <=