* proper use of save-current-buffer
@ 2008-04-05 2:51 tyler
2008-04-05 2:59 ` tyler
2008-04-07 2:24 ` proper use of save-current-buffer, sleep-for not sleeping? tyler
0 siblings, 2 replies; 5+ messages in thread
From: tyler @ 2008-04-05 2:51 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I'm messing with ESS, which is a mode for interacting with a
command-line stats program. As such, it's based on comint-mode. The
function I'm working on sends the region to the process. Usually, this
entails sending selected text from one buffer to another one, where the
process is 'attached'. I want to add a bit of clean up in the process
buffer after the function does it's job, so I added the following to the
function:
(sleep-for 1)
(save-current-buffer
(set-buffer (get-ess-buffer ess-current-process-name))
(end-of-buffer)
(comint-bol)
(kill-line))
The sleep-for was necessary, as the process was adding bits of text to
the process buffer *after* the code in the function had completed.
What I've got now is some strange jumping around in the source buffer. I
select a region, send it to the process buffer, and then the source
buffer jumps. Sometimes it just recenters, sometimes point actually
moves. I've tried both save-excursion and save-current-buffer, but both
produce the same movement in the source buffer. Is there something else
I can do to leave point in the source buffer in the same position, and
not have the buffer recentered after sending code to the process buffer?
I have pasted the complete function below for context.
Thanks,
Tyler
(defun ess-eval-region (start end toggle &optional message)
"Send the current region to the inferior ESS process.
With prefix argument toggle the meaning of `ess-eval-visibly-p';
this does not apply when using the S-plus GUI, see `ess-eval-region-ddeclient'."
(interactive "r\nP")
;;(untabify (point-min) (point-max))
;;(untabify start end); do we really need to save-excursion?
(ess-force-buffer-current "Process to load into: ")
(message "Starting evaluation...")
(if (ess-ddeclient-p)
(ess-eval-region-ddeclient start end 'even-empty)
;; else: "normal", non-DDE behavior:
(let ((visibly (if toggle (not ess-eval-visibly-p) ess-eval-visibly-p)))
(if visibly
(ess-eval-linewise (buffer-substring start end))
(if ess-synchronize-evals
(ess-eval-linewise (buffer-substring start end)
(or message "Eval region"))
;; else [almost always!]
(let ((sprocess (get-ess-process ess-current-process-name)))
(process-send-region sprocess start end)
(process-send-string sprocess "\n"))))))
(sleep-for 1)
(save-current-buffer
(set-buffer (get-ess-buffer ess-current-process-name))
(end-of-buffer)
(comint-bol)
(kill-line))
(message "Finished evaluation")
;; return value
(list start end))
--
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: proper use of save-current-buffer
2008-04-05 2:51 proper use of save-current-buffer tyler
@ 2008-04-05 2:59 ` tyler
2008-04-05 3:35 ` gnus email address fixed [Re: proper use of save-current-buffer] tyler
2008-04-07 2:24 ` proper use of save-current-buffer, sleep-for not sleeping? tyler
1 sibling, 1 reply; 5+ messages in thread
From: tyler @ 2008-04-05 2:59 UTC (permalink / raw)
To: help-gnu-emacs
Incidentally, that's not my real email. I'm just starting exploring
gnus, and apparently I haven't configured it to properly display my
actual email address instead of the arbitrarily-names from my local
installation. So please, reply to the list, don't email me. And if
gnus users can point me towards the solution to this problem that'd be
swell too.
Cheers,
Tyler
--
^ permalink raw reply [flat|nested] 5+ messages in thread
* gnus email address fixed [Re: proper use of save-current-buffer]
2008-04-05 2:59 ` tyler
@ 2008-04-05 3:35 ` tyler
2008-04-05 10:10 ` gnus email address fixed Reiner Steib
0 siblings, 1 reply; 5+ messages in thread
From: tyler @ 2008-04-05 3:35 UTC (permalink / raw)
To: help-gnu-emacs
tyler <tyler@blackbart.sedgenet> writes:
> Incidentally, that's not my real email. I'm just starting exploring
> gnus, and apparently I haven't configured it to properly display my
> actual email address
>
Problem solved. Still need help with my original elisp question though!
Tyler
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: gnus email address fixed
2008-04-05 3:35 ` gnus email address fixed [Re: proper use of save-current-buffer] tyler
@ 2008-04-05 10:10 ` Reiner Steib
0 siblings, 0 replies; 5+ messages in thread
From: Reiner Steib @ 2008-04-05 10:10 UTC (permalink / raw)
To: help-gnu-emacs
On Sat, Apr 05 2008, tyler wrote:
> tyler <tyler@blackbart.sedgenet> writes:
>
>> Incidentally, that's not my real email. I'm just starting exploring
>> gnus, and apparently I haven't configured it to properly display my
>> actual email address
>>
>
> Problem solved.
JFTR, it's described on the first manual page:
,----[ (info "(gnus)Starting Up") ]
| If your system administrator has set things up properly, starting
| Gnus and reading news is extremely easy--you just type `M-x gnus' in
| your Emacs. If not, you should customize the variable
| `gnus-select-method' as described in *Note Finding the News::. For a
| minimal setup for posting should also customize the variables
| `user-full-name' and `user-mail-address'.
`----
Bye, Reiner.
--
,,,
(o o)
---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: proper use of save-current-buffer, sleep-for not sleeping?
2008-04-05 2:51 proper use of save-current-buffer tyler
2008-04-05 2:59 ` tyler
@ 2008-04-07 2:24 ` tyler
1 sibling, 0 replies; 5+ messages in thread
From: tyler @ 2008-04-07 2:24 UTC (permalink / raw)
To: help-gnu-emacs
tyler <tyler@blackbart.sedgenet> writes:
Further experimenting on the same bit of code reveals it's really not
doing what I thought it was doing. I determined that for larger
functions, which presumably take longer to process, the clean-up of the
target buffer was happening before the process returned all the output.
So I tried modifying the sleep-for time. At this point I realised that
the function was not sleeping at all! In the code below I expect a 10
second pause - why doesn't it happen?
As an aside, I now realise that accept-process-output is probably more
appropriate in this context. However, I can't make that work either.
Cheers,
Tyler
(defun ess-eval-region (start end toggle &optional message)
"Send the current region to the inferior ESS process.
With prefix argument toggle the meaning of `ess-eval-visibly-p';
this does not apply when using the S-plus GUI, see `ess-eval-region-ddeclient'."
(interactive "r\nP")
;;(untabify (point-min) (point-max))
;;(untabify start end); do we really need to save-excursion?
(ess-force-buffer-current "Process to load into: ")
(message "Starting evaluation...")
(if (ess-ddeclient-p)
(ess-eval-region-ddeclient start end 'even-empty)
;; else: "normal", non-DDE behavior:
(let ((visibly (if toggle (not ess-eval-visibly-p) ess-eval-visibly-p)))
(if visibly
(ess-eval-linewise (buffer-substring start end))
(if ess-synchronize-evals
(ess-eval-linewise (buffer-substring start end)
(or message "Eval region"))
;; else [almost always!]
(let ((sprocess (get-ess-process ess-current-process-name)))
(process-send-region sprocess start end)
(process-send-string sprocess "\n"))))))
;;;;;;;;;;; should be sleeping here!!! ;;;;;;;;;;;;;
(sleep-for 10)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(save-current-buffer
(set-buffer (get-ess-buffer ess-current-process-name))
(end-of-buffer)
(comint-bol)
(kill-line))
(message "Finished evaluation")
;; return value
(list start end))
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-04-07 2:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-05 2:51 proper use of save-current-buffer tyler
2008-04-05 2:59 ` tyler
2008-04-05 3:35 ` gnus email address fixed [Re: proper use of save-current-buffer] tyler
2008-04-05 10:10 ` gnus email address fixed Reiner Steib
2008-04-07 2:24 ` proper use of save-current-buffer, sleep-for not sleeping? tyler
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).