GNU bug report logs - #37862
[PATCH] Use alternative C++ source files for determining C/C++ header files.

Previous Next

Packages: emacs, cc-mode;

Reported by: Hong Xu <hong <at> topbug.net>

Date: Tue, 22 Oct 2019 03:14:03 UTC

Severity: wishlist

Tags: patch, wontfix

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Hong Xu <hong <at> topbug.net>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Use alternative C++ source files for determining C/C++
 header files.
Date: Mon, 21 Oct 2019 20:12:51 -0700
* lisp/progmodes/cc-mode.el (c-or-c++-mode): Add check for the
existence of alternative C++ source files.
---
 lisp/progmodes/cc-mode.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 6bdfb170f1ba..940bd4be3f92 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -2492,16 +2492,23 @@ c-or-c++-mode
 matching on file name insufficient for detecting major mode that
 should be used.
 
-This function attempts to use file contents to determine whether
-the code is C or C++ and based on that chooses whether to enable
-`c-mode' or `c++-mode'."
-  (if (save-excursion
+This function attempts to use file contents and the existence of
+alternative C++ source files to determine whether the code is C
+or C++ and based on that chooses whether to enable `c-mode' or
+`c++-mode'."
+  (if (or
+       (save-excursion
         (save-restriction
           (save-match-data
             (widen)
             (goto-char (point-min))
             (re-search-forward c-or-c++-mode--regexp
                                (+ (point) c-guess-region-max) t))))
+       ;; We could have gone through auto-mode-alist here, but it
+       ;; might be too slow.
+       (let ((base-name (file-name-sans-extension (buffer-file-name))))
+	 (seq-find (lambda (ext) (file-exists-p (concat base-name ext)))
+		   '(".cc" ".cpp" ".cxx" ".c++"))))
       (c++-mode)
     (c-mode)))
 
-- 
2.20.1






This bug report was last modified 4 years and 323 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.