[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: use Elisp to improve your Elisp - some code issues
From: |
Marcin Borkowski |
Subject: |
Re: use Elisp to improve your Elisp - some code issues |
Date: |
Fri, 31 Jul 2015 04:30:20 +0200 |
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