From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls? Date: Fri, 28 Nov 2008 23:49:45 +0100 Message-ID: <873ahbtqie.fsf@escher.local.home> References: <429c5cab-0015-4eb6-a794-ce990c6255d6@q26g2000prq.googlegroups.com> <87oczzkfif.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 1227912654 15678 80.91.229.12 (28 Nov 2008 22:50:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Nov 2008 22:50:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 28 23:51:57 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 1L6CBo-0002fL-Np for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 23:51:56 +0100 Original-Received: from localhost ([127.0.0.1]:40424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L6CAf-0001Xr-23 for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 17:50:45 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L6CA4-0001KR-FM for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 17:50:08 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L6CA3-0001Iy-3J for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 17:50:08 -0500 Original-Received: from [199.232.76.173] (port=35014 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L6CA2-0001Iq-Os for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 17:50:06 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:54417 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L6CA1-0000fk-Vq for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 17:50:06 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L6C9v-00025s-3w for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 22:49:59 +0000 Original-Received: from i59f54e12.versanet.de ([89.245.78.18]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Nov 2008 22:49:59 +0000 Original-Received: from stephen.berman by i59f54e12.versanet.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Nov 2008 22:49:59 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 67 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: i59f54e12.versanet.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:60208 Archived-At: On Fri, 28 Nov 2008 11:59:52 -0400 tyler wrote: > Barry Margolin writes: > >> In article >> <429c5cab-0015-4eb6-a794-ce990c6255d6@q26g2000prq.googlegroups.com>, >> "seberino@spawar.navy.mil" wrote: >> >>> I'm trying to map C-d to a function that deletes an entire line and >>> stops on the *SAME* column number of the following line.... >>> >>> (global-set-key "\^d" (lambda () (interactive) (save-excursion (kill- >>> line) >>> >>> (kill-line 0) >>> >>> (kill-line)))) >>> >>> Why doesn't save-excursion preserve the column number after these kill- >>> line invocations? >>> >>> chris >> >> save-excursion restores the location in the buffer, not the row and >> column positions. If the text around the location is deleted, it finds >> the closest remaining location. > > I don't understand. The documentation for save-excursion says: > > "Save point, mark, and current buffer; execute body; restore those things." > > I tried Chris' code, first calling (point), then running the command, > then running (point) again, and the value has definitely not been > restored. It is possible, for example: > > (defun mykill () > (interactive) > (let ((p (point))) > (kill-line) > (kill-line 0) > (kill-line) > (goto-char p))) > > I've been confused by save-excursion in other contexts though, so I'm > still unclear on why the original version of this function doesn't work. If Barry Margolin's accurate but terse explanation is unclear, perhaps this more detailed remark from the Emacs Lisp reference manual, node (elisp)Excursions, helps: "*Warning:* Ordinary insertion of text adjacent to the saved point value relocates the saved value, just as it relocates all markers. More precisely, the saved value is a marker with insertion type `nil'. *Note Marker Insertion Types::. Therefore, when the saved point value is restored, it normally comes before the inserted text." To see the difference, compare the first code above with the following: (defun mykill () (interactive) (save-excursion (forward-line 5) (kill-line) (kill-line 0) (kill-line))) Steve Berman