merging Emacs.app (NeXTstep port)
[bpt/emacs.git] / lisp / woman.el
index 876fd6f..99de62e 100644 (file)
@@ -1,7 +1,7 @@
 ;;; woman.el --- browse UN*X manual pages `wo (without) man'
 
 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007 Free Software Foundation, Inc.
+;;   2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: Francis J. Wright <F.J.Wright@qmul.ac.uk>
 ;; Maintainer: FSF
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -23,9 +23,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;; (By default, WoMan will automatically define the dired keys "W" and
 ;; "w" when it loads, but only if they are not already defined.  This
-;; behaviour is controlled by the user option `woman-dired-keys'.
+;; behavior is controlled by the user option `woman-dired-keys'.
 ;; Note that the `dired-x' (dired extra) package binds
 ;; `dired-copy-filename-as-kill' to the key "w" (as pointed out by Jim
 ;; Davidson), although "W" appears to be really unused.  The `dired-x'
 ;; The *WoMan-Log* buffer
 ;; ======================
 
-;; This is modelled on the byte-compiler.  It logs all files formatted
+;; This is modeled on the byte-compiler.  It logs all files formatted
 ;; by WoMan, and if WoMan finds anything that it cannot handle then it
 ;; writes a warning to this buffer.  If the variable `woman-show-log'
 ;; is non-nil (by default it is `nil') then WoMan automatically
@@ -547,9 +545,11 @@ Change only via `Customization' or the function `add-hook'."
 
 (defcustom woman-man.conf-path
   (let ((path '("/usr/lib" "/etc")))
-    (if (eq system-type 'windows-nt)
-       (mapcar 'woman-Cyg-to-Win path)
-      path))
+    (cond ((eq system-type 'windows-nt)
+          (mapcar 'woman-Cyg-to-Win path))
+         ((eq system-type 'darwin)
+          (cons "/usr/share/misc" path))
+         (t path)))
   "List of dirs to search and/or files to try for man config file.
 A trailing separator (`/' for UNIX etc.) on directories is
 optional, and the filename is used if a directory specified is
@@ -603,8 +603,61 @@ MANPATH_MAP[ \t]+\\(\\S-+\\)[ \t]+\\(\\S-+\\)\\)" nil t)
       (setq path (cdr path)))
     (nreverse manpath)))
 
+;; Autoload so set-locale-environment can operate on it.
+;;;###autoload
+(defcustom woman-locale nil
+  "String specifying a manual page locale, or nil.
+If a manual page is available in the specified locale
+\(e.g. \"sv_SE.ISO8859-1\"), it will be offered in preference to the
+default version.  Normally, `set-locale-environment' sets this at startup."
+  :type '(choice string (const nil))
+  :group 'woman-interface
+  :version "23.1")
+
+;; FIXME Is this a sensible list of alternatives?
+(defun woman-expand-locale (locale)
+  "Expand a locale into a list suitable for man page lookup.
+Expands a locale of the form LANGUAGE_TERRITORY.CHARSET into the list:
+LANGUAGE_TERRITORY.CHARSET LANGUAGE_TERRITORY LANGUAGE.CHARSET LANGUAGE.
+The TERRITORY and CHARSET portions may be absent."
+  (string-match "\\([^._]*\\)\\(_[^.]*\\)?\\(\\..*\\)?" locale)
+  (let ((lang (match-string 1 locale))
+        (terr (match-string 2 locale))
+        (charset (match-string 3 locale)))
+    (delq nil (list locale
+                    (and charset terr (concat lang terr))
+                    (and charset terr (concat lang charset))
+                    (if (or charset terr) lang)))))
+
+(defun woman-manpath-add-locales (manpath)
+  "Add locale-specific subdirectories to the elements of MANPATH.
+MANPATH is a list of the form of `woman-manpath'.  Returns a list
+with those locale-specific subdirectories specified by the action
+of `woman-expand-locale' on `woman-locale' added, where they exist."
+  (if (zerop (length woman-locale))
+      manpath
+    (let ((subdirs (woman-expand-locale woman-locale))
+          lst dir)
+      (dolist (elem manpath (nreverse lst))
+        (dolist (sub subdirs)
+          (when (file-directory-p
+                 (setq dir
+                       ;; Use f-n-a-d because parse-colon-path does.
+                       (file-name-as-directory
+                        (expand-file-name sub (substitute-in-file-name
+                                               (if (consp elem)
+                                                   (cdr elem)
+                                                 elem))))))
+            (add-to-list 'lst (if (consp elem)
+                                  (cons (car elem) dir)
+                                dir))))
+        ;; Non-locale-specific has lowest precedence.
+        (add-to-list 'lst elem)))))
+
 (defcustom woman-manpath
-  (or (woman-parse-colon-path (getenv "MANPATH"))
+  ;; Locales could also be added in woman-expand-directory-path.
+  (or (woman-manpath-add-locales
+       (woman-parse-colon-path (getenv "MANPATH")))
       '("/usr/man" "/usr/share/man" "/usr/local/man"))
   "List of DIRECTORY TREES to search for UN*X manual files.
 Each element should be the name of a directory that contains
@@ -636,6 +689,7 @@ I recommend including drive letters explicitly, e.g.
 The MANPATH environment variable may be set using DOS semi-colon-
 separated or UN*X/Cygwin colon-separated syntax (but not mixed)."
   :type '(repeat (choice string (cons string string)))
+  :version "23.1"                    ; added woman-manpath-add-locales
   :group 'woman-interface)
 
 (defcustom woman-manpath-man-regexp "[Mm][Aa][Nn]"
@@ -808,7 +862,7 @@ Should begin with \\. and end with \\' and MUST NOT be optional."
 
 (defcustom woman-use-own-frame         ; window-system
   (or (and (fboundp 'display-graphic-p) (display-graphic-p)) ; Emacs 21
-      (memq window-system '(x w32)))   ; Emacs 20
+      (memq window-system '(x w32 ns)))        ; Emacs 20
   "If non-nil then use a dedicated frame for displaying WoMan windows.
 Only useful when run on a graphic display such as X or MS-Windows."
   :type 'boolean
@@ -961,6 +1015,9 @@ This is usually either black or white."
           (setq symbol-fonts (cons font symbol-fonts))))
     symbol-fonts))
 
+(declare-function x-list-fonts "xfaces.c"
+                 (pattern &optional face frame maximum width))
+
 (when woman-font-support
   (make-face 'woman-symbol)
 
@@ -2745,7 +2802,7 @@ Replaces || by |, but | by \, where | denotes the internal escape."
   "Process .de/am xx yy -- (re)define/append macro xx; end at `..'.
 \(Should be up to call of yy, which defaults to `.')
 Optional argument APPEND, if non-nil, means append macro."
-  ;; Modelled on woman-strings.  BEWARE: Processing of .am is a hack!
+  ;; Modeled on woman-strings.  BEWARE: Processing of .am is a hack!
   ;; Add support for .rm?
   ;; (skip-chars-forward " \t")
   (if (eolp)                           ; ignore if no argument
@@ -3540,8 +3597,10 @@ The expression may be an argument in quotes."
             (setq value (funcall op value (woman-parse-numeric-value))))
            ((looking-at "[<=>]=?")     ; relational operators
             (goto-char (match-end 0))
-            (setq op (or (intern-soft (match-string 0))
-                        (intern-soft "=")))
+            (setq op (intern-soft
+                       (if (string-equal (match-string 0) "==")
+                           "="
+                         (match-string 0))))
             (setq value (if (funcall op value (woman-parse-numeric-value))
                             1 0)))
            ((memq (setq op (following-char)) '(?& ?:)) ; Boolean and / or
@@ -3790,10 +3849,9 @@ v alters page foot left; m alters page head center.
       (insert " -- ")
       (woman-forward-arg 'unquote 'concat)
       ;; Delete repeated arguments:
-      (if (string-match (buffer-substring here (point))
+      (if (string-equal (buffer-substring here (point))
                        (buffer-substring start here))
-         (delete-region here (point)))
-      ))
+         (delete-region here (point)))))
   ;; Embolden heading (point is at end of heading):
   (woman-set-face
    (save-excursion (beginning-of-line) (point)) (point) 'woman-bold)