From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: tyler Newsgroups: gmane.emacs.help Subject: proper use of save-current-buffer Date: Fri, 04 Apr 2008 23:51:40 -0300 Message-ID: <87ej9l2ev7.fsf@blackbart.sedgenet> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1207372104 32328 80.91.229.12 (5 Apr 2008 05:08:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 5 Apr 2008 05:08:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Apr 05 07:08:55 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ji0e6-00005b-Jd for geh-help-gnu-emacs@m.gmane.org; Sat, 05 Apr 2008 07:08:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ji0dT-000471-T5 for geh-help-gnu-emacs@m.gmane.org; Sat, 05 Apr 2008 01:08:15 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!post02.iad01!post01.iad01!news.aliant.net!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:gIydyXYQ0XjFowBI2JAZl2OSA0Y= Original-Lines: 72 Original-NNTP-Posting-Host: 142.177.136.18 Original-X-Complaints-To: abuse@aliant.net Original-Xref: shelby.stanford.edu gnu.emacs.help:157699 X-Mailman-Approved-At: Sat, 05 Apr 2008 01:01:35 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:53077 Archived-At: 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)) --