[gnu.emacs] MANPATH

worley@EDDIE.MIT.EDU (Dale Worley) (11/22/89)

Does anybody out there have code to read the MANPATH environment
variable and add its elements to the manual-formatted-dirlist variable
in the correct way?  It should be straightforward, but I don't want to
reinvent the wheel...

Thanks,

Dale Worley		Compass, Inc.			worley@compass.com
--
The world ends tomorrow -- be sure to back up your files!

rberlin@birdland.sun.com (Rich Berlin) (12/02/89)

This ought to fill the bill.

-- Rich

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; manpath.el --- find /cat? directories using MANPATH environment variable.
;; Author          : Rich Berlin
;; Created On      : Thu Sep  1 16:52:15 1988
;; Last Modified By: Rich Berlin
;; Last Modified On: Thu Nov 16 16:25:17 1989
;; Update Count    : 5
;; Status          : In daily use, probably OK.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; This is a handy way to keep up-to-date with the MANPATH in your .cshrc.
;; I use this by loading this file, and then doing
;; (setq manual-formatted-dirlist (search-manpath-for-cat-directories))
;;
;; Of some interest is csh-path-to-list, which you may want to use
;; for other purposes.

(defun search-manpath-for-cat-directories ()
  "Return a list of all 'cat' directories in the current path specified\n\
by the 'MANPATH' environment variable."
  (search-path-for-files-matching
   (csh-path-to-list (getenv "MANPATH")) "cat.+"))

(defun csh-path-to-list (string)
  (if (null string)
      (setq string "/usr/man"))
  (let ((path nil) index)
    (while (setq index (string-match ":" string))
      (setq path (append path (list (substring string 0 index))))
      (setq string (substring string (1+ index))))
    (setq path (append path (list string)))))


(defun search-path-for-files-matching (path regexp)
  (if (null path)
      (list regexp)
    (let (curr-dir directory-list)
      (setq regexp (format "^%s$" regexp))  ; So files MATCH regexp, instead
      (while path			    ; of just CONTAINING regexp.
	(setq curr-dir (car path))
	(setq path (cdr path))
	(if (file-exists-p curr-dir)
	    (setq directory-list (append directory-list
					 (directory-files curr-dir t regexp)))))
      directory-list)))