unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Doug Lewan <dougl@shubertticketing.com>
To: Glen Stark <mail@glenstark.net>,
	"help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: RE: Help improving an elisp function
Date: Thu, 2 Apr 2015 15:57:27 +0000	[thread overview]
Message-ID: <155DEC68569B714B86C2C7075F5EDA9892BCC03C@DAKIYA1.pegasus.local> (raw)
In-Reply-To: <7LcTw.28088$kA6.5489@fx46.am4>

> On
> Behalf Of Glen Stark
> Sent: Thursday, 2015 April 02 10:55
> To: help-gnu-emacs@gnu.org
> Subject: Help improving an elisp function
> 
> 
> But it's pretty awful.  What I'd really like to do is have one function
> that looks up the buffer-name in question, and inserts the include
> statement, without jumping there.


It sounds like (with-current-buffer) is what you want to use
to avoid jumping to the other buffer.

> 
> Also, I had originally had the line (seq gas-cpp-include-path (buffer-
> file-name)) in the find-what-provides function, but that wound up
> giving
> me the path to the buffer I was starting in, not the one that ggtags-
> find-
> definition took me to.  Can someone let me know what's going on there?
> Is the buffer only being updated after the function exits?

You might want to look at (file-name-directory).
Use it in (find-what-provides) to build the path you want,
then use the new (find-what-provides) in M-x insert-missing-include.

> 
> Many thanks.  Here's the code:
> 
> 
> (require ggtags)
> 
> (setq gas-cpp-include-path)
> (defun find-what-provides ()
>   (interactive)
>   (ggtags-find-definition (thing-at-point `symbol))
>   )
> 
> (defun insert-missing-include ()
>   (interactive)
>   (setq gas-cpp-include-path (buffer-file-name))
>   (kill-buffer)
>   (beginning-of-buffer)
>   (while (re-search-forward "#include \".*\"" nil t))
>   (insert (concat "\n#include \""
> 				  (file-name-nondirectory gas-cpp-include-
> path)
> 				  "\"\n"))
>   )
> 
> (global-set-key (kbd "<f9>") 'find-what-provides)
> (global-set-key (kbd "<f10>") 'insert-missing-include)

-- 
,Doug
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224 or ext 4335

The human brain is the most complex thing known to man, according to the human brain.



  reply	other threads:[~2015-04-02 15:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-02 14:54 Help improving an elisp function Glen Stark
2015-04-02 15:57 ` Doug Lewan [this message]
2015-04-02 23:45 ` Emanuel Berg
2015-04-03  5:20 ` Thien-Thi Nguyen

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=155DEC68569B714B86C2C7075F5EDA9892BCC03C@DAKIYA1.pegasus.local \
    --to=dougl@shubertticketing.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mail@glenstark.net \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).