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 16:18:15 -0400 Message-ID: <87fxlbk3js.fsf@blackbart.sedgenet> References: <429c5cab-0015-4eb6-a794-ce990c6255d6@q26g2000prq.googlegroups.com> <9700303c-f0d1-42b6-b1d0-a74e3fe2ab33@t26g2000prh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1227903564 23412 80.91.229.12 (28 Nov 2008 20:19:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Nov 2008 20:19: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 Fri Nov 28 21:20:25 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 1L69p9-0000kR-Uc for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 21:20:24 +0100 Original-Received: from localhost ([127.0.0.1]:51163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L69o0-0001Eh-0u for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 15:19:12 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L69nC-00012p-W2 for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 15:18:23 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L69nC-00012L-FY for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 15:18:22 -0500 Original-Received: from [199.232.76.173] (port=52212 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L69nC-00012E-23 for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 15:18:22 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:47825 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 1L69nB-0004y0-Ey for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 15:18:21 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L69n6-0005vC-5r for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 20:18:16 +0000 Original-Received: from h148hlfxns0149w-142177125.pppoe-dynamic.ns.aliant.net ([142.177.125.148]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Nov 2008 20:18:16 +0000 Original-Received: from tyler.smith by h148hlfxns0149w-142177125.pppoe-dynamic.ns.aliant.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Nov 2008 20:18:16 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 76 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: h148hlfxns0149w-142177125.pppoe-dynamic.ns.aliant.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:V1ecn40qhodqewkYZcRHBzi6v7k= 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:60198 Archived-At: Xah Lee writes: > 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. Cursor-position is point in emacs jargon, no? The documentation clearly states that point is saved and restored during save-excursion. Point itself is just an integer, and does not disappear when text is deleted. > in your code, your several kill-line code deleted the line the cursor > is on. > > what exactly do you want to do? I'm not sure what the OP wanted, but I want to understand why save-excursion does not do the same thing as my function `mykill' does. > > 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. The function provided above does exactly what I wanted (granted for only simple cases). Try it with point on the u in 'presumes' in the paragraph above. That line is killed, with point ending up at the same numeric position where it started - i.e., the same column on the following line. (This will only be the case when the following line is long enough, of course). The real question is why save-excursion *doesn't* do this. The documentation states that point is restored. Either 'restoring' point means something other than setting point to equal the previously saved value, or there is something missing in the documentation. Tyler -- Philosophy of science is about as useful to scientists as ornithology is to birds. --Richard Feynman