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: Kevin Rodgers
Subject: Re: How to change and save a read-only file?
Date: Wed, 20 Nov 2013 07:22:08 -0700
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20

On 11/19/13 8:27 PM, Emanuel Berg wrote:
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."
   (interactive)
   (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))

See the "Rename or Copy" node (aka "Backup by Renaming or by Copying?")
in the Emacs Lisp manual: let-bind backup-by-copying to nil and
backup-by-copying-when-linked to t.

Also, see the interactions with backup-directory-alist that are explained in
the "Auto-save and Backup" node of the Tramp manual.

--
Kevin Rodgers
Denver, Colorado, USA




reply via email to

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