help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help improving an elisp function


From: Glen Stark
Subject: Help improving an elisp function
Date: Thu, 02 Apr 2015 14:54:59 GMT
User-agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)

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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]