From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: use Elisp to improve your Elisp - some code issues Date: Fri, 31 Jul 2015 04:30:20 +0200 Message-ID: <87h9olxdmr.fsf@mbork.pl> References: <87io91dvlm.fsf@nl106-137-147.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1438309864 8686 80.91.229.3 (31 Jul 2015 02:31:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Jul 2015 02:31:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jul 31 04:30:56 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZL063-0006tH-Is for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Jul 2015 04:30:55 +0200 Original-Received: from localhost ([::1]:42914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL062-0000CW-II for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Jul 2015 22:30:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL05p-0000Bq-1e for help-gnu-emacs@gnu.org; Thu, 30 Jul 2015 22:30:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZL05l-0005YR-Ag for help-gnu-emacs@gnu.org; Thu, 30 Jul 2015 22:30:40 -0400 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:40490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL05k-0005Wv-Vj for help-gnu-emacs@gnu.org; Thu, 30 Jul 2015 22:30:37 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 1670A8F2004 for ; Fri, 31 Jul 2015 04:30:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bvDmrAoxInjd for ; Fri, 31 Jul 2015 04:30:28 +0200 (CEST) Original-Received: from localhost (unknown [109.232.24.146]) by mail.mojserwer.eu (Postfix) with ESMTPSA id A2F528F2003 for ; Fri, 31 Jul 2015 04:30:27 +0200 (CEST) In-reply-to: <87io91dvlm.fsf@nl106-137-147.student.uu.se> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:5e00:2:52::8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106159 Archived-At: On 2015-07-31, at 02:22, Emanuel Berg 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