Article View: gnu.emacs.help
Article #189027Re: Trouble with find-file-hooks
From: young-il choo
Date: Mon, 06 May 1991 22:51
Date: Mon, 06 May 1991 22:51
59 lines
3180 bytes
3180 bytes
In article <BROWNING.91Apr27231818@ew10.nas.nasa.gov> browning@nas.nasa.gov (David S. Browning) writes:
David> I don't like how generate-new-buffer adds <1>, <2>, etc. to buffers
David> with duplicate filenames. The number doesn't tell me what file I'm
David> editing! It's overkill to use
Rather than messing with the mode-line specifier after the buffer name has
been created, the following code generates a minimal addition to the file
name to make the buffer name unique.
;;; uniquify-simple.el Simplified uniquify --
;; Young-il Choo 1989-10-29 choo-young-il@yale.edu
;; A simplification of someone's uniquify.el so that we only add enough of
;; the path to the current name to make the buffer name unique, and we do not
;; modify other buffer names.
;; Example: When two files named ".../x/file" and ".../y/file" are opened in
;; sequence, the buffers will be name "file" and "y/file" respectively.
(defun yic-uniquify (filename)
"Returns a unique buffer name for filename."
(let ((lastname (file-name-nondirectory filename))
(buffer-name-list (mapcar 'buffer-name (buffer-list)))
(dir-list (reverse (yic-path-list filename))))
(if (string= lastname "") (setq lastname filename))
(while (and (yic-mem-string-equal lastname buffer-name-list)
(not (null dir-list)))
(setq lastname (concat (car dir-list) lastname))
(setq dir-list (cdr dir-list)))
lastname))
(defun yic-mem-string-equal (string list)
"Predicate for testing membership of STRING in LIST, by chasing the tail."
(if list ; list is not nil
(if (string= string (car list)) t
(yic-mem-string-equal string (cdr list)))
nil))
(defun yic-path-list (filename)
"Takes a full path name and returns a list of the subdirectories."
(let* ((beg (string-match "[^/]*/" filename))
(end (match-end 0)))
(if beg ; there are subdirectories
(cons (substring filename beg end)
(yic-path-list (substring filename end nil)))
nil)))
(defun create-file-buffer (filename) ;from files.el
"Creates a suitably named buffer for visiting FILENAME, adding parts of the
directory if necessary to make the name unique.."
(generate-new-buffer (yic-uniquify filename)))
--
-- Young-il Choo
Yale University Computer Science New Haven CT 06520-2158 USA
choo-young-il@cs.yale.edu 1-203-432-6828
Technical Details
Message-ID:
<1991May6.225107.9955@cs.yale.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!nnews!zaphod.mps.ohio-state.edu!caen!ox.com!yale!cs.yale.edu!cs.yale.edu!choo-young-ilReferences:
<BROWNING.91Apr27231818@ew10.nas.nasa.gov>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,b30da067b3069980 X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-05-07 10:40:25 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!nnews!zaphod.mps.ohio-state.edu!caen!ox.com!yale!cs.yale.edu!cs.yale.edu!choo-young-il From: choo-young-il@CS.Yale.Edu (young-il choo) Newsgroups: gnu.emacs.help Subject: Re: Trouble with find-file-hooks Message-ID: <1991May6.225107.9955@cs.yale.edu> Date: 6 May 91 22:51:07 GMT References: <BROWNING.91Apr27231818@ew10.nas.nasa.gov> Sender: news@cs.yale.edu (Usenet News) Distribution: gnu Organization: Yale University Computer Science Department Lines: 59 In-Reply-To: browning@nas.nasa.gov's message of 28 Apr 91 07: 18:18 GMT Nntp-Posting-Host: aqua.systemsx.cs.yale.edu