From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: tyler Newsgroups: gmane.emacs.help Subject: Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls? Date: Fri, 28 Nov 2008 11:59:52 -0400 Message-ID: <87oczzkfif.fsf@blackbart.sedgenet> References: <429c5cab-0015-4eb6-a794-ce990c6255d6@q26g2000prq.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1227888072 6867 80.91.229.12 (28 Nov 2008 16:01:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Nov 2008 16:01:12 +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 17:02:14 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 1L65mr-0001sQ-Mw for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 17:01:45 +0100 Original-Received: from localhost ([127.0.0.1]:34753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L65lh-0005aO-Qf for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 11:00:33 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L65lG-0005TO-Rp for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 11:00:06 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L65lF-0005SQ-8N for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 11:00:06 -0500 Original-Received: from [199.232.76.173] (port=60667 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L65lE-0005SF-Na for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 11:00:04 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:49686 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 1L65lE-0001Vw-65 for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 11:00:04 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L65l4-0005Zo-Rz for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 15:59:55 +0000 Original-Received: from hlfxns0149w-142068242085.pppoe-dynamic.ns.aliant.net ([142.68.242.85]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Nov 2008 15:59:54 +0000 Original-Received: from tyler.smith by hlfxns0149w-142068242085.pppoe-dynamic.ns.aliant.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Nov 2008 15:59:54 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 52 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: hlfxns0149w-142068242085.pppoe-dynamic.ns.aliant.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:vcBD/uCURKP47OdC8J+9Fw2kkMw= 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:60191 Archived-At: 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. Cheers, Tyler -- Friends don't let friends send Word documents http://www.nothingisreal.com/dfki/no-word