unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] let octave-mode understand single-quoted strings
@ 2010-05-30 21:19 Daniel Colascione
  2010-08-31 12:32 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel Colascione @ 2010-05-30 21:19 UTC (permalink / raw)
  To: Emacs development discussions

[-- Attachment #1: Type: text/plain, Size: 3365 bytes --]

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))


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-10-04 17:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-30 21:19 [PATCH] let octave-mode understand single-quoted strings Daniel Colascione
2010-08-31 12:32 ` Stefan Monnier
2010-08-31 21:15   ` Jordi Gutiérrez Hermoso
2010-09-01  6:46     ` Stefan Monnier
2010-09-02 14:07       ` Jordi Gutiérrez Hermoso
2010-09-02 16:24         ` Stefan Monnier
2010-09-02 23:46           ` Jordi Gutiérrez Hermoso
2010-09-03 10:48             ` Stefan Monnier
2010-10-05  8:28               ` John W. Eaton
2010-10-05 23:57                 ` Eric M. Ludlam
2010-10-07  8:41                   ` Stefan Monnier
2011-10-04 15:13                     ` Jordi Gutiérrez Hermoso
2011-10-04 17:40                       ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).