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

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs,cc-mode; Reported by: Hong Xu <hong@HIDDEN>; Keywords: patch; dated Tue, 22 Oct 2019 03:14:03 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug reassigned from package 'emacs' to 'emacs,cc-mode'. Request was from Stefan Kangas <stefan@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 37862 <at> debbugs.gnu.org:


Received: (at 37862) by debbugs.gnu.org; 27 Oct 2019 20:31:41 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 27 16:31:41 2019
Received: from localhost ([127.0.0.1]:43581 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iOpCO-0002Iq-QJ
	for submit <at> debbugs.gnu.org; Sun, 27 Oct 2019 16:31:41 -0400
Received: from sender4-of-o54.zoho.com ([136.143.188.54]:21492)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hong@HIDDEN>) id 1iOpCL-0002Ia-44
 for 37862 <at> debbugs.gnu.org; Sun, 27 Oct 2019 16:31:38 -0400
ARC-Seal: i=1; a=rsa-sha256; t=1572208294; cv=none; 
 d=zohomail.com; s=zohoarc; 
 b=UL+DOvEDw1vOsRMvQSoMYXXBMuDl4bP1ta3RHDsIqQdZMyPU2DQWFac+DXJqfKXm6tLrPKw32o0tMOmUK2tAWQNi6e3mmJd+bTfrV2rTXCNYOFf7YyWUJU37CVbTkwzZfK6UpiSIPjxNppi572N8bHw0pJBvHX+ZvIyOAwvcjUg=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc; t=1572208294;
 h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To;
 bh=vSHJb4v52vrPaTvekFFa+3c3Gc1/lEvy8015bfMaBxE=; 
 b=IqPT4an2sC3yvBUDf7pHjvLYVLAkQFY8yRiNbmCY/r19EWHBgWSemYV6+l1ATpsa9W3+F92I9Nmj20yTIwQjQ2gVFajxktF1UKzvgEWpDALvK/6TQxE7nufFBNd1AM5NxQMfIQgznEcwRWY43AulpHvfBxzlCNse7oKJ9oiGWDo=
ARC-Authentication-Results: i=1; mx.zohomail.com;
 dkim=pass  header.i=topbug.net;
 spf=pass  smtp.mailfrom=hong@HIDDEN;
 dmarc=pass header.from=<hong@HIDDEN> header.from=<hong@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1572208294; 
 s=zoho; d=topbug.net; i=hong@HIDDEN;
 h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding;
 l=1334; bh=vSHJb4v52vrPaTvekFFa+3c3Gc1/lEvy8015bfMaBxE=;
 b=Ul1ZKlkOb4Yp62MevGaFfdrfcFXCRil9whzWYbMA4w6SAKwkq8dZon9dMy+H1g/s
 P+TKe/UnlQpJLVJawVSnB6aWu67qLKA/KNdlCQUbo9z1y8Mm1FGNntem1JLLGmzyHtU
 BabwsQQm0WG9PgIn/CdGne0dALOZ85boTt/2ntRk=
Received: from [192.168.88.88] (69-215-149-151.lightspeed.sntcca.sbcglobal.net
 [69.215.149.151]) by mx.zohomail.com
 with SMTPS id 1572208294404234.7524913405265;
 Sun, 27 Oct 2019 13:31:34 -0700 (PDT)
Subject: Re: bug#37862: [PATCH] Use alternative C++ source files for
 determining C/C++ header files.
To: Alan Mackenzie <acm@HIDDEN>
References: <87r235scb0.fsf@HIDDEN> <20191027133038.GA27906@ACM>
From: Hong Xu <hong@HIDDEN>
Openpgp: preference=signencrypt
Message-ID: <89b138ad-e044-d117-e26f-414d29ca7732@HIDDEN>
Date: Sun, 27 Oct 2019 13:31:33 -0700
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.9.0
MIME-Version: 1.0
In-Reply-To: <20191027133038.GA27906@ACM>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-ZohoMailClient: External
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 37862
Cc: 37862 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

On 10/27/19 6:30 AM, Alan Mackenzie wrote:
> 
> Thanks for writing this proposal.
> 
> I think it would be better, given a foo.h, to find all files foo.*, and
> test each one in turn for a match in auto-mode-alist.  Searching this
> alist is really not that slow, particularly as it is only being done a
> few times, and not in a tight loop.

I agree with this approach, if it would not be too slow. Perhaps we can set a limit on the number of files that match foo.*.
> 
> For this, we really want a function in the Emacs core which would find
> the match in auto-mode-alist.  Currently, this functionality is open
> coded in set-auto-mode (in .../lisp/files.el).

I like the idea to create a separate function that provides this feature. Do you mean it's somewhat buried in `set-auto-mode'? It's probably also useful in other places.

> 
> However, I'm a bit sceptical about the use of this proposed facility.
> Many projects (possibly most) have .c/.c++ files in a directory called
> "src", and .h files in a separate directory called "include".  This
> proposed facility wouldn't work in such a set up.  To extend it to cope
> with separate "src"/"include" directories would make it messy.


This is true; but I think no guessing is perfect. At least the proposed solution should help with some smaller projects.





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37862; Package emacs. Full text available.

Message received at 37862 <at> debbugs.gnu.org:


Received: (at 37862) by debbugs.gnu.org; 27 Oct 2019 13:30:45 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 27 09:30:45 2019
Received: from localhost ([127.0.0.1]:41798 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iOid2-0007mF-RO
	for submit <at> debbugs.gnu.org; Sun, 27 Oct 2019 09:30:45 -0400
Received: from colin.muc.de ([193.149.48.1]:63743 helo=mail.muc.de)
 by debbugs.gnu.org with smtp (Exim 4.84_2)
 (envelope-from <acm@HIDDEN>) id 1iOid0-0007m5-G9
 for 37862 <at> debbugs.gnu.org; Sun, 27 Oct 2019 09:30:43 -0400
Received: (qmail 47103 invoked by uid 3782); 27 Oct 2019 13:30:40 -0000
Received: from acm.muc.de (p2E5D5E17.dip0.t-ipconnect.de [46.93.94.23]) by
 colin.muc.de (tmda-ofmipd) with ESMTP;
 Sun, 27 Oct 2019 14:30:38 +0100
Received: (qmail 28236 invoked by uid 1000); 27 Oct 2019 13:30:38 -0000
Date: Sun, 27 Oct 2019 13:30:38 +0000
To: Hong Xu <hong@HIDDEN>
Subject: Re: bug#37862: [PATCH] Use alternative C++ source files for
 determining C/C++ header files.
Message-ID: <20191027133038.GA27906@ACM>
References: <87r235scb0.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <87r235scb0.fsf@HIDDEN>
User-Agent: Mutt/1.10.1 (2018-07-13)
X-Delivery-Agent: TMDA/1.1.12 (Macallan)
From: Alan Mackenzie <acm@HIDDEN>
X-Primary-Address: acm@HIDDEN
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 37862
Cc: 37862 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello, Hong.

On Mon, Oct 21, 2019 at 20:12:51 -0700, Hong Xu wrote:

> * 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

Thanks for writing this proposal.

I think it would be better, given a foo.h, to find all files foo.*, and
test each one in turn for a match in auto-mode-alist.  Searching this
alist is really not that slow, particularly as it is only being done a
few times, and not in a tight loop.

For this, we really want a function in the Emacs core which would find
the match in auto-mode-alist.  Currently, this functionality is open
coded in set-auto-mode (in .../lisp/files.el).

However, I'm a bit sceptical about the use of this proposed facility.
Many projects (possibly most) have .c/.c++ files in a directory called
"src", and .h files in a separate directory called "include".  This
proposed facility wouldn't work in such a set up.  To extend it to cope
with separate "src"/"include" directories would make it messy.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37862; Package emacs. Full text available.

Message received at 37862 <at> debbugs.gnu.org:


Received: (at 37862) by debbugs.gnu.org; 26 Oct 2019 15:19:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Oct 26 11:19:26 2019
Received: from localhost ([127.0.0.1]:41334 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iONqg-0000Nu-FQ
	for submit <at> debbugs.gnu.org; Sat, 26 Oct 2019 11:19:26 -0400
Received: from colin.muc.de ([193.149.48.1]:52857 helo=mail.muc.de)
 by debbugs.gnu.org with smtp (Exim 4.84_2)
 (envelope-from <acm@HIDDEN>) id 1iONqe-0000Nf-4y
 for 37862 <at> debbugs.gnu.org; Sat, 26 Oct 2019 11:19:24 -0400
Received: (qmail 35913 invoked by uid 3782); 26 Oct 2019 15:19:22 -0000
Received: from acm.muc.de (p2E5D5144.dip0.t-ipconnect.de [46.93.81.68]) by
 colin.muc.de (tmda-ofmipd) with ESMTP;
 Sat, 26 Oct 2019 17:19:20 +0200
Received: (qmail 22051 invoked by uid 1000); 26 Oct 2019 15:19:20 -0000
Date: Sat, 26 Oct 2019 15:19:20 +0000
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#37862: [PATCH] Use alternative C++ source files for
 determining C/C++ header files.
Message-ID: <20191026151920.GE17424@ACM>
References: <87r235scb0.fsf@HIDDEN>
 <83eeyzvk8w.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <83eeyzvk8w.fsf@HIDDEN>
User-Agent: Mutt/1.10.1 (2018-07-13)
X-Delivery-Agent: TMDA/1.1.12 (Macallan)
From: Alan Mackenzie <acm@HIDDEN>
X-Primary-Address: acm@HIDDEN
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 37862
Cc: 37862 <at> debbugs.gnu.org, Hong Xu <hong@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello, Eli.

On Sat, Oct 26, 2019 at 14:06:39 +0300, Eli Zaretskii wrote:
> > From: Hong Xu <hong@HIDDEN>
> > 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.

> Thanks.

> Alan, are you looking at this?

Yes, I've been thinking about it for a few days, now.

I think what we could do with is a function `auto-mode' which, given a
file name, would return the corresponding major mode as recorded in
auto-mode-alist.  At the moment, this functionality is a part of
set-auto-mode, making it more difficult for other functions to do the
same thing.  It shouldn't be difficult.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37862; Package emacs. Full text available.

Message received at 37862 <at> debbugs.gnu.org:


Received: (at 37862) by debbugs.gnu.org; 26 Oct 2019 11:07:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Oct 26 07:07:01 2019
Received: from localhost ([127.0.0.1]:39754 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iOJuO-000069-Lx
	for submit <at> debbugs.gnu.org; Sat, 26 Oct 2019 07:07:00 -0400
Received: from eggs.gnu.org ([209.51.188.92]:52878)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1iOJuM-00005n-VW
 for 37862 <at> debbugs.gnu.org; Sat, 26 Oct 2019 07:06:59 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:39712)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <eliz@HIDDEN>)
 id 1iOJuH-0003MK-GC; Sat, 26 Oct 2019 07:06:53 -0400
Received: from [176.228.60.248] (port=2793 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1iOJuF-0002s9-PP; Sat, 26 Oct 2019 07:06:53 -0400
Date: Sat, 26 Oct 2019 14:06:39 +0300
Message-Id: <83eeyzvk8w.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Hong Xu <hong@HIDDEN>, Alan Mackenzie <acm@HIDDEN>
In-reply-to: <87r235scb0.fsf@HIDDEN> (message from Hong Xu on Mon, 21 Oct
 2019 20:12:51 -0700)
Subject: Re: bug#37862: [PATCH] Use alternative C++ source files for
 determining C/C++ header files.
References: <87r235scb0.fsf@HIDDEN>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 37862
Cc: 37862 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Hong Xu <hong@HIDDEN>
> 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.

Thanks.

Alan, are you looking at this?
 




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37862; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 22 Oct 2019 03:13:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Oct 21 23:13:04 2019
Received: from localhost ([127.0.0.1]:58124 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iMkbX-0007tk-NJ
	for submit <at> debbugs.gnu.org; Mon, 21 Oct 2019 23:13:03 -0400
Received: from lists.gnu.org ([209.51.188.17]:41407)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hong@HIDDEN>) id 1iMkbW-0007tT-Bi
 for submit <at> debbugs.gnu.org; Mon, 21 Oct 2019 23:13:02 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:45886)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <hong@HIDDEN>) id 1iMkbV-0003Vk-0a
 for bug-gnu-emacs@HIDDEN; Mon, 21 Oct 2019 23:13:02 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,URIBL_BLOCKED
 autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <hong@HIDDEN>) id 1iMkbS-0004TD-HS
 for bug-gnu-emacs@HIDDEN; Mon, 21 Oct 2019 23:13:00 -0400
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 <hong@HIDDEN>) id 1iMkbR-0004RH-9T
 for bug-gnu-emacs@HIDDEN; 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@HIDDEN;
 dmarc=pass header.from=<hong@HIDDEN> header.from=<hong@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1571713973; 
 s=zoho; d=topbug.net; i=hong@HIDDEN;
 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=
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)
From: Hong Xu <hong@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: [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@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-ZohoMailClient: External
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
X-Received-From: 136.143.188.54
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)


* 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






Acknowledgement sent to Hong Xu <hong@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#37862; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 8 Nov 2019 01:15:02 UTC

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