From: Marcin Borkowski <mbork@mbork.pl>
To: help-gnu-emacs@gnu.org
Subject: Re: use Elisp to improve your Elisp - some code issues
Date: Fri, 31 Jul 2015 04:30:20 +0200 [thread overview]
Message-ID: <87h9olxdmr.fsf@mbork.pl> (raw)
In-Reply-To: <87io91dvlm.fsf@nl106-137-147.student.uu.se>
On 2015-07-31, at 02:22, Emanuel Berg <embe8573@student.uu.se> wrote:
> I just wrote some Elisp which can be used on a set of
> files to identify for example the construct
>
> (if a a b)
>
> if you want to replace those for
>
> (or a b)
I like the idea! Even though basically the % m Q combo in Dired already
does this (well, more or less). Or multi-occur. Or
multi-occur-in-matching-buffers. (These two operate on buffers, not
files, OTOH.) (Projectile has similar things, too, I guess, though
I don't se it. And Icicles takes that idea to the next level.)
> See the comments for the issues!
Well, I also glanced at the code itself;-).
> Issue one is how to best create a temporary buffer to
> display the results.
`pop-to-buffer'? Also, why not name the buffer with earmuffs?
> Issue two is to not kill buffers that were already
> open at invocation - I can solve that by checking if
> there is such a buffer, but I suspect there is
> a better way to do these kind of things all in the
> background, rather than the `find-file' and then
> conditionally `kill-buffer' combo.
I wouldn't use find-file in Lisp programs. Related:
http://emacs.stackexchange.com/questions/2868/whats-wrong-with-find-file-noselect
(the solution given there would also solve your problem, I guess - the
downside being that if the file is already visited, you get "data
duplication").
I'd write a macro (with-file-visited file &rest body) which checks
whether `file' is visited by some buffer or not. If yes, it would just
use `with-current-buffer', and if not, it would use the
`with-temp-buffer' / `insert-file-contents' combo. This way, you would
both be efficient and have a decent level of abstraction at the same
time.
> Third (minor) issue is the annoying message that
> `downcase' does. Isn't there a (shut-up (do-stuff))?
What about `line-number-at-pos' instead of `what-line'?
Also,
(require 'cl)
(cl-flet ((message (&rest args))) ...).
> Other comments also appreciated, as always.
Why use regexen for that? It is not, ekhm, the best solution. ;-P
Shouldn't you use some kind of pattern-matching/destructuring thingy?
In fact, I wanted to write a similar thing, and that was exactly when
I decided that I absolutely *have* to understand precisely how the
backtick works. (Now I think I do, but not before I implemented
a subset of Elisp in Elisp...)
(I haven't written that thing yet, but it's somewhere on the agenda.)
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
next prev parent reply other threads:[~2015-07-31 2:30 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-31 0:22 use Elisp to improve your Elisp - some code issues Emanuel Berg
2015-07-31 2:30 ` Marcin Borkowski [this message]
2015-07-31 7:42 ` Stefan Monnier
2015-07-31 12:11 ` Navy Cheng
2015-08-03 7:56 ` Tassilo Horn
[not found] <mailman.7671.1438302261.904.help-gnu-emacs@gnu.org>
2015-07-31 2:39 ` Pascal J. Bourguignon
2015-08-01 4:09 ` Emanuel Berg
[not found] ` <mailman.7712.1438402251.904.help-gnu-emacs@gnu.org>
2015-08-01 8:54 ` Pascal J. Bourguignon
2015-08-01 12:41 ` Emanuel Berg
[not found] ` <mailman.7727.1438432975.904.help-gnu-emacs@gnu.org>
2015-08-01 15:59 ` Pascal J. Bourguignon
2015-08-02 0:06 ` Emanuel Berg
2015-08-03 1:23 ` Ian Zimmerman
[not found] ` <mailman.7751.1438474104.904.help-gnu-emacs@gnu.org>
2015-08-02 0:44 ` Pascal J. Bourguignon
2015-08-02 1:29 ` Emanuel Berg
2015-08-02 15:36 ` Robert Thorpe
2015-08-02 16:44 ` Pascal J. Bourguignon
2015-08-05 23:40 ` Emanuel Berg
2015-08-06 0:59 ` John Mastro
[not found] ` <mailman.7758.1438529790.904.help-gnu-emacs@gnu.org>
2015-08-02 16:25 ` Rusi
2015-08-01 16:13 ` Michael Heerdegen
2015-07-31 20:24 ` Sam Halliday
2015-08-01 4:20 ` Emanuel Berg
2015-08-01 6:26 ` Marcin Borkowski
[not found] ` <mailman.7714.1438410426.904.help-gnu-emacs@gnu.org>
2015-08-01 8:57 ` Pascal J. Bourguignon
2015-08-01 12:48 ` Emanuel Berg
2015-08-01 13:05 ` Marcin Borkowski
2015-08-01 13:14 ` Emanuel Berg
2015-08-01 13:21 ` Emanuel Berg
[not found] ` <mailman.7713.1438402953.904.help-gnu-emacs@gnu.org>
2015-08-02 10:42 ` Sam Halliday
2015-08-05 23:21 ` Emanuel Berg
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h9olxdmr.fsf@mbork.pl \
--to=mbork@mbork.pl \
--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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.