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 13:44:55 -0600
User-agent: slrn/0.9.9p1 (Linux)

On 2010-02-22, Pascal J. Bourguignon <pjb@informatimago.com> wrote:
<...>
> In general, functions don't modify variables.  This would be a bad case
> of side effect.  In emacs lisp it would be somewhat possible, since all
>                    var))))
>
> (Notice that this effect is a design bug in LISP that was detected in
> 1960 and corrected in the following years by the introduction of lexical
> variables.  emacs lisp is somewhat retrograde (or at least conservator)
> on this point).
>
>
> Anyways, it is a bad idea to try to modify variables from called
> functions.
>
>
> What you really need is to BIND the RESULT of buffer-string and other
> functions TO a variable.  This is done with LET:
>
> (let ((string (buffer-substring (point-min) (+ 10 (point-min)))))
>   (string= "Newsgroups" string))
>
> --> t
 Pascal, the total of what you have written is valuable to me in
 understand programming elisp. I don't fully follow all of what you say,
 but I hope that it will soak in.
 I've now written a function that copies a delimited 'form' (sexp or
 other data structure)
 I submit it here for your comments. Your comments will no doubt further
 enlighten me on your insights.
 ;; code follows
(defun tj-copy-previous-region()
  "Grab a symmetrically delimited data structure beginning on the same line
  as the cursor"
  (interactive)
  (let ((boundary(point))found end success (origin (point)))
  (beginning-of-line-text)
  (if (member (char-after) '(40 91 123))
    (progn 
    (setq found (point)))
    (progn
    (setq found(re-search-forward "(\\|\\[\\|{" boundary t))
    (if found
      (progn
      (backward-char 1)
      (setq found (point)))
      (message "*** No Opening delimiter found on this line ***"))))
  (when found
    (forward-sexp)
    (setq end (point))
    (setq success (buffer-substring found end))
    (message "** RESULT: %s ***" success)
    (goto-char origin)) 
  success))
  ;; needs a little more factoring and I note some redundant bindings...
> But who I am to say such things, I'm not RMS...
  :) We all owe RMS a great debt for his contributions and his
  passionate opinions are well known....
thanks
-- 
Tim 
tim@johnsons-web.com
http://www.akwebsoft.com


reply via email to

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