From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: How to change and save a read-only file? Date: Wed, 20 Nov 2013 07:22:08 -0700 Message-ID: References: <87wqk3da68.fsf@nl106-137-194.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1384957278 15508 80.91.229.3 (20 Nov 2013 14:21:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 20 Nov 2013 14:21:18 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 20 15:21:22 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vj8ef-0005Ay-L7 for geh-help-gnu-emacs@m.gmane.org; Wed, 20 Nov 2013 15:21:21 +0100 Original-Received: from localhost ([::1]:54918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vj8ef-0005T2-56 for geh-help-gnu-emacs@m.gmane.org; Wed, 20 Nov 2013 09:21:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vj8eI-0005IZ-U4 for help-gnu-emacs@gnu.org; Wed, 20 Nov 2013 09:21:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vj8eB-0006Ia-5u for help-gnu-emacs@gnu.org; Wed, 20 Nov 2013 09:20:58 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:48842) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vj8eA-0006IF-VF for help-gnu-emacs@gnu.org; Wed, 20 Nov 2013 09:20:51 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Vj8e8-0004rP-Tp for help-gnu-emacs@gnu.org; Wed, 20 Nov 2013 15:20:48 +0100 Original-Received: from 70-59-29-67.hlrn.qwest.net ([70.59.29.67]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 20 Nov 2013 15:20:48 +0100 Original-Received: from kevin.d.rodgers by 70-59-29-67.hlrn.qwest.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 20 Nov 2013 15:20:48 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 42 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 70-59-29-67.hlrn.qwest.net 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 In-Reply-To: <87wqk3da68.fsf@nl106-137-194.student.uu.se> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:94544 Archived-At: 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