[Top][All Lists]

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

How to change and save a read-only file?

From: Emanuel Berg
Subject: How to change and save a read-only file?
Date: Wed, 20 Nov 2013 04:27:34 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

It seems the thread that the subject refers to is
inaccessible by Gnus, so perhaps the OP won't read this
anyway, but I like to say it nonetheless, because this
bug almost drove me insane.

The below function cannot be used on symbolic links,
because with (buffer-file-name), you'll get the name
(and path) of the *link*...

When used to edit and save such a link that points to a
file not in $HOME, the result is that the link is
*replaced* by the file, and the file (at its original
place), disappears (?).

The code, with the bug:

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

The solution, I hope, is:
(file-truename (buffer-file-name))

Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:

reply via email to

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