[comp.emacs] unix apropos

kautz@allegra.UUCP (Henry Kautz) (09/02/88)

Here's a nice addition to the manual-entry command for unix systems
which support the "man -k" option.

-------------------------------- cut -----------------------------------------
;;; unix-apropos command

;; USE:
;;   M-x unix-apropos
;; prompts for keywords, and invokes man -k.  Pops up window of possible
;; unix documentation.  Move cursor to desired command and hit RETURN.
;; Command also bound to C-h u.

;;; This file is not part of the GNU Emacs distribution (yet).

;; This file 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
;; this file, 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.

;;; MODIFICATION HISTORY:
 
;;; 9/1/88, created by  Henry Kautz
;;;                     uucp: allegra!kautz

(provide 'unix-apropos)

(global-set-key "\C-hu" 'unix-apropos)

(defvar unix-apropos-map nil)

(defun unix-apropos-get-man ()
   "Get the manual entry for the current line"
   (interactive)
   (let (topic section)
      (interactive)
      (beginning-of-line 1)
      (looking-at "\\w*")
      (setq topic (buffer-substring (match-beginning 0) (match-end 0)))
      (re-search-forward "(\\([^)]*\\))")
      (setq section (downcase (buffer-substring
				 (match-beginning 1) (match-end 1))))
      (beginning-of-line 1)
      (manual-entry topic section)
      )
   )

(defun unix-apropos (topic)
   "Display apropos for TOPIC"
   (interactive "sUnix apropos: ")
   (pop-to-buffer "*Unix Apropos*")
   (unix-apropos-mode))

(defun unix-apropos-mode ()
   "<return> get manual entry; <space> next line; <delete> previous line
a = unix apropos; h = describe mode"
   (setq buffer-read-only nil)
   (erase-buffer)
   (buffer-flush-undo (current-buffer))
   (if (null unix-apropos-map)
      (progn
	 (setq unix-apropos-map (make-sparse-keymap))
	 (define-key unix-apropos-map "\C-M" 'unix-apropos-get-man)
	 (define-key unix-apropos-map " " 'next-line)
	 (define-key unix-apropos-map "\C-?" 'previous-line)
	 (define-key unix-apropos-map "u" 'unix-apropos)
	 (define-key unix-apropos-map "a" 'unix-apropos)
	 (define-key unix-apropos-map "h" 'describe-mode)
	 (define-key unix-apropos-map "?" 'describe-mode)
	 )
      )
   (use-local-map unix-apropos-map)
   (setq mode-name "Apropos")
   (setq major-mode 'unix-apropos-mode)
   (call-process "man" nil t nil "-k" topic)
   (setq buffer-read-only t)
   (goto-char (point-min))
   )