all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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

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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.