From 20e527d0c5e5a4ba95f14ab1d0379c20557406ae Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Mon, 15 Apr 2013 16:10:24 +0000 Subject: [PATCH] Correct the placement of c-cpp-delimiters when there're #s not at col 0. * progmodes/cc-langs.el (c-anchored-cpp-prefix): Reformulate and place a submatch around the #. * progmodes/cc-mode.el(c-neutralize-syntax-in-and-mark-CPP): Start a search at BOL. Put the c-cpp-delimiter category text propertiy on the #, not BOL. --- lisp/ChangeLog | 11 +++++++++++ lisp/progmodes/cc-langs.el | 4 ++-- lisp/progmodes/cc-mode.el | 9 ++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2966af7e0bc..f366c1937af 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2013-04-15 Alan Mackenzie + + Correct the placement of c-cpp-delimiters when there're #s not at + col 0. + + * progmodes/cc-langs.el (c-anchored-cpp-prefix): Reformulate and + place a submatch around the #. + * progmodes/cc-mode.el(c-neutralize-syntax-in-and-mark-CPP): Start + a search at BOL. Put the c-cpp-delimiter category text propertiy + on the #, not BOL. + 2013-04-15 Stefan Monnier * emacs-lisp/nadvice.el: Properly test names when adding advice. diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index ba9c42e4c89..af52ad53aad 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -812,8 +812,8 @@ Assumed to not contain any submatches or \\| operators." (c-lang-defconst c-anchored-cpp-prefix "Regexp matching the prefix of a cpp directive anchored to BOL, in the languages that have a macro preprocessor." - t (if (c-lang-const c-opt-cpp-prefix) - (concat "^" (c-lang-const c-opt-cpp-prefix)))) + t "^\\s *\\(#\\)\\s *" + (java awk) nil) (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix)) (c-lang-defconst c-opt-cpp-start diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 3c3a5766582..17e80b8b25b 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -936,7 +936,8 @@ Note that the style variables are always made local to the buffer." ;; Add needed properties to each CPP construct in the region. (goto-char c-new-BEG) - (let ((pps-position c-new-BEG) pps-state mbeg) + (skip-chars-backward " \t") + (let ((pps-position (point)) pps-state mbeg) (while (and (< (point) c-new-END) (search-forward-regexp c-anchored-cpp-prefix c-new-END t)) ;; If we've found a "#" inside a string/comment, ignore it. @@ -945,14 +946,12 @@ Note that the style variables are always made local to the buffer." pps-position (point)) (unless (or (nth 3 pps-state) ; in a string? (nth 4 pps-state)) ; in a comment? - (goto-char (match-beginning 0)) + (goto-char (match-beginning 1)) (setq mbeg (point)) (if (> (c-syntactic-end-of-macro) mbeg) (progn (c-neutralize-CPP-line mbeg (point)) - (c-set-cpp-delimiters mbeg (point)) - ;(setq pps-position (point)) - ) + (c-set-cpp-delimiters mbeg (point))) (forward-line)) ; no infinite loop with, e.g., "#//" ))))) -- 2.39.2