From: Daniel Colascione <daniel@censorshipresearch.org>
To: Emacs development discussions <emacs-devel@gnu.org>
Subject: [PATCH] let octave-mode understand single-quoted strings
Date: Sun, 30 May 2010 17:19:57 -0400 [thread overview]
Message-ID: <4C02D67D.5090302@censorshipresearch.org> (raw)
[-- 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 --]
next reply other threads:[~2010-05-30 21:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-30 21:19 Daniel Colascione [this message]
2010-08-31 12:32 ` [PATCH] let octave-mode understand single-quoted strings 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C02D67D.5090302@censorshipresearch.org \
--to=daniel@censorshipresearch.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.