unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* eval-last-sexp in other window
@ 2009-03-30  4:22 Bob Babcock
  2009-03-30  8:05 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 8+ messages in thread
From: Bob Babcock @ 2009-03-30  4:22 UTC (permalink / raw)
  To: help-gnu-emacs

Is there a way to have eval-last-sexp (typically bound to C-xC-e) run in a 
different window?  This would be convenient when developing a macro that 
reformats text - I want the part of the macro I'm testing to be applied to 
the file being reformatted, not to my macro.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: eval-last-sexp in other window
  2009-03-30  4:22 Bob Babcock
@ 2009-03-30  8:05 ` Pascal J. Bourguignon
  2009-03-31  4:42   ` Bob Babcock
  0 siblings, 1 reply; 8+ messages in thread
From: Pascal J. Bourguignon @ 2009-03-30  8:05 UTC (permalink / raw)
  To: help-gnu-emacs

Bob Babcock <wssddc@nospam.gis.net> writes:

> Is there a way to have eval-last-sexp (typically bound to C-xC-e) run in a 
> different window?  This would be convenient when developing a macro that 
> reformats text - I want the part of the macro I'm testing to be applied to 
> the file being reformatted, not to my macro.

You may use M-:  to apply a form to the current buffer. 


Otherwise:

(with-current-buffer (get-buffer "The Other Buffer Name")
   (do-what-you-want)) C-x C-e

-- 
__Pascal Bourguignon__


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: eval-last-sexp in other window
  2009-03-30  8:05 ` Pascal J. Bourguignon
@ 2009-03-31  4:42   ` Bob Babcock
  2009-03-31  7:53     ` Pascal J. Bourguignon
  0 siblings, 1 reply; 8+ messages in thread
From: Bob Babcock @ 2009-03-31  4:42 UTC (permalink / raw)
  To: help-gnu-emacs

pjb@informatimago.com (Pascal J. Bourguignon) wrote in
news:87d4bzbfky.fsf@galatea.local: 

>> Is there a way to have eval-last-sexp (typically bound to C-xC-e) run
>> in a different window?  This would be convenient when developing a
>> macro that reformats text - I want the part of the macro I'm testing
>> to be applied to the file being reformatted, not to my macro.
> 
> You may use M-:  to apply a form to the current buffer. 
> 
> 
> Otherwise:
> 
> (with-current-buffer (get-buffer "The Other Buffer Name")
>    (do-what-you-want)) C-x C-e

Thanks.  After several false starts, I have a simple macro that seems to do 
what I want:

(defun last-sexp-other-window()
"Get last sexp and run it in other window.
If there isn't another window, use current window."
  (interactive)
  (setq ow-sexp (preceding-sexp))
  (other-window 1) (eval ow-sexp) (other-window -1) )

This doesn't call the debugger on error, but that's ok.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: eval-last-sexp in other window
  2009-03-31  4:42   ` Bob Babcock
@ 2009-03-31  7:53     ` Pascal J. Bourguignon
  2009-04-01  2:10       ` Bob Babcock
  0 siblings, 1 reply; 8+ messages in thread
From: Pascal J. Bourguignon @ 2009-03-31  7:53 UTC (permalink / raw)
  To: help-gnu-emacs

Bob Babcock <wssddc@nospam.gis.net> writes:

> pjb@informatimago.com (Pascal J. Bourguignon) wrote in
> news:87d4bzbfky.fsf@galatea.local: 
>
>>> Is there a way to have eval-last-sexp (typically bound to C-xC-e) run
>>> in a different window?  This would be convenient when developing a
>>> macro that reformats text - I want the part of the macro I'm testing
>>> to be applied to the file being reformatted, not to my macro.
>> 
>> You may use M-:  to apply a form to the current buffer. 
>> 
>> 
>> Otherwise:
>> 
>> (with-current-buffer (get-buffer "The Other Buffer Name")
>>    (do-what-you-want)) C-x C-e
>
> Thanks.  After several false starts, I have a simple macro that seems to do 
> what I want:
>
> (defun last-sexp-other-window()
> "Get last sexp and run it in other window.
> If there isn't another window, use current window."
>   (interactive)
>   (setq ow-sexp (preceding-sexp))
>   (other-window 1) (eval ow-sexp) (other-window -1) )

At the very least, use let, not setq!

(defun last-sexp-other-window()
 "Get last sexp and run it in other window.
If there isn't another window, use current window."
   (interactive)
   (let ((ow-sexp (preceding-sexp)))
      (other-window 1)
      (eval ow-sexp)
      (other-window -1)))

-- 
__Pascal Bourguignon__


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: eval-last-sexp in other window
@ 2009-03-31 20:25 Xavier Maillard
  0 siblings, 0 replies; 8+ messages in thread
From: Xavier Maillard @ 2009-03-31 20:25 UTC (permalink / raw)
  To: Bob Babcock; +Cc: help-gnu-emacs


   pjb@informatimago.com (Pascal J. Bourguignon) wrote in
   news:87d4bzbfky.fsf@galatea.local: 

   >> Is there a way to have eval-last-sexp (typically bound to C-xC-e) run
   >> in a different window?  This would be convenient when developing a
   >> macro that reformats text - I want the part of the macro I'm testing
   >> to be applied to the file being reformatted, not to my macro.
   > 
   > You may use M-:  to apply a form to the current buffer. 
   > 
   > 
   > Otherwise:
   > 
   > (with-current-buffer (get-buffer "The Other Buffer Name")
   >    (do-what-you-want)) C-x C-e

   Thanks.  After several false starts, I have a simple macro that seems to do 
   what I want:

   (defun last-sexp-other-window()
   "Get last sexp and run it in other window.
   If there isn't another window, use current window."
     (interactive)
     (setq ow-sexp (preceding-sexp))
     (other-window 1) (eval ow-sexp) (other-window -1) )

Why not use let instead of setq ?

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: eval-last-sexp in other window
       [not found] <mailman.4338.1238531287.31690.help-gnu-emacs@gnu.org>
@ 2009-03-31 20:29 ` Pascal J. Bourguignon
  0 siblings, 0 replies; 8+ messages in thread
From: Pascal J. Bourguignon @ 2009-03-31 20:29 UTC (permalink / raw)
  To: help-gnu-emacs

Xavier Maillard <xma@gnu.org> writes:

>    pjb@informatimago.com (Pascal J. Bourguignon) wrote in
>    news:87d4bzbfky.fsf@galatea.local: 
>
>    >> Is there a way to have eval-last-sexp (typically bound to C-xC-e) run
>    >> in a different window?  This would be convenient when developing a
>    >> macro that reformats text - I want the part of the macro I'm testing
>    >> to be applied to the file being reformatted, not to my macro.
>    > 
>    > You may use M-:  to apply a form to the current buffer. 
>    > 
>    > 
>    > Otherwise:
>    > 
>    > (with-current-buffer (get-buffer "The Other Buffer Name")
>    >    (do-what-you-want)) C-x C-e
>
>    Thanks.  After several false starts, I have a simple macro that seems to do 
>    what I want:
>
>    (defun last-sexp-other-window()
>    "Get last sexp and run it in other window.
>    If there isn't another window, use current window."
>      (interactive)
>      (setq ow-sexp (preceding-sexp))
>      (other-window 1) (eval ow-sexp) (other-window -1) )
>
> Why not use let instead of setq ?

À mon avis, c'est par pure méchanceté.

-- 
__Pascal Bourguignon__


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: eval-last-sexp in other window
  2009-03-31  7:53     ` Pascal J. Bourguignon
@ 2009-04-01  2:10       ` Bob Babcock
  2009-04-01  9:09         ` Pascal J. Bourguignon
  0 siblings, 1 reply; 8+ messages in thread
From: Bob Babcock @ 2009-04-01  2:10 UTC (permalink / raw)
  To: help-gnu-emacs

pjb@informatimago.com (Pascal J. Bourguignon) wrote in
news:87bpri9lhd.fsf@galatea.local: 

>> (defun last-sexp-other-window()
>> "Get last sexp and run it in other window.
>> If there isn't another window, use current window."
>>   (interactive)
>>   (setq ow-sexp (preceding-sexp))
>>   (other-window 1) (eval ow-sexp) (other-window -1) )
> 
> At the very least, use let, not setq!
> 
> (defun last-sexp-other-window()
>  "Get last sexp and run it in other window.
> If there isn't another window, use current window."
>    (interactive)
>    (let ((ow-sexp (preceding-sexp)))
>       (other-window 1)
>       (eval ow-sexp)
>       (other-window -1)))

I will admit that I was surprised when setq worked in this context.
Perhaps there are cases where setq would fail?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: eval-last-sexp in other window
  2009-04-01  2:10       ` Bob Babcock
@ 2009-04-01  9:09         ` Pascal J. Bourguignon
  0 siblings, 0 replies; 8+ messages in thread
From: Pascal J. Bourguignon @ 2009-04-01  9:09 UTC (permalink / raw)
  To: help-gnu-emacs

Bob Babcock <wssddc@nospam.gis.net> writes:

> pjb@informatimago.com (Pascal J. Bourguignon) wrote in
> news:87bpri9lhd.fsf@galatea.local: 
>
>>> (defun last-sexp-other-window()
>>> "Get last sexp and run it in other window.
>>> If there isn't another window, use current window."
>>>   (interactive)
>>>   (setq ow-sexp (preceding-sexp))
>>>   (other-window 1) (eval ow-sexp) (other-window -1) )
>> 
>> At the very least, use let, not setq!
>> 
>> (defun last-sexp-other-window()
>>  "Get last sexp and run it in other window.
>> If there isn't another window, use current window."
>>    (interactive)
>>    (let ((ow-sexp (preceding-sexp)))
>>       (other-window 1)
>>       (eval ow-sexp)
>>       (other-window -1)))
>
> I will admit that I was surprised when setq worked in this context.
> Perhaps there are cases where setq would fail?

For example in this case:

(defun evaluate-sexps-in-other-windows ()
  (let ((ow-sexp 0)) ; count the sexps we evaluate.
     (while (< (point) (max-point))
        (incf ow-sexp)
        (forward-sexp)
        (last-sexp-other-window))
    ow-sexp))


Remember that in emacs lisp, all the bindings are special (dynamic).
When you use setq on a variable for which you don't provide a local
binding, you are actually destroying the binding of the caller (or the
caller of the caller...), therefore introducing bugs in unrelated code.

In some occasions it might be easier to use setq/setf, but do it only
on a locally rebound variable:

  (let ((var init-value))
     (setf var (f1 var))
     (loop 
        while (condp var)
        do (setf var (f2 var)))
     (setf var (f3 var))
     var)


[ which, in the case of loop can also be rewritten as:

    (loop
       with var = init-value
       initially (setf var (f1 var))
       while (condp var)
       do (setf var (f2 var))
       finally (return (f3 var)))
].



But it may be clearer to write it as:

  (f3 (fix (function f2) (function condp) (f1 init-value)))


with:

(defun fix (fun predicate value)
  (if (funcall predicate value)
     (fix fun predicate (funcall fun value))
     value))


-- 
__Pascal Bourguignon__


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-04-01  9:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.4338.1238531287.31690.help-gnu-emacs@gnu.org>
2009-03-31 20:29 ` eval-last-sexp in other window Pascal J. Bourguignon
2009-03-31 20:25 Xavier Maillard
  -- strict thread matches above, loose matches on Subject: below --
2009-03-30  4:22 Bob Babcock
2009-03-30  8:05 ` Pascal J. Bourguignon
2009-03-31  4:42   ` Bob Babcock
2009-03-31  7:53     ` Pascal J. Bourguignon
2009-04-01  2:10       ` Bob Babcock
2009-04-01  9:09         ` Pascal J. Bourguignon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).