]> git.eshelyaron.com Git - emacs.git/commitdiff
Check that a "macro" found near point-min isn't a ## operator. Fixes
authorAlan Mackenzie <acm@muc.de>
Sat, 18 Oct 2014 10:02:59 +0000 (10:02 +0000)
committerAlan Mackenzie <acm@muc.de>
Sat, 18 Oct 2014 10:02:59 +0000 (10:02 +0000)
bug #18749.
progmodes/cc-engine.el (c-macro-is-genuine-p): New function.
(c-beginning-of-macro): Use the above new function.

lisp/ChangeLog
lisp/progmodes/cc-engine.el

index 0da7f2877e10572611c13b061df49838e51dd2b8..0e99febb3663e24253fd25972fa9c3f433723a3a 100644 (file)
@@ -1,3 +1,10 @@
+2014-10-18  Alan Mackenzie  <acm@muc.de>
+
+       Check that a "macro" found near point-min isn't a ## operator.
+       Fixes bug #18749.
+       * progmodes/cc-engine.el (c-macro-is-genuine-p): New function.
+       (c-beginning-of-macro): Use the above new function.
+
 2014-10-18  Teodor Zlatanov  <tzz@lifelogs.com>
 
        * net/gnutls.el (gnutls-negotiate): Don't use cl-mapcan; pass
index 9a2531d1e9933b731b54a4a1426d9c21e99703da..ccc3f067571a1609160c4cfff0ad99ada1692d2f 100644 (file)
     (setq c-macro-cache-start-pos beg
          c-macro-cache-syntactic nil))))
 
+(defun c-macro-is-genuine-p ()
+  ;; Check that the ostensible CPP construct at point is a real one.  In
+  ;; particular, if point is on the first line of a narrowed buffer, make sure
+  ;; that the "#" isn't, say, the second character of a "##" operator.  Return
+  ;; t when the macro is real, nil otherwise.
+  (let ((here (point)))
+    (beginning-of-line)
+    (prog1
+       (if (and (eq (point) (point-min))
+                (/= (point) 1))
+           (save-restriction
+             (widen)
+             (beginning-of-line)
+             (and (looking-at c-anchored-cpp-prefix)
+                  (eq (match-beginning 1) here)))
+         t)
+      (goto-char here))))
+
 (defun c-beginning-of-macro (&optional lim)
   "Go to the beginning of a preprocessor directive.
 Leave point at the beginning of the directive and return t if in one,
@@ -279,7 +297,8 @@ comment at the start of cc-engine.el for more info."
            (forward-line -1))
          (back-to-indentation)
          (if (and (<= (point) here)
-                  (looking-at c-opt-cpp-start))
+                  (looking-at c-opt-cpp-start)
+                  (c-macro-is-genuine-p))
              (progn
                (setq c-macro-cache (cons (point) nil)
                      c-macro-cache-start-pos here)