all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Glenn Morris <rgm@gnu.org>
Cc: 23050-done@debbugs.gnu.org, Bogolisk <bogolisk@gmail.com>,
	Jackson Hamilton <jackson@jacksonrayhamilton.com>
Subject: bug#23050: package.el overwrites symlinks when saving "(package-initialize)"
Date: Sun, 22 May 2016 17:40:48 -0700	[thread overview]
Message-ID: <57425190.5040107@cs.ucla.edu> (raw)
In-Reply-To: <CAGiE8Aw73cf7p0LGyUrVSqU5P6tf8zJZsk=bQ6epM23UA9YCaQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

> So package.el could avoid the issue by binding
> find-file-visit-truename, like cus-edit does (see bug#454).

Thanks, that suggestion worked when I tried it, so I installed the attached 
patch into emacs-25 and am marking this bug as done.

[-- Attachment #2: 0001-Do-not-trash-symlinks-to-init-file.txt --]
[-- Type: text/plain, Size: 2395 bytes --]

From 239521765c6ecf5679463dd9603359bf907570eb Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 22 May 2016 17:29:58 -0700
Subject: [PATCH] Do not trash symlinks to init file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If the user’s init file is a symbolic link, do not break the link
when initializing the package system.  Problem reported by Jackson
Hamilton (Bug#23050).
* lisp/emacs-lisp/package.el (package--ensure-init-file):
Bind find-file-visit-truename when visiting the init file, and
save and restore the buffer name the way cus-edit does in a
similar situation (Bug#454).
---
 lisp/emacs-lisp/package.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index b0a6db0..14626e2 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1869,6 +1869,7 @@ package--ensure-init-file
              (file-readable-p user-init-file)
              (file-writable-p user-init-file))
     (let* ((buffer (find-buffer-visiting user-init-file))
+           buffer-name
            (contains-init
             (if buffer
                 (with-current-buffer buffer
@@ -1884,8 +1885,12 @@ package--ensure-init-file
                 (re-search-forward "(package-initialize\\_>" nil 'noerror)))))
       (unless contains-init
         (with-current-buffer (or buffer
-                                 (let ((delay-mode-hooks t))
+                                 (let ((delay-mode-hooks t)
+                                       (find-file-visit-truename t))
                                    (find-file-noselect user-init-file)))
+          (when buffer
+            (setq buffer-name (buffer-file-name))
+            (set-visited-file-name (file-chase-links user-init-file)))
           (save-excursion
             (save-restriction
               (widen)
@@ -1904,7 +1909,10 @@ package--ensure-init-file
                 (insert "\n"))
               (let ((file-precious-flag t))
                 (save-buffer))
-              (unless buffer
+              (if buffer
+                  (progn
+                    (set-visited-file-name buffer-name)
+                    (set-buffer-modified-p nil))
                 (kill-buffer (current-buffer)))))))))
   (setq package--init-file-ensured t))
 
-- 
2.7.4


      parent reply	other threads:[~2016-05-23  0:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-18  6:53 bug#23050: package.el overwrites symlinks when saving "(package-initialize)" Jackson Hamilton
2016-03-19  2:05 ` Glenn Morris
2016-03-19  2:13   ` Glenn Morris
2016-03-22 16:51     ` bug#23050: package.el overwrites symlinks when saving Bogolisk
2016-05-23  0:40 ` Paul Eggert [this message]

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=57425190.5040107@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=23050-done@debbugs.gnu.org \
    --cc=bogolisk@gmail.com \
    --cc=jackson@jacksonrayhamilton.com \
    --cc=rgm@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.