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: Thu, 07 Oct 2010 10:41:39 +0200 Message-ID: References: <4C02D67D.5090302@censorshipresearch.org> <19626.57759.799627.189216@segfault.lan> <4CABBB75.2010606@siege-engine.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1286441536 16341 80.91.229.12 (7 Oct 2010 08:52:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 7 Oct 2010 08:52:16 +0000 (UTC) Cc: "John W. Eaton" , Kurt Hornik , Jordi =?iso-8859-1?Q?Guti=E9rrez?= Hermoso , Daniel Colascione , Emacs development discussions To: "Eric M. Ludlam" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 07 10:52:13 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 1P3mCy-0002qP-CY for ged-emacs-devel@m.gmane.org; Thu, 07 Oct 2010 10:52:12 +0200 Original-Received: from localhost ([127.0.0.1]:35882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3mCx-00050n-Lu for ged-emacs-devel@m.gmane.org; Thu, 07 Oct 2010 04:52:11 -0400 Original-Received: from [140.186.70.92] (port=52309 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3m3I-0007U8-HR for emacs-devel@gnu.org; Thu, 07 Oct 2010 04:42:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P3m34-0005zN-2d for emacs-devel@gnu.org; Thu, 07 Oct 2010 04:42:10 -0400 Original-Received: from smtp04.smtpout.orange.fr ([80.12.242.126]:56695 helo=smtp.smtpout.orange.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P3m33-0005yH-Pl for emacs-devel@gnu.org; Thu, 07 Oct 2010 04:41:58 -0400 Original-Received: from fmsmemgm.homelinux.net ([92.140.114.212]) by mwinf5d08 with ME id Fkhp1f0034b1Gto03khplk; Thu, 07 Oct 2010 10:41:56 +0200 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 33221AE517; Thu, 7 Oct 2010 10:41:39 +0200 (CEST) In-Reply-To: <4CABBB75.2010606@siege-engine.com> (Eric M. Ludlam's message of "Tue, 05 Oct 2010 19:57:41 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Linux 2.6? (barebone, rare!) 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:131417 Archived-At: >>>>> John W. Eaton writes: > A single-quote character is recognized as a transpose operator if it [...] > Does that help? Yes, it does, thank you. > The Octave manual has a more complete description of how > "command-style" parsing works (yes, this is ugly; it was implemented > because it is required for compatibility with Matlab). Could you give me a pointer to it? I haven't found it. >>>>> "Eric" == Eric M Ludlam writes: > If not, the basic idea behind it is to use font-lock's functional matching > stuff. Look to these functions: > matlab-font-lock-string-match-normal > matlab-font-lock-string-match-unterminated > matlab-font-lock-comment-match Thanks. octave-mod.el uses syntax-table text-properties instead (since it has the advantage of making buffer navigation functions work correctly as well), so it's necessarily a bit different. > The strings and comments have to be done together, so you end up having to > use these functions in a particular order, checking to see what faces are > left behind while looking at comment chars to make sure it isn't in > a string. FWIW, I've appended the code I use now in octave-mod.el, since I think it's a good bit simpler. It uses the new syntax-propertize feature, but you could use font-lock-syntactic-keywords instead. Stefan (defun octave-syntax-propertize-function (start end) (goto-char start) (octave-syntax-propertize-sqs end) (funcall (syntax-propertize-rules ;; Try to distinguish the string-quotes from the transpose-quotes. ("[[({,; ]\\('\\)" (1 (prog1 "\"'" (octave-syntax-propertize-sqs end))))) (point) end)) (defun octave-syntax-propertize-sqs (end) "Propertize the content/end of single-quote strings." (when (eq (nth 3 (syntax-ppss)) ?\') ;; A '..' string. (when (re-search-forward "\\(?:\\=\\|[^']\\)\\(?:''\\)*\\('\\)\\($\\|[^']\\)" end 'move) (goto-char (match-beginning 2)) (when (eq (char-before (match-beginning 1)) ?\\) ;; Backslash cannot escape a single quote. (put-text-property (1- (match-beginning 1)) (match-beginning 1) 'syntax-table (string-to-syntax "."))) (put-text-property (match-beginning 1) (match-end 1) 'syntax-table (string-to-syntax "\"'")))))