From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: Help improving an elisp function
Date: Fri, 03 Apr 2015 01:45:17 +0200 [thread overview]
Message-ID: <87mw2qumb6.fsf@debian.uxu> (raw)
In-Reply-To: 7LcTw.28088$kA6.5489@fx46.am4
Glen Stark <mail@glenstark.net> writes:
> 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.
You are exactly right the problem is the user-level
mucking around with the buffers. I could help you with
that but I don't get the ggtags to work right away and
as I never felt the need for that unless you provide
me with step by step instructions I'll leave it
at that.
But: for all on-the-top user-level mucking around with
buffers there are the equivalents to do that below
where it isn't noticed, so you should find
those equivalents.
Also, the byte compiler (see the Emacs man page) can
help you with some bad habits - often it tells you
what you should use as well, and the buffer issue is
one where the compiler is strict :)
But... as for your problem, in principle it is
absolutely correct to automatize the workflow, however
in this case if you do any amount of C++ henceforth
you will very rapidly not need this anyway, because
you will know where stuff is and putting the includes
in place manually won't bother you.
So what you do is over-engineering, but we will of
course help you nonetheless if you continue to post.
> (require ggtags)
(require 'ggtags)
> (setq gas-cpp-include-path)
Better than a global variable is a `let' in the
function where it belongs (i.e., is used):
(let ((gas-cpp-include-path ...)
(other-var ...))
; do stuff with the vars
)
> (defun find-what-provides ()
> (interactive)
> (ggtags-find-definition (thing-at-point `symbol))
> )
No need to backtick "symbol", (thing-at-point 'symbol)
is fine.
> (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"))
> )
Apart from what I mentioned - let, and the buffers -
I've found that `format' is more manageable than
`concat', especially when it gets complicated.
With format, you can specify the structure first,
which will communicate the purpose (to you), then you
only set up the data once (all to the right) and never
bother with it again:
(format "purpose and structure" data_1 ... data_n)
> (global-set-key (kbd "<f9>") 'find-what-provides)
> (global-set-key (kbd "<f10>") 'insert-missing-include)
You can type those as [f9] instead of (kbd "<f9>") -
try evaluating it, if you are unsure!
But: Those keys aren't good. You don't want to let go
of your hands from the typing position, which is the
"asdf" and "jkl;" keys for the left and right hand,
respec... uhm, you get it. Tho seemingly as single key
is faster and easier and less error-prone than
a combination, that isn't so with time and practice if
the combination is close and short, because then the
"reach, find and reset" can be eliminated. Remember,
speed kills!
Good luck! Come back with more questions, of course.
--
underground experts united
http://user.it.uu.se/~embe8573
next prev parent reply other threads:[~2015-04-02 23:45 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
2015-04-02 23:45 ` Emanuel Berg [this message]
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=87mw2qumb6.fsf@debian.uxu \
--to=embe8573@student.uu.se \
--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).