[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Help improving an elisp function
From: |
Doug Lewan |
Subject: |
RE: Help improving an elisp function |
Date: |
Thu, 2 Apr 2015 15:57:27 +0000 |
> 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.