From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Jordi_Guti=C3=A9rrez_Hermoso?= Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] let octave-mode understand single-quoted strings Date: Tue, 4 Oct 2011 10:13:23 -0500 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=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1317741222 16171 80.91.229.12 (4 Oct 2011 15:13:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 Oct 2011 15:13:42 +0000 (UTC) Cc: "John W. Eaton" , Kurt Hornik , Emacs development discussions , Daniel Colascione , "Eric M. Ludlam" To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 04 17:13:35 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RB6gZ-0002as-3J for ged-emacs-devel@m.gmane.org; Tue, 04 Oct 2011 17:13:35 +0200 Original-Received: from localhost ([::1]:50480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB6gY-0001Ql-Gq for ged-emacs-devel@m.gmane.org; Tue, 04 Oct 2011 11:13:34 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:37265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB6gV-0001Qe-TR for emacs-devel@gnu.org; Tue, 04 Oct 2011 11:13:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RB6gP-0007do-S9 for emacs-devel@gnu.org; Tue, 04 Oct 2011 11:13:31 -0400 Original-Received: from mail-iy0-f169.google.com ([209.85.210.169]:47737) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB6gP-0007dE-Nk for emacs-devel@gnu.org; Tue, 04 Oct 2011 11:13:25 -0400 Original-Received: by iaen33 with SMTP id n33so936409iae.0 for ; Tue, 04 Oct 2011 08:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=azQ5Wd3+7nssR9thmszfgjovkSTQQUHKFq+4wRR8yno=; b=V9+Io3zJH3erD6SdCaARQR4AshTFcp2cJaGIzJ7K5GyzgRtDjZ3IZHbsm3nE5xcR40 /oeHSSot+L/q0RXFPdEvaCCa+gRhIsmvOoUhipjexNGZz33MMuE+IJ+99x6hVMnpgYWi QaQPmYxxMIde8Kqm8Wd23pMli710uJpGPSCBE= Original-Received: by 10.231.28.156 with SMTP id m28mr2312964ibc.79.1317741204184; Tue, 04 Oct 2011 08:13:24 -0700 (PDT) Original-Received: by 10.231.170.65 with HTTP; Tue, 4 Oct 2011 08:13:23 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:144565 Archived-At: On 7 October 2010 03:41, Stefan Monnier wrote: >>>>>> 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? =C2=A0I haven't found it. > >>>>>> "Eric" =3D=3D Eric M Ludlam writes: >> If not, the basic idea behind it is to use font-lock's functional matchi= ng >> stuff. =C2=A0Look to these functions: > >> matlab-font-lock-string-match-normal >> matlab-font-lock-string-match-unterminated >> matlab-font-lock-comment-match > > Thanks. =C2=A0octave-mod.el uses syntax-table text-properties instead (si= nce > 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 ar= e >> 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. =C2=A0It uses the new syntax-propertize feature,= but > you could use font-lock-syntactic-keywords instead. > > > =C2=A0 =C2=A0 =C2=A0 =C2=A0Stefan > > > (defun octave-syntax-propertize-function (start end) > =C2=A0(goto-char start) > =C2=A0(octave-syntax-propertize-sqs end) > =C2=A0(funcall (syntax-propertize-rules > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Try to distinguish the string= -quotes from the transpose-quotes. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0("[[({,; ]\\('\\)" > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (1 (prog1 "\"'" (octave-syntax-= propertize-sqs end))))) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (point) end)) > > (defun octave-syntax-propertize-sqs (end) > =C2=A0"Propertize the content/end of single-quote strings." > =C2=A0(when (eq (nth 3 (syntax-ppss)) ?\') > =C2=A0 =C2=A0;; A '..' string. > =C2=A0 =C2=A0(when (re-search-forward > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\\(?:\\=3D\\|[^']\\)\\(?:''\\)*\\('\\= )\\($\\|[^']\\)" end 'move) > =C2=A0 =C2=A0 =C2=A0(goto-char (match-beginning 2)) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when (eq (char-before (match-be= ginning 1)) ?\\) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Backslash cannot escap= e a single quote. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(put-text-property (1- (m= atch-beginning 1)) (match-beginning 1) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 'syntax-table (string-to-syntax ".")= )) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(put-text-property (match-beginn= ing 1) (match-end 1) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 'syntax-table (string-to-syntax "\"'"))))) > Ping! It's been almost a year. And still no single-quote strings in Octave mode. I have forgotten what the issues were. Can this code be pushed now to the bzr repo? - Jordi G. H.