From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Andrus Newsgroups: gmane.emacs.bugs Subject: bug#15212: 24.3.50; c++-mode doesn't support raw string literals Date: Tue, 24 May 2016 11:12:31 -0600 Message-ID: References: <8C5AB533-B326-424B-9612-0B4858BC80BF@gmail.com> <20160403183638.GE3537@acm.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1464110001 21065 80.91.229.3 (24 May 2016 17:13:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 May 2016 17:13:21 +0000 (UTC) Cc: 15212@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 24 19:13:14 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1b5FtJ-00017N-Ho for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 May 2016 19:13:13 +0200 Original-Received: from localhost ([::1]:54446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5FtI-000850-S2 for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 May 2016 13:13:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5FtC-00084f-8h for bug-gnu-emacs@gnu.org; Tue, 24 May 2016 13:13:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5Ft8-0006L1-Fa for bug-gnu-emacs@gnu.org; Tue, 24 May 2016 13:13:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52518) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5Ft8-0006Kx-C6; Tue, 24 May 2016 13:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1b5Ft8-0007ob-6h; Tue, 24 May 2016 13:13:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Andrus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Tue, 24 May 2016 17:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15212 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 15212-submit@debbugs.gnu.org id=B15212.146410995930009 (code B ref 15212); Tue, 24 May 2016 17:13:02 +0000 Original-Received: (at 15212) by debbugs.gnu.org; 24 May 2016 17:12:39 +0000 Original-Received: from localhost ([127.0.0.1]:36622 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5Fsl-0007nx-G6 for submit@debbugs.gnu.org; Tue, 24 May 2016 13:12:39 -0400 Original-Received: from mail-oi0-f50.google.com ([209.85.218.50]:36349) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5Fsi-0007nj-Th for 15212@debbugs.gnu.org; Tue, 24 May 2016 13:12:38 -0400 Original-Received: by mail-oi0-f50.google.com with SMTP id j1so37165262oih.3 for <15212@debbugs.gnu.org>; Tue, 24 May 2016 10:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=u4B3QYzPfORpTqdE9Ywd95OG4A3o29evHNPSquKpazs=; b=Wp18rFtDycgnZnSjqwu4Fas+BB043Cb/CTnOWf6ThoFBsKL4leufU7M1tMEGjyvlet TtztTkVHo0inPbgaqDNiSP/KtJ7pc+Vuj+diAytm/O1Dvpr3CIFMAINREvoUwwsGh8lC Bl5nUl1PKES0XkXqFqMG8gTMiYJv7yCq92nyrZNQRB28sR9wwKMXCvtNtpcPkjXoYNKq 5ew4/Pd7y6DuHAN+WBd80F8KbgHdU1e2NPfkTxBGGEgXs4D6yp+l0jvRh5wOMhk214FO p0x7peIrZH57hcm5JiIJRPS4O0wgwfwd7AySu8Mrt5OPKvvt3bR8rGbrdmFRmCryIlvW Uq+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=u4B3QYzPfORpTqdE9Ywd95OG4A3o29evHNPSquKpazs=; b=H4uqNnRhMKQgVRM9l9bobUHuvGin0rCqg9DGrmOXyDXdChUeX9BUTIpgx/pDl/a4Ii YjSbxp+IO5xYUJTa6O4sWVcpiejX2zpGaXilDk+fgzqZewR0UsOCjfKdLUXRY1OOI2if +fWrua6oWv8cpzZdH7kSuGmrLIZaxSv+aZ2FPkLZqblXPHjubb2t8LUosM6wgiDdteEw rfSMx/tpTKlS4ioPRzWDVp2gHj7dTiCDFAFwe+SEp5ldXFxckef0kYnfNuCtAxK4dQ9E mUTzdxh8D6S/R759DXpqexIqoBFis+qBPHDtKdC9QXJ2wBZg041XaMTmzJDfWHqOA0oY fFoA== X-Gm-Message-State: AOPr4FWobG5CNh05+BtG5xCd6IONBq/LRrocH5nlBLy8CUP3fdVg56OelKPS/1pd7FeQGi5olpDyeJGfhyXnow== X-Received: by 10.202.224.138 with SMTP id x132mr11725009oig.28.1464109951140; Tue, 24 May 2016 10:12:31 -0700 (PDT) Original-Received: by 10.202.65.8 with HTTP; Tue, 24 May 2016 10:12:31 -0700 (PDT) In-Reply-To: <20160403183638.GE3537@acm.fritz.box> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:118630 Archived-At: I've tried the following function which seems to work reasonably well in my limited testing. I'm not suggesting this as the final solution, but I would be happy to do some revisions based on your feedback, or abandon it altogether if you have a better method. Alternately, you can use any pieces that you find useful. (defun c++11-syntax-propertize-function (beg end) ;; interactive for easy testing (interactive (list (point-min) (point-max))) (save-excursion (if (not (nth 3 (syntax-ppss beg))) ;; Not in a string, so in particular, not in a raw string (goto-char beg) ;; We have to re-propertize a raw-string, so move back to the beginning of it. (goto-char (nth 8 (syntax-ppss beg))) (skip-syntax-backward "'")) ;; Look for raw strings in the area of interest (while (search-forward-regexp "\\(\\(?:L\\|u8\\|u\\|U\\)?R\\)\"\\([^(]*\\)(" end t) (let* ((full (match-string-no-properties 0)) (qualifier (match-string-no-properties 1)) (delimiter (match-string-no-properties 2)) (beg-beg (match-beginning 0)) (beg-quote (+ beg-beg (length qualifier))) (beg-quote-after (1+ beg-quote))) (let* ((ppss (syntax-ppss beg-beg)) (in-string-or-comment (or (nth 3 ppss) (nth 4 ppss)))) (if in-string-or-comment ;; Move past the match to avoid an infinite loop (goto-char (match-end 0)) ;; Search for the end of the string (when (search-forward-regexp (concat ")" delimiter "\"") ;; I don't limit it to end because I'm afraid it might not be far enough. nil t) (let ((end-end (match-end 0))) (remove-text-properties beg-beg end-end '(syntax-table . nil)) ;; Mark the qualifier as attaching to the next sexp (put-text-property beg-beg beg-quote 'syntax-table (string-to-syntax "'")) ;; Mark the quotes appropriately (put-text-property beg-quote beg-quote-after 'syntax-table ;; (string-to-syntax "\"") (string-to-syntax "|")) (put-text-property (1- end-end) end-end 'syntax-table (string-to-syntax "|")))))))))) ;; Then in a c++ buffer... (setq-local syntax-propertize-function #'c++11-syntax-propertize-function) -Ivan On Sun, Apr 3, 2016 at 12:36 PM, Alan Mackenzie wrote: > Hello, Ivan. > > On Tue, Mar 29, 2016 at 09:14:44PM -0600, Ivan Andrus wrote: >> Ivan Andrus writes: > >> > C++11 allows fancy new raw string literals [1], but these strings aren't >> > supported in c++-mode (e.g. fontification and movement by sexp's). > >> > In my experience such raw strings are fairly rare, and they are no doubt >> > difficult to support. But I thought I would report this since I >> > didn't see a bug for it in debbugs. > >> > -Ivan > >> > [1] http://en.wikipedia.org/wiki/C%2B%2B11#New_string_literals > >> Any thoughts on this? These are becoming more common in the code I work >> on and some colleagues and I would like support, since they can destroy >> fontification of the rest of the buffer. I'm hesitant to try and do it >> myself because of the famed difficulty of cc-mode. :-( But I'm willing >> to try if someone has ideas. > > OK, I'll have a go at adding these ASAP. I've got a few ideas as how > best to do this. > >> -Ivan > > -- > Alan Mackenzie (Nuremberg, Germany).