Xref: utzoo comp.emacs:4439 gnu.emacs:87 gnu.emacs.bug:108 Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!porthos.rutgers.edu!gaynor From: gaynor@porthos.rutgers.edu (Silver) Newsgroups: comp.emacs,gnu.emacs,gnu.emacs.bug Subject: symbolic links & GNU Emacs Keywords: breaking symbolic links Message-ID: Date: 19 Oct 88 08:46:37 GMT Organization: Rutgers Univ., New Brunswick, N.J. Lines: 65 I got burned by breaking a symbolic link chain, by the way GNU Emacs saves files. I edited a link, not realizing that it wasn't the file I had intended to edit. When I went to save the file, emacs did it's usual antics of moving the previous contents to the backup file, and saved the buffer into a newly created file. So, to avoid getting nuked in the future, I wrote a quickie which (query) resolves links when a file is found. I didn't sit around and test it for hours, but it worked on all of the nastiest cases I could think of in half an hour. It is not armed to the teeth with features; the only effect of installing it is the addition of a find-file hook and a tweek to basic-save-buffer. I think things should be done in a similar fashion by default, which is why you are seeing this on gnu.emacs.bug. I'd appreciate hearing your comments if you have any. Regards, [Ag] gaynor@rutgers.edu --------------------------------- symlink.el ---------------------------------- ;; GNU, it's yours if you want it. [Ag] gaynor@rutgers.edu (provide 'symlink) (defvar buffer-symlink-name nil "Set to the name of the file at which a symbolic link chain should be broken when performing a basic-save-buffer.") (setq find-file-hooks (cons 'find-file-symlink-hook find-file-hooks)) (defun find-file-symlink-hook () "find-file hook which assigns buffer-symlink-name upon reading a file. Interactively walks through a symlink chain until user chooses to break the chain." (set (make-local-variable 'buffer-symlink-name) (resolve-symlink-name buffer-file-name))) (defun resolve-symlink-name (file-name &optional quiet) (let ((symlink-name file-name) (sln (file-symlink-p file-name))) (while (and sln (or quiet (y-or-n-p (format "Follow symlink %s to %s? " symlink-name sln)))) (setq symlink-name (expand-file-name sln) sln (file-symlink-p sln))) symlink-name)) ;; Redefine basic-save-buffer to give precedence to buffer-symlink-name if it ;; is non-nil. (let ((bsb (symbol-function 'basic-save-buffer))) (fset 'basic-save-buffer (list (car (nthcdr 0 bsb)) ;; lambda (car (nthcdr 1 bsb)) ;; arguments (car (nthcdr 2 bsb)) ;; documentation (car (nthcdr 3 bsb)) ;; interactive (append '(let ((buffer-file-name (or buffer-symlink-name buffer-file-name)) (real-buffer-file-name buffer-file-name))) (nthcdr 4 bsb))))) ;; body of basic-save-buffer