all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nikolaj Schumacher <me@nschum.de>
To: Nordlöw <per.nordlow@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Auto-Insertion of C/C++ #include-statements upon use of their symbols
Date: Fri, 19 Sep 2008 18:13:28 +0200	[thread overview]
Message-ID: <m2od2k6rmf.fsf@nschum.de> (raw)
In-Reply-To: <0724fa6a-b298-49b8-84bb-06933d09c573@p25g2000hsf.googlegroups.com> ("Nordlöw"'s message of "Wed\, 17 Sep 2008 08\:04\:39 -0700 \(PDT\)")

Nordlöw <per.nordlow@gmail.com> 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 <string.h>" 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




      parent reply	other threads:[~2008-09-19 16:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-17 15:04 Auto-Insertion of C/C++ #include-statements upon use of their symbols Nordlöw
2008-09-17 16:18 ` David
     [not found] ` <mailman.19414.1221668342.18990.help-gnu-emacs@gnu.org>
2008-09-17 18:39   ` Chetan
2008-09-17 21:17     ` Peter Milliken
2008-09-17 21:54     ` David
2008-09-19 16:13 ` Nikolaj Schumacher [this message]

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=m2od2k6rmf.fsf@nschum.de \
    --to=me@nschum.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=per.nordlow@gmail.com \
    /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.