From: Glen Stark <mail@glenstark.net>
To: help-gnu-emacs@gnu.org
Subject: Help improving an elisp function
Date: Thu, 02 Apr 2015 14:54:59 GMT [thread overview]
Message-ID: <7LcTw.28088$kA6.5489@fx46.am4> (raw)
Hi Everyone.
Still trying to reach journeyman level with elisp. I've written a little
something that helps my workflow, but it's pretty kludgy, and I'd like to
get some feedback how to improve it. The code below makes finding and
inserting a missing include a lot easier:
F9: goes to the definition (via ggtags) of thing-at-point.
F10: copies the buffer name, closes the buffer, and inserts the missing
include file.
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.
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?
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)
next reply other threads:[~2015-04-02 14:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-02 14:54 Glen Stark [this message]
2015-04-02 15:57 ` Help improving an elisp function Doug Lewan
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='7LcTw.28088$kA6.5489@fx46.am4' \
--to=mail@glenstark.net \
--cc=help-gnu-emacs@gnu.org \
/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).