From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Hong Xu Newsgroups: gmane.emacs.bugs Subject: bug#37862: [PATCH] Use alternative C++ source files for determining C/C++ header files. Date: Mon, 21 Oct 2019 20:12:51 -0700 Message-ID: <87r235scb0.fsf@topbug.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="117627"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: 37862@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 22 05:14:12 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iMkcd-000UUr-Vl for geb-bug-gnu-emacs@m.gmane.org; Tue, 22 Oct 2019 05:14:12 +0200 Original-Received: from localhost ([::1]:49652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMkcc-0003bu-AC for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Oct 2019 23:14:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46003) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMkcX-0003bZ-4r for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 23:14:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMkcW-0004dP-1g for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 23:14:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49303) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iMkcV-0004dL-Ue for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 23:14:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iMkcV-0007vP-NR for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 23:14:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Hong Xu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 22 Oct 2019 03:14:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 37862 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.157171398430368 (code B ref -1); Tue, 22 Oct 2019 03:14:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Oct 2019 03:13:04 +0000 Original-Received: from localhost ([127.0.0.1]:58124 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iMkbX-0007tk-NJ for submit@debbugs.gnu.org; Mon, 21 Oct 2019 23:13:03 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:41407) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iMkbW-0007tT-Bi for submit@debbugs.gnu.org; Mon, 21 Oct 2019 23:13:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45886) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMkbV-0003Vk-0a for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 23:13:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMkbS-0004TD-HS for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 23:13:00 -0400 Original-Received: from sender4-of-o54.zoho.com ([136.143.188.54]:21475) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iMkbR-0004RH-9T for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 23:12:58 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1571713973; cv=none; d=zohomail.com; s=zohoarc; b=eobJvVKaXeQVPwkJUSknik3dI5QWJbrT1qAOpQNnWkKHXz4pATaNDSQcGE7zfV9S6qvWwtJxRMYB+Eygw+RmoBl70wwduRen+prRtz0DySIEaLFGwC3YaD8pevATSJqugHrBdUJgqhGTAQg0MKx/m95LCQ7OQQln7cnyL6+0uXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1571713973; h=Content-Type:Date:From:MIME-Version:Message-ID:Subject:To; bh=dbgMNXChYnV02tOF/oTxVqBTb52aded0ddyv6U2c25w=; b=b2jPlq9j1Wao8BIRokKOm5KaXJhjN8V0VfY/3SE98kfMUG5QH/n5RzroRIAs+4QARq+negcZTs3F+9kNlKjLvFhMTFv3qlDSe99004KKFAC2eL/BfFZSg/X5v4IxA6MiE3RrfYox6kEQi3TrRMH32FHRbFU8LOj312yZDhrx1E0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=topbug.net; spf=pass smtp.mailfrom=hong@topbug.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1571713973; s=zoho; d=topbug.net; i=hong@topbug.net; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; l=1400; bh=dbgMNXChYnV02tOF/oTxVqBTb52aded0ddyv6U2c25w=; b=eygDlBn/427LSbnEHcaUm/v6jpHNLLRdKiO4QLATqGTEZVJn1Sa8/wNXL84jcSSo 8sUJVv/YOaTWZ9IGvnVcKO2WxEmMDegyOzqDXETAXJh3v/4BOfvYGW6Yz19NO5YH0JE 4clT8iWYwBfhy70/DRZ6LtmhyR1+MMUpIdCcQAJs= Original-Received: from home (69-215-149-151.lightspeed.sntcca.sbcglobal.net [69.215.149.151]) by mx.zohomail.com with SMTPS id 1571713971547434.48002720750753; Mon, 21 Oct 2019 20:12:51 -0700 (PDT) X-ZohoMailClient: External X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:169968 Archived-At: * 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