From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] let octave-mode understand single-quoted strings Date: Fri, 03 Sep 2010 12:48:35 +0200 Message-ID: References: <4C02D67D.5090302@censorshipresearch.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1283510942 5525 80.91.229.12 (3 Sep 2010 10:49:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Sep 2010 10:49:02 +0000 (UTC) Cc: "John W. Eaton" , Kurt Hornik , Emacs, Daniel Colascione , development discussions To: Jordi =?iso-8859-1?Q?Guti=E9rrez?= Hermoso Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Sep 03 12:48:58 2010 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 1OrTpJ-0003ai-8m for ged-emacs-devel@m.gmane.org; Fri, 03 Sep 2010 12:48:57 +0200 Original-Received: from localhost ([127.0.0.1]:52089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrTpI-0005tW-Pg for ged-emacs-devel@m.gmane.org; Fri, 03 Sep 2010 06:48:56 -0400 Original-Received: from [140.186.70.92] (port=60387 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrTpC-0005sJ-P7 for emacs-devel@gnu.org; Fri, 03 Sep 2010 06:48:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrTpB-0002cM-7h for emacs-devel@gnu.org; Fri, 03 Sep 2010 06:48:50 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:58127) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrTpB-0002by-2v for emacs-devel@gnu.org; Fri, 03 Sep 2010 06:48:49 -0400 Original-Received: from ceviche.home (vpn-132-204-232-51.acd.umontreal.ca [132.204.232.51]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id o83AmbvI008850; Fri, 3 Sep 2010 06:48:38 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id C5FD5660DF; Fri, 3 Sep 2010 12:48:35 +0200 (CEST) In-Reply-To: ("Jordi =?iso-8859-1?Q?Guti=E9rrez?= Hermoso"'s message of "Thu, 2 Sep 2010 18:46:54 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3614=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:129640 Archived-At: >> 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. =A0I.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 =3D=3D=3D 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.") =20 +(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