From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Newsgroups: gmane.emacs.help Subject: Re: Auto-Insertion of C/C++ #include-statements upon use of their symbols Date: Wed, 17 Sep 2008 23:54:27 +0200 Message-ID: <87prn2a164.fsf@arcor.de> References: <0724fa6a-b298-49b8-84bb-06933d09c573@p25g2000hsf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1221688513 720 80.91.229.12 (17 Sep 2008 21:55:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Sep 2008 21:55:13 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 17 23:56:10 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kg50G-00053w-3L for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Sep 2008 23:56:04 +0200 Original-Received: from localhost ([127.0.0.1]:50779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kg4zF-0007YO-1j for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Sep 2008 17:55:01 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kg4yy-0007Y8-8E for help-gnu-emacs@gnu.org; Wed, 17 Sep 2008 17:54:44 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kg4yw-0007Xm-N3 for help-gnu-emacs@gnu.org; Wed, 17 Sep 2008 17:54:44 -0400 Original-Received: from [199.232.76.173] (port=44809 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kg4yw-0007Xf-Gq for help-gnu-emacs@gnu.org; Wed, 17 Sep 2008 17:54:42 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:53548 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kg4yv-0007Po-S9 for help-gnu-emacs@gnu.org; Wed, 17 Sep 2008 17:54:42 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Kg4yr-0003rd-0u for help-gnu-emacs@gnu.org; Wed, 17 Sep 2008 21:54:37 +0000 Original-Received: from dslb-082-083-049-176.pools.arcor-ip.net ([82.83.49.176]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Sep 2008 21:54:37 +0000 Original-Received: from de_bb by dslb-082-083-049-176.pools.arcor-ip.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Sep 2008 21:54:37 +0000 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 34 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dslb-082-083-049-176.pools.arcor-ip.net Mail-Copies-To: never User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.3 (gnu/linux) Cancel-Lock: sha1:z2R8b/YfLJXtw4MjPsvestX2IFk= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:57744 Archived-At: >> Nordlöw writes: >>> My suggestion is to make Emacs call a function each time a character >>> is inserted into buffer and then check if we are currently standing >>> behind such a use pattern. I believe looking-back() is usable here. >> >>> We also need to check that the cursor is *NOT* currently standing >>> inside a comment or string; How do I query such a context? > David writes: >> Better solution: Since you are using semantic anyway, you could override >> `semantic-ctxt-current-symbol' for C/C++, so that no symbol is returned >> when the point is in a comment or string. Eric can surely say if this >> would be reasonable to do. >> >> I'm not sure all of this will be fast enough for calling it in something >> like 'post-command-hook, though. Maybe this should just be an extra >> command, which inserts the correct header for the current symbol, if >> necessary? Chetan writes: > This looks like something that abbrev-mode, expand and other template > packages do already. I am not sure what you are trying to do and how it > is differs from any of those. He wants to automatically add proper #include statements as soon as you use external functions. In practice, this would mean you wouldn't have to write any #include statements at all, since they would be automatically added as you write your code (and also removed again when not needed anymore, although this would be more difficult to do). By using CEDET's templating system SRecode, this could even be made language independent. I don't think the usual templating systems can do that. -David