all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Hong Xu <hong@topbug.net>
To: 37862@debbugs.gnu.org
Subject: bug#37862: [PATCH] Use alternative C++ source files for determining C/C++ header files.
Date: Mon, 21 Oct 2019 20:12:51 -0700	[thread overview]
Message-ID: <87r235scb0.fsf@topbug.net> (raw)


* 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







             reply	other threads:[~2019-10-22  3:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22  3:12 Hong Xu [this message]
2019-10-26 11:06 ` bug#37862: [PATCH] Use alternative C++ source files for determining C/C++ header files Eli Zaretskii
2019-10-26 15:19   ` Alan Mackenzie
2019-10-27 13:30 ` Alan Mackenzie
2019-10-27 20:31   ` Hong Xu
2020-07-04 17:10     ` 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=87r235scb0.fsf@topbug.net \
    --to=hong@topbug.net \
    --cc=37862@debbugs.gnu.org \
    /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.