[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why save-excursion doesn't restore cursor position after 3 kill-line
From: |
tyler |
Subject: |
Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls? |
Date: |
Fri, 28 Nov 2008 11:59:52 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Barry Margolin <barmar@alum.mit.edu> writes:
> In article
> <429c5cab-0015-4eb6-a794-ce990c6255d6@q26g2000prq.googlegroups.com>,
> "seberino@spawar.navy.mil" <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
- Why save-excursion doesn't restore cursor position after 3 kill-line calls?, address@hidden, 2008/11/28
- Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls?, Barry Margolin, 2008/11/28
- Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls?,
tyler <=
- Message not available
- Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls?, Xah Lee, 2008/11/28
- Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls?, tyler, 2008/11/28
- Message not available
- Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls?, Andreas Politz, 2008/11/28
- Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls?, tyler, 2008/11/28
- Message not available
- Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls?, Barry Margolin, 2008/11/29
- Re: Why save-excursion doesn't restore cursor position after 3 kill-line calls?, tyler, 2008/11/29