comparison lisp/man.el @ 54515:9172c9ef1dcf

(Man-width): New var. (Man-getpage-in-background): Use it. (Man-support-local-filenames): New var and fun. (Man-build-man-command): Don't add a second %s. (Man-fontify-manpage): Clean up message. (Man-mode): Set outline-regexp, outline-level, imenu-generic-expression.
author Juri Linkov <juri@jurta.org>
date Tue, 23 Mar 2004 07:33:39 +0000
parents 230edeac0da5
children 4729059e27b8
comparison
equal deleted inserted replaced
54514:4f9a38a6854c 54515:9172c9ef1dcf
1 ;;; man.el --- browse UNIX manual pages -*- coding: iso-8859-1 -*- 1 ;;; man.el --- browse UNIX manual pages -*- coding: iso-8859-1 -*-
2 2
3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2001, 2003 Free Software Foundation, Inc. 3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2001, 2003, 2004 Free Software Foundation, Inc.
4 4
5 ;; Author: Barry A. Warsaw <bwarsaw@cen.com> 5 ;; Author: Barry A. Warsaw <bwarsaw@cen.com>
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Keywords: help 7 ;; Keywords: help
8 ;; Adapted-By: ESR, pot 8 ;; Adapted-By: ESR, pot
173 :type '(radio (const newframe) (const pushy) (const bully) 173 :type '(radio (const newframe) (const pushy) (const bully)
174 (const aggressive) (const friendly) 174 (const aggressive) (const friendly)
175 (const polite) (const quiet) (const meek)) 175 (const polite) (const quiet) (const meek))
176 :group 'man) 176 :group 'man)
177 177
178 (defcustom Man-width nil
179 "*Number of columns for which manual pages should be formatted.
180 If nil, the width of the window selected at the moment of man
181 invocation is used. If non-nil, the width of the frame selected
182 at the moment of man invocation is used. The value also can be a
183 positive integer."
184 :type '(choice (const :tag "Window width" nil)
185 (const :tag "Frame width" t)
186 (integer :tag "Specific width" :value 65))
187 :group 'man)
188
178 (defcustom Man-frame-parameters nil 189 (defcustom Man-frame-parameters nil
179 "*Frame parameter list for creating a new frame for a manual page." 190 "*Frame parameter list for creating a new frame for a manual page."
180 :type 'sexp 191 :type 'sexp
181 :group 'man) 192 :group 'man)
182 193
314 (defvar Man-specified-section-option 325 (defvar Man-specified-section-option
315 (if (string-match "-solaris[0-9.]*$" system-configuration) 326 (if (string-match "-solaris[0-9.]*$" system-configuration)
316 "-s" 327 "-s"
317 "") 328 "")
318 "Option that indicates a specified a manual section name.") 329 "Option that indicates a specified a manual section name.")
330
331 (defvar Man-support-local-filenames 'auto-detect
332 "Internal cache for the value of the function `Man-support-local-filenames'.
333 `auto-detect' means the value is not yet determined.
334 Otherwise, the value is whatever the function
335 `Man-support-local-filenames' should return.")
319 336
320 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 337 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
321 ;; end user variables 338 ;; end user variables
322 339
323 ;; other variables and keymap initializations 340 ;; other variables and keymap initializations
484 (length Man-page-list))) 501 (length Man-page-list)))
485 502
486 (defsubst Man-build-man-command () 503 (defsubst Man-build-man-command ()
487 "Builds the entire background manpage and cleaning command." 504 "Builds the entire background manpage and cleaning command."
488 (let ((command (concat manual-program " " Man-switches 505 (let ((command (concat manual-program " " Man-switches
489 ; Stock MS-DOS shells cannot redirect stderr; 506 (cond
490 ; `call-process' below sends it to /dev/null, 507 ;; Already has %s
491 ; so we don't need `2>' even with DOS shells 508 ((string-match "%s" manual-program) "")
492 ; which do support stderr redirection. 509 ;; Stock MS-DOS shells cannot redirect stderr;
493 (if (not (fboundp 'start-process)) 510 ;; `call-process' below sends it to /dev/null,
494 " %s" 511 ;; so we don't need `2>' even with DOS shells
495 (concat " %s 2>" null-device)))) 512 ;; which do support stderr redirection.
513 ((not (fboundp 'start-process)) " %s")
514 ((concat " %s 2>" null-device)))))
496 (flist Man-filter-list)) 515 (flist Man-filter-list))
497 (while (and flist (car flist)) 516 (while (and flist (car flist))
498 (let ((pcom (car (car flist))) 517 (let ((pcom (car (car flist)))
499 (pargs (cdr (car flist)))) 518 (pargs (cdr (car flist))))
500 (setq command 519 (setq command
552 (setq section (if Man-downcase-section-letters-flag 571 (setq section (if Man-downcase-section-letters-flag
553 (downcase s2) 572 (downcase s2)
554 s2) 573 s2)
555 slist nil)))) 574 slist nil))))
556 (concat Man-specified-section-option section " " name)))) 575 (concat Man-specified-section-option section " " name))))
576
577 (defun Man-support-local-filenames ()
578 "Check the availability of `-l' option of the man command.
579 This option allows `man' to interpret command line arguments
580 as local filenames.
581 Return the value of the variable `Man-support-local-filenames'
582 if it was set to nil or t before the call of this function.
583 If t, the man command supports `-l' option. If nil, it don't.
584 Otherwise, if the value of `Man-support-local-filenames'
585 is neither t nor nil, then determine a new value, set it
586 to the variable `Man-support-local-filenames' and return
587 a new value."
588 (if (or (not Man-support-local-filenames)
589 (eq Man-support-local-filenames t))
590 Man-support-local-filenames
591 (setq Man-support-local-filenames
592 (with-temp-buffer
593 (and (equal (condition-case nil
594 (call-process manual-program nil t nil "--help")
595 (error nil))
596 0)
597 (progn
598 (goto-char (point-min))
599 (search-forward "--local-file" nil t))
600 t)))))
557 601
558 602
559 ;; ====================================================================== 603 ;; ======================================================================
560 ;; default man entry: get word under point 604 ;; default man entry: get word under point
561 605
677 (if window-system 721 (if window-system
678 (unless (or (getenv "MANWIDTH") (getenv "COLUMNS")) 722 (unless (or (getenv "MANWIDTH") (getenv "COLUMNS"))
679 ;; This isn't strictly correct, since we don't know how 723 ;; This isn't strictly correct, since we don't know how
680 ;; the page will actually be displayed, but it seems 724 ;; the page will actually be displayed, but it seems
681 ;; reasonable. 725 ;; reasonable.
682 (setenv "COLUMNS" (number-to-string (frame-width))))) 726 (setenv "COLUMNS" (number-to-string
727 (cond
728 ((and (integerp Man-width) (> Man-width 0))
729 Man-width)
730 (Man-width (frame-width))
731 ((window-width)))))))
683 (setenv "GROFF_NO_SGR" "1") 732 (setenv "GROFF_NO_SGR" "1")
684 (if (fboundp 'start-process) 733 (if (fboundp 'start-process)
685 (set-process-sentinel 734 (set-process-sentinel
686 (start-process manual-program buffer "sh" "-c" 735 (start-process manual-program buffer "sh" "-c"
687 (format (Man-build-man-command) man-args)) 736 (format (Man-build-man-command) man-args))
755 804
756 (defun Man-fontify-manpage () 805 (defun Man-fontify-manpage ()
757 "Convert overstriking and underlining to the correct fonts. 806 "Convert overstriking and underlining to the correct fonts.
758 Same for the ANSI bold and normal escape sequences." 807 Same for the ANSI bold and normal escape sequences."
759 (interactive) 808 (interactive)
760 (message "Please wait: making up the %s man page..." Man-arguments) 809 (message "Please wait: formatting the %s man page..." Man-arguments)
761 (goto-char (point-min)) 810 (goto-char (point-min))
762 (while (search-forward "\e[1m" nil t) 811 (while (search-forward "\e[1m" nil t)
763 (delete-backward-char 4) 812 (delete-backward-char 4)
764 (put-text-property (point) 813 (put-text-property (point)
765 (progn (if (search-forward "\e[0m" nil 'move) 814 (progn (if (search-forward "\e[0m" nil 'move)
974 buffer-read-only t) 1023 buffer-read-only t)
975 (buffer-disable-undo (current-buffer)) 1024 (buffer-disable-undo (current-buffer))
976 (auto-fill-mode -1) 1025 (auto-fill-mode -1)
977 (use-local-map Man-mode-map) 1026 (use-local-map Man-mode-map)
978 (set-syntax-table man-mode-syntax-table) 1027 (set-syntax-table man-mode-syntax-table)
1028 (setq imenu-generic-expression (list (list nil Man-heading-regexp 0)))
1029 (set (make-local-variable 'outline-regexp) Man-heading-regexp)
1030 (set (make-local-variable 'outline-level) (lambda () 1))
979 (Man-build-page-list) 1031 (Man-build-page-list)
980 (Man-strip-page-headers) 1032 (Man-strip-page-headers)
981 (Man-unindent) 1033 (Man-unindent)
982 (Man-goto-page 1) 1034 (Man-goto-page 1)
983 (run-hooks 'Man-mode-hook)) 1035 (run-hooks 'Man-mode-hook))