unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Help improving an elisp function
@ 2015-04-02 14:54 Glen Stark
  2015-04-02 15:57 ` Doug Lewan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Glen Stark @ 2015-04-02 14:54 UTC (permalink / raw)
  To: help-gnu-emacs

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)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-03  5:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-02 14:54 Help improving an elisp function Glen Stark
2015-04-02 15:57 ` Doug Lewan
2015-04-02 23:45 ` Emanuel Berg
2015-04-03  5:20 ` Thien-Thi Nguyen

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).