help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inserting output from a program into a buffer


From: Tim Johnson
Subject: Re: Inserting output from a program into a buffer
Date: Mon, 22 Feb 2010 18:44:55 -0600
User-agent: slrn/0.9.9p1 (Linux)

On 2010-02-22, Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> Tim Johnson <tim@johnsons-web.com> writes:
>
>> On 2010-02-22, Pascal J. Bourguignon <pjb@informatimago.com> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]