🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #100073

where-is-file & buffer-offer-save

#100073
From: Hallvard B Furuseth
Date: Fri, 26 Jan 1990 11:22
53 lines
2697 bytes
Here are two defuns which my info.el uses:
  WHERE-IS-FILE (Search for a file in a list of directories), and
  BUFFER-OFFER-SAVE (Offer to save the buffer, if it is modified).

where-is-file is a lisp version of openp() in src/lread.c.  Instead of
using the exec_only argument of openp(), it returns the name of a
*readable* file.  Should include an optional ACCESS argument as well,
but I do not know how.  (To check f.ex "is there an executable file
named foo?").

**Please** move where-is-file to src/lread.c.  It is quite useful, and
it feels stupid to use this slow Lisp version when there already is a
C version.  It could use openp() if exec_only were the mode-argument
to access() and not only a boolean flag.  Or openp() and
Fwhere_is_file() could both call an extended_openp().


Hallvard Furuseth
hallvard@ifi.uio.no

(defun where-is-file (path filename &optional suffixes)
  "Search through PATH (list) for readable FILENAME, expanded by one of the
optional SUFFIXES (string of suffixes separated by \":\"s)."
  (let ((filelist nil) pos temp templist)
    ;; Make list of possible file names
    (setq filelist
	  (if suffixes
	      (progn
		(while (setq pos (string-match ":[^:]*$" suffixes))
		  (setq filelist (cons (concat filename
					       (substring suffixes (1+ pos)))
				       filelist))
		  (setq suffixes (substring suffixes 0 pos)))
		(cons (concat filename suffixes) filelist))
	    (list filename)))
    ;; Search PATH for a readable file in filelist
    (catch 'bar
      (if (file-name-absolute-p filename) (setq path '("")))
      (while path
	(setq templist filelist)
	(while (if (file-readable-p
		    (setq temp (expand-file-name (car templist) (car path))))
		   (throw 'bar temp)
		 (setq templist (cdr templist))))
	(setq path (cdr path)))
      nil)))


(defun buffer-offer-save (&optional prompt)
  "Offer to save the buffer, if it is modified."
  (and (buffer-modified-p)
       (y-or-n-p (or prompt (format "Save file %s? " buffer-file-name)))
       (save-buffer)))
Technical Details
Message-ID: <9001261122.AA00694@nikud.uio.no>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!snorkelwacker!tut.cis.ohio-state.edu!IFI.UIO.NO!hallvard

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,dad9abd669009462,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-01-26 03:22:45 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!snorkelwacker!tut.cis.ohio-state.edu!IFI.UIO.NO!hallvard
From: hallvard@IFI.UIO.NO (Hallvard B Furuseth)
Newsgroups: gnu.emacs.bug
Subject: where-is-file & buffer-offer-save
Message-ID: <9001261122.AA00694@nikud.uio.no>
Date: 26 Jan 90 11:22:45 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 53
Posted: Fri Jan 26 12:22:45 1990