From: tyler <tyler@blackbart.sedgenet>
To: help-gnu-emacs@gnu.org
Subject: proper use of save-current-buffer
Date: Fri, 04 Apr 2008 23:51:40 -0300 [thread overview]
Message-ID: <87ej9l2ev7.fsf@blackbart.sedgenet> (raw)
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))
--
next reply other threads:[~2008-04-05 2:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-05 2:51 tyler [this message]
2008-04-05 2:59 ` proper use of save-current-buffer 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ej9l2ev7.fsf@blackbart.sedgenet \
--to=tyler@blackbart.sedgenet \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).