all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ivan Andrus <darthandrus@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: 15212@debbugs.gnu.org
Subject: bug#15212: 24.3.50; c++-mode doesn't support raw string literals
Date: Tue, 24 May 2016 11:12:31 -0600	[thread overview]
Message-ID: <CA+R1CoxGhSEDErgbbd3y9wPDWydhxgeikbhv=mb-FTbgkvfk+w@mail.gmail.com> (raw)
In-Reply-To: <20160403183638.GE3537@acm.fritz.box>

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 <acm@muc.de> wrote:
> Hello, Ivan.
>
> On Tue, Mar 29, 2016 at 09:14:44PM -0600, Ivan Andrus wrote:
>> Ivan Andrus <darthandrus@gmail.com> 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).





  reply	other threads:[~2016-05-24 17:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-29 21:00 bug#15212: 24.3.50; c++-mode doesn't support raw string literals Ivan Andrus
2016-03-30  3:14 ` Ivan Andrus
2016-04-03 18:36   ` Alan Mackenzie
2016-05-24 17:12     ` Ivan Andrus [this message]
2016-05-28 14:40       ` Alan Mackenzie
2016-05-29 21:36         ` Alan Mackenzie
2016-05-31 14:22           ` Ivan Andrus
2016-05-31 21:32             ` Alan Mackenzie
2016-05-31 23:52               ` Michael Welsh Duggan
2016-06-02 16:36                 ` Alan Mackenzie
2016-05-31 22:21             ` Alan Mackenzie
2016-06-01  5:21               ` Ivan Andrus
2016-06-02 16:07                 ` Alan Mackenzie
     [not found]                 ` <20160602160741.GC4067@acm.fritz.box>
2016-06-06 16:32                   ` Alan Mackenzie
     [not found]                   ` <20160606163203.GA19322@acm.fritz.box>
2016-06-07 22:06                     ` Michael Welsh Duggan
2016-06-07 22:21                       ` Alan Mackenzie
2016-06-09  1:38                     ` Ivan Andrus
2016-06-09 15:04                       ` Alan Mackenzie
2016-06-09 15:06   ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+R1CoxGhSEDErgbbd3y9wPDWydhxgeikbhv=mb-FTbgkvfk+w@mail.gmail.com' \
    --to=darthandrus@gmail.com \
    --cc=15212@debbugs.gnu.org \
    --cc=acm@muc.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.