From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim Johnson Newsgroups: gmane.emacs.help Subject: Re: Inserting output from a program into a buffer Date: Mon, 22 Feb 2010 18:44:55 -0600 Organization: AkWebsoft Message-ID: References: <87zl324774.fsf@lion.rapttech.com.au> <87k4u66nhh.fsf@galatea.lan.informatimago.com> <87zl316218.fsf@galatea.lan.informatimago.com> <87iq9ozwfl.fsf@galatea.lan.informatimago.com> Reply-To: tim@johnsons-web.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1266889258 6205 80.91.229.12 (23 Feb 2010 01:40:58 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 23 Feb 2010 01:40:58 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 23 02:40:54 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NjjlR-0004ck-Cm for geh-help-gnu-emacs@m.gmane.org; Tue, 23 Feb 2010 02:40:41 +0100 Original-Received: from localhost ([127.0.0.1]:48524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NjjlQ-0001sP-Ou for geh-help-gnu-emacs@m.gmane.org; Mon, 22 Feb 2010 20:40:40 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Mon, 22 Feb 2010 18:44:55 -0600 Original-Newsgroups: gnu.emacs.help User-Agent: slrn/0.9.9p1 (Linux) Original-Lines: 50 Original-X-Trace: sv3-xuOXeUtnDTTXvkFyBNoNHREoGcpwPXSFVHLhPIWKngOAfXxfb6LCEV3+3+7GM/l0ia6g0NJIrTv5Ii1!fhs/N9hrbIGNtXwimP7QeMZC7d+KgPqBL0deFjSZAYQ8PfYYuQ2N6WcroVlme+UbceyMsN4= Original-X-Complaints-To: www.supernews.com/docs/abuse.html X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Original-Xref: news.stanford.edu gnu.emacs.help:177004 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:72042 Archived-At: On 2010-02-22, Pascal J. Bourguignon wrote: > Tim Johnson writes: > >> On 2010-02-22, Pascal J. Bourguignon wrote: > You could write it like this: > > (defun tj-copy-previous-region () > "Save a list surrounding or before the cursor into the kill-ring." > (interactive) > (save-excursion > (let ((boundary (point))) > (beginning-of-line-text) > (if (re-search-forward "[([{]" boundary t) > (let ((start (match-beginning 0))) > (goto-char (1- start)) > (forward-sexp) > (kill-ring-save start (point))) > (error "No Opening delimiter found on this line"))))) > > aaaa (1 2 3 4 5 6 7 8 9) zzzz > ^ M-x tj-copy-previous-region RET C-n C-n C-y inserts: > (1 2 3 4 5 6 7 8 9) Very nice illustration. > Notice: > > - spaces before opening parentheses not preceded by an opening > parenthesis. Understood. > - indentation done automatically by emacs. (blush) was using vim. > - avoidance of setf or setq. Thus the nested 'lets. Aha! > - do actually what was documented (by the function name), ie. use > kill-ring-save instead of buffer-substring. K > - use of save-excursion to save the excursion K > - use of error to deal with exceptional cases instead of just message. > error will do the right thing depending on the local circumstances > (ie. it will message the error in interactive use, but enter the > debugger or have the error otherwise handled if the programmer asks it > to). K Thank you very much for this lesson Regards -- Tim tim@johnsons-web.com http://www.akwebsoft.com