From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: [PATCH] let octave-mode understand single-quoted strings Date: Sun, 30 May 2010 17:19:57 -0400 Organization: Censorship Research Center Message-ID: <4C02D67D.5090302@censorshipresearch.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigFDF0097C2EE044017CAB7A5E" X-Trace: dough.gmane.org 1275254422 10212 80.91.229.12 (30 May 2010 21:20:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 30 May 2010 21:20:22 +0000 (UTC) To: Emacs development discussions Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 30 23:20:21 2010 connect(): No such file or directory Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OIpvg-0000Cn-GH for ged-emacs-devel@m.gmane.org; Sun, 30 May 2010 23:20:20 +0200 Original-Received: from localhost ([127.0.0.1]:48263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OIpvf-0001eC-ON for ged-emacs-devel@m.gmane.org; Sun, 30 May 2010 17:20:19 -0400 Original-Received: from [140.186.70.92] (port=42225 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OIpvX-0001c6-Qk for emacs-devel@gnu.org; Sun, 30 May 2010 17:20:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OIpvW-0001xH-GC for emacs-devel@gnu.org; Sun, 30 May 2010 17:20:11 -0400 Original-Received: from haystack.austinheap.com ([70.32.98.68]:52399 helo=haystacknetwork.com) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OIpvW-0001x1-BM for emacs-devel@gnu.org; Sun, 30 May 2010 17:20:10 -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 X-Enigmail-Version: 1.0.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:125371 Archived-At: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFDF0097C2EE044017CAB7A5E Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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)) --------------enigFDF0097C2EE044017CAB7A5E Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (Darwin) iEYEARECAAYFAkwC1oAACgkQ17c2LVA10VvrLQCgsgYV5hMoR8V8PXLdyeFasgnL ElIAnRZjlTKSrm9P015rUAne4ZG0cFwc =pGPV -----END PGP SIGNATURE----- --------------enigFDF0097C2EE044017CAB7A5E--