all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to change and save a read-only file?
Date: Wed, 20 Nov 2013 07:22:08 -0700	[thread overview]
Message-ID: <l6igf9$e9b$1@ger.gmane.org> (raw)
In-Reply-To: <87wqk3da68.fsf@nl106-137-194.student.uu.se>

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	other threads:[~2013-11-20 14:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20  3:27 How to change and save a read-only file? Emanuel Berg
2013-11-20 14:22 ` Kevin Rodgers [this message]
     [not found] ` <mailman.6640.1384957268.10748.help-gnu-emacs@gnu.org>
2013-11-20 16:24   ` Emanuel Berg
     [not found] <mailman.2780.1372497288.22516.help-gnu-emacs@gnu.org>
2013-06-29 13:10 ` Emanuel Berg
2013-06-29 13:30   ` Emanuel Berg
2013-07-01 22:35     ` Richard Copley
     [not found]     ` <mailman.14.1372718151.12400.help-gnu-emacs@gnu.org>
2013-07-01 23:42       ` Emanuel Berg
2013-07-19 12:36         ` Emanuel Berg
  -- strict thread matches above, loose matches on Subject: below --
2013-06-29  9:14 Marius Hofert
2013-06-29  9:20 ` Peter Dyballa
2013-06-29 11:04 ` Thorsten Jolitz
2013-06-29 11:16   ` Jude DaShiell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='l6igf9$e9b$1@ger.gmane.org' \
    --to=kevin.d.rodgers@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.