From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls? Date: Fri, 28 Nov 2008 08:43:19 -0800 (PST) Organization: http://groups.google.com Message-ID: <9700303c-f0d1-42b6-b1d0-a74e3fe2ab33@t26g2000prh.googlegroups.com> References: <429c5cab-0015-4eb6-a794-ce990c6255d6@q26g2000prq.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1227899988 12838 80.91.229.12 (28 Nov 2008 19:19:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Nov 2008 19:19:48 +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 20:20:49 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 1L68tU-0006ES-RZ for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 20:20:49 +0100 Original-Received: from localhost ([127.0.0.1]:49285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L68sL-00079n-2n for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 14:19:37 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!t26g2000prh.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 53 Original-NNTP-Posting-Host: 24.6.185.159 Original-X-Trace: posting.google.com 1227890600 14083 127.0.0.1 (28 Nov 2008 16:43:20 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 28 Nov 2008 16:43:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t26g2000prh.googlegroups.com; posting-host=24.6.185.159; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:164865 X-Mailman-Approved-At: Fri, 28 Nov 2008 14:18:29 -0500 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:60195 Archived-At: On Nov 28, 7:59 am, tyler wrote: > Barry Margolin writes: > > In article > > <429c5cab-0015-4eb6-a794-ce990c625...@q26g2000prq.googlegroups.com>, > > "seber...@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? > 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. Like Barry Margolin has said, save-excursion restore the cursor position but not when the text the cursor is on is deleted in your code. In other words, it is theoretically senseless to preserve something that's not there anymore. in your code, your several kill-line code deleted the line the cursor is on. what exactly do you want to do? if you want to return your cursor to the same column it was on, you can get the column position then move your cursor to that afterwards. However, that presumes that you are on a line that has enough chars to cover the column. Overall, i think you need to clarify the behavior you wanted. Xah =E2=88=91 http://xahlee.org/ =E2=98=84