From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: use Elisp to improve your Elisp - some code issues Date: Fri, 31 Jul 2015 04:39:37 +0200 Organization: Informatimago Message-ID: <877fphvymu.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1438310425 16007 80.91.229.3 (31 Jul 2015 02:40:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Jul 2015 02:40:25 +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:40:21 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 1ZL0FA-0006Xa-Ak for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Jul 2015 04:40:20 +0200 Original-Received: from localhost ([::1]:42929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL0F9-0002Ob-M3 for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Jul 2015 22:40:19 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 88 Original-X-Trace: individual.net hnsYFmGoS8JqDcNWZTyaZQwXE3moD+ZNx+mNyfwaByMjQG3qrK Cancel-Lock: sha1:NDc3YmFjZTBlYzk3NmI1YmRiYTVkMDk2NjBlYWRjOTc4ZTdlNDUwOQ== sha1:HvNPRBqtPewBHpPVRBf3eRxoIJ4= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:213875 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:106160 Archived-At: Emanuel Berg writes: > 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) > > See the comments for the issues! > > Issue one is how to best create a temporary buffer to > display the results. It's not so much a temporary buffer than a buffer that is not backed by a file, that you want. A temporary buffer, created by with-temporary-buffer would be deleted right away, and not visible to the user. You want your buffer to be visible by the user. The convention for this type of buffer is to name it with stars around "*Results*". If you want such a buffer but not visible to the user, add a prefix space: " *PrivateResults*" You can see the current "invisible" buffer with C-x b SPC TAB or all the buffers with (buffer-list) > 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 don't think there's another way. In my opinion, it's not too important a feature; in my own with-file macro (used by with-files), I didn't check for pre-existing buffers. > Third (minor) issue is the annoying message that > `downcase' does. Isn't there a (shut-up (do-stuff))? I never noted any message from downcase; what do you get? Perhaps you'd want to use: (defun what-line-message () "Return a formated string containing the current buffer line number and narrowed line number of point." (let ((start (point-min)) (n (line-number-at-pos))) (if (= start 1) (format "Line %d" n) (save-excursion (save-restriction (widen) (format "line %d (narrowed line %d)" (+ n (line-number-at-pos start) -1) n)))))) (what-line-message) --> "line 79 (narrowed line 72)" instead of what-line? You could send a patch to emacs to replace what-line with: (defun what-line () (interactive) (message "%s" (what-line-message))) and the what-line-message function. In anycase, it is a basic precept to never mix I/O with computing in a single function. -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk