From 605cfb8b7a4ef8f73ddc8f2de5c086f3a7455971 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sat, 18 Oct 2014 10:02:59 +0000 Subject: [PATCH] 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. --- lisp/ChangeLog | 7 +++++++ lisp/progmodes/cc-engine.el | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0da7f2877e1..0e99febb366 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2014-10-18 Alan Mackenzie + + 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 * net/gnutls.el (gnutls-negotiate): Don't use cl-mapcan; pass diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 9a2531d1e99..ccc3f067571 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -249,6 +249,24 @@ (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) -- 2.11.4.GIT