help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to change and save a read-only file?


From: Emanuel Berg
Subject: Re: How to change and save a read-only file?
Date: Tue, 02 Jul 2013 01:42:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Richard Copley <rcopley@gmail.com> writes:

> 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)))

That looks pretty standard to me. But more important, it works
great!

I take it the temporary file~ is what you used for testing?

Anyway, it boiled down to this - awesome stuff:

(defun su-edit ()
  "Edit the current buffer file as superuser."
  (interactive)
  (let ((window-start (window-start))
        (point (point)) )
    (find-alternate-file (format "/sudo::%s" (buffer-file-name)))
    (goto-char point)
    (set-window-start nil window-start) )) ; nil - selected window

-- 
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]