🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99671

Re: one file accessed by differents names should end up in one buffer

#99671
From: Joe Wells
Date: Sat, 30 Jun 1990 00:41
120 lines
5835 bytes
In article <STEF.90Jun26165845@zweig.SUN> stef@zweig.SUN (Stephane Payrard) writes:

   Suppose I have a file which "canonic" (ie: without symbolic links)
   pathanme is /usr/spool/X/log.  If I sucessessively do
   M-xfind-file/usr/spool/X/log and M-xfind-file/var/spool/X/log, I end
   up with two buffers where I really want one: in the 2 cases, I
   reference the same file so I would have expected gnu-emacs smart enough to
   figure out that there is only one file involved.

I am including the "fix" I developed for this.

Enjoy,

-- 
Joe Wells <jbw@uswest.com>
----------------------------------------------------------------------
;; symlink-fix: Fix to remove symbolic links from file pathnames.
;; Copyright (C) 1989 Free Software Foundation, Inc.

;; This file is not officially part of GNU Emacs, but is being donated
;; to the Free Software Foundation.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

;; Created by: Joe Wells, joew@uswest.com
;; Created on: summer 1988
;; Last modified by: Joe Wells, jbw@bucsf
;; Last modified on: Fri May 11 12:56:08 1990
;; Filename: symlink-fix.el
;; Purpose: remove symbolic links from pathnames

(or (fboundp 'original-expand-file-name)
    (fset 'original-expand-file-name
	  (symbol-function 'expand-file-name)))

(defun symlink-expand-file-name (file-name &optional directory)
  "Convert FILENAME to absolute, and canonicalize it.
Second arg DEFAULT is directory to start with if FILENAME is relative
\(does not start with slash); if DEFAULT is nil or missing,
the current buffer's value of default-directory is used.
Filenames containing . or .. as components are simplified;
initial ~ is expanded.  See also the function  substitute-in-file-name.
This has been modified to resolve all symbolic links from FILENAME.
The original function definition is stored on original-expand-file-name."
  (let (left right split link)
    (setq right (original-expand-file-name file-name directory))
    (setq left "")
    (while (not (equal right ""))
      (setq split (split-file-name right))
      (setq left (join-file-name left (car split)))
      (setq right (cdr split))
      (setq link (file-symlink-p left))
      (if (null link)
	  nil
	(if (eq 0 (length link)) (setq link "."))
	(cond ((not (eq (aref link 0) ?/))
	       (setq split (split-file-name link))
	       (setq left (join-file-name (file-name-directory left)
					  (car split)))
	       (setq right (join-file-name (cdr split) right)))
	      (t
	       (setq right (join-file-name link right))
	       (setq left "")))))
    (setq left (original-expand-file-name left))
    (if (string-equal left file-name)
	file-name
      left)))

;; Concatenates LEFT and RIGHT, preserving at most one slash between them.
;; This horrible hack is necessary to work around the fact that
;; expand-file-name treats // specially.
(defun join-file-name (left right)
  (let* ((llen (length left))
	 (rlen (length right))
	 (lend llen)
	 (rstart 0)
	 slash-found)
    (while (and (> lend 0)
		(eq ?/ (aref left (1- lend))))
      (setq slash-found t
	    lend (1- lend)))
    (while (and (< rstart rlen)
		(eq ?/ (aref right rstart)))
      (setq slash-found t
	    rstart (1+ rstart)))
    (concat (if (eq lend llen) left (substring left 0 lend))
	    (if slash-found "/" "")
	    (if (eq rstart 0) right (substring right rstart rlen)))))

;; Splits FILENAME into two strings, and returns a list of the two
;; strings.  The first string will be the first filename component in
;; FILENAME, plus any leading slashes, and the second string will be the
;; rest of FILENAME, possibly a string of length 0.
(defun split-file-name (file-name)
  (if (string-match "\\`\\(/*[^/]+\\)\\(/.*\\)\\'" file-name)
      (cons (substring file-name (match-beginning 1) (match-end 1))
	    (substring file-name (match-beginning 2) (match-end 2)))
    (cons file-name "")))

;; Takes FILENAME and LINK and returns a string which substitutes LINK for
;; the last component of FILENAME.
(defun hack-local-link (file-name link)
  (or (string-match "\\`\\(.*/\\)[^/]+\\'" file-name)
      (error "hack-local-link bad argument: %s" file-name))
  (concat (substring file-name (match-beginning 1) (match-end 1)) link))

(provide 'symlink-fix)
Technical Details
Message-ID: <JBW.90Jun29184155@zeb.uswest.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!ncar!boulder!uswat!jbw
References: <STEF.90Jun26165845@zweig.SUN>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,d312b7b2bcea8e37
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-06-30 09:53:34 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!ncar!boulder!uswat!jbw
From: jbw@zeb.uswest.com (Joe Wells)
Newsgroups: gnu.emacs.bug
Subject: Re: one file accessed by differents names should end up in one buffer
Message-ID: <JBW.90Jun29184155@zeb.uswest.com>
Date: 30 Jun 90 00:41:55 GMT
References: <STEF.90Jun26165845@zweig.SUN>
Sender: news@uswat.UUCP
Distribution: gnu
Organization: /home/zeb/jbw/.organization
Lines: 120
Posted: Sat Jun 30 01:41:55 1990
In-reply-to: stef@zweig.SUN's message of 26 Jun 90 23:58:45 GMT