From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: Auto-Insertion of C/C++ #include-statements upon use of their symbols Date: Fri, 19 Sep 2008 18:13:28 +0200 Message-ID: References: <0724fa6a-b298-49b8-84bb-06933d09c573@p25g2000hsf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1221841182 9429 80.91.229.12 (19 Sep 2008 16:19:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Sep 2008 16:19:42 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: =?utf-8?Q?Nordl=C3=B6w?= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 19 18:20:39 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 1Kgiig-00043n-La for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Sep 2008 18:20:34 +0200 Original-Received: from localhost ([127.0.0.1]:39830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kgihf-00077T-7Z for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Sep 2008 12:19:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kgibt-0005Dr-JN for help-gnu-emacs@gnu.org; Fri, 19 Sep 2008 12:13:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kgibs-0005DA-K9 for help-gnu-emacs@gnu.org; Fri, 19 Sep 2008 12:13:33 -0400 Original-Received: from [199.232.76.173] (port=36585 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kgibs-0005D2-Az for help-gnu-emacs@gnu.org; Fri, 19 Sep 2008 12:13:32 -0400 Original-Received: from dd18200.kasserver.com ([85.13.138.168]:43071) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kgibs-0002nU-75 for help-gnu-emacs@gnu.org; Fri, 19 Sep 2008 12:13:32 -0400 Original-Received: from thursday (kobz-590f1232.pool.einsundeins.de [89.15.18.50]) by dd18200.kasserver.com (Postfix) with ESMTP id 100E21802B21B; Fri, 19 Sep 2008 18:13:33 +0200 (CEST) In-Reply-To: <0724fa6a-b298-49b8-84bb-06933d09c573@p25g2000hsf.googlegroups.com> (=?utf-8?Q?=22Nordl=C3=B6w=22's?= message of "Wed\, 17 Sep 2008 08\:04\:39 -0700 \(PDT\)") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2.50 (darwin) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:57807 Archived-At: Nordl=C3=B6w wrote: > I am currently writing some logic for automatically looking up a > required header file when the programmer completes the use of a symbol > defined in this header file. This to relieve especially C/C++ > programmers from the cumbersome process of doing for example "man > memcpy" to figure out that we need to "include " before > calling memcpy(). I've hacked together something similar for Java. If you're interested, I could send you some of it (GPLed). > The logic for these lookups and insertions already exists. What now > remains is the logic for sensing when this is needed. I use this: (add-hook 'pre-abbrev-expand-hook import-class-maybe nil t) (defun comment-or-string-p () (let ((pos (syntax-ppss))) (or (nth 3 pos) (nth 4 pos)))) (defun import-class-maybe () "Add an import statement for the class name before point if there is any." (let (case-fold-search) (and (looking-back class-name-regexp) (not (comment-or-string-p)) (ignore-errors (profi-import-class (match-string-no-properties 1) t))))) > My suggestion is to make Emacs call a function each time a character > is inserted into buffer `pre-abbrev-expand-hook' is only called at the end of words, which might even be better. `after-change-functions' is called after every character. > If any one is interested in using this add-ons I will gladly send it > to you. I hope you'll release it eventually, though. regards, Nikolaj Schumacher