[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to change and save a read-only file?
From: |
Richard Copley |
Subject: |
Re: How to change and save a read-only file? |
Date: |
Mon, 1 Jul 2013 23:35:45 +0100 |
On 29 June 2013 14:30, Emanuel Berg <embe8573@student.uu.se> wrote:
> Emanuel Berg <embe8573@student.uu.se> writes:
>
>> (defun su-edit ()
>> "Edit the current buffer file as superuser -
>> in a new buffer, that should look the same."
>> (interactive)
>> (let ((start-point-pos (point)))
>> (recenter-top-bottom 0)
>> (let ((top-window-pos (point))
>> (buffer (buffer-file-name)) )
>> (kill-buffer)
>> (find-file (format "/sudo::%s" buffer))
>> (goto-char top-window-pos)
>> (recenter-top-bottom 0)
>> (goto-char start-point-pos) )))
>
> Aha, now I see, `recenter-top-bottom' doesn't change the point!
> Silly. Still, even though with this realization I could fix it, I
> leave it open to you foxes as you more than once have provided me
> with standard solutions (for which I am grateful, because they
> work better - and not without pride I add that last word :) )
Not sure about "standard solution" (or "fox") but I would do it like this:
(let ((window-start (window-start))
(point (point)))
(find-alternate-file (format "%s~" (buffer-file-name)))
(goto-char point)
(set-window-start nil window-start)))
- Re: How to change and save a read-only file?,
Richard Copley <=