help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proper use of save-current-buffer


From: tyler
Subject: proper use of save-current-buffer
Date: Fri, 04 Apr 2008 23:51:40 -0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

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))

-- 



reply via email to

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