New version from Francis J. Wright <F.J.Wright@Maths.QMW.ac.uk>:
[bpt/emacs.git] / lisp / woman.el
1 ;;; woman.el --- browse UN*X manual pages `wo (without) man'
2
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
4
5 ;; Author: Francis J. Wright <F.J.Wright@Maths.QMW.ac.uk>
6 ;; Maintainer: Francis J. Wright <F.J.Wright@Maths.QMW.ac.uk>
7 ;; Keywords: help, man, UN*X, manual
8 ;; Adapted-By: Eli Zaretskii <eliz@is.elta.co.il>
9 ;; Version: see `woman-version'
10 ;; URL: http://centaur.maths.qmw.ac.uk/Emacs/WoMan/
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
28
29 ;;; Commentary:
30
31 ;; WoMan implements a subset of the formatting performed by the Emacs
32 ;; `man' (or `manual-entry') command to format a UN*X manual `page'
33 ;; for display, but without calling any external programs. It is
34 ;; intended to emulate the whole of the -man macro package, plus those
35 ;; ?roff requests that are most commonly used in man pages. However,
36 ;; the emulation is modified to include the reformatting done by the
37 ;; Emacs `man' command. No hyphenation is performed.
38
39 ;; Advantages
40
41 ;; Much more direct, does not require any external programs.
42 ;; Supports completion on man page names.
43
44 ;; Disadvantages
45
46 ;; Not a complete emulation. Currently no support for eqn or tbl.
47 ;; Slightly slower for large man pages (but usually faster for
48 ;; small- and medium-size pages).
49
50 ;; This browser works quite well on simple well-written man files. It
51 ;; works less well on idiosyncratic files that `break the rules' or
52 ;; use the more obscure ?roff requests directly. Current test results
53 ;; are available in the file woman.status.
54
55 ;; WoMan supports the use of compressed man files via
56 ;; `auto-compression-mode' by turning it on if necessary. But you may
57 ;; need to adjust the user option `woman-file-compression-regexp'.
58
59 ;; Read on for (currently) the only documentation for WoMan!
60
61 ;; See also the documentation for the WoMan interactive commands and
62 ;; user option variables, all of which begin with the prefix `woman-'.
63 ;; This can be done most easily by loading WoMan and then running the
64 ;; command `woman-mini-help', or selecting the WoMan menu option `Mini
65 ;; Help' when WoMan is running.
66
67 ;; WoMan is still under development! Please let me know what doesn't
68 ;; work -- I am adding and improving functionality as testing shows
69 ;; that it is necessary. See below for guidance on reporting bugs.
70
71 ;; Recommended use
72 ;; ===============
73
74 ;; Put this in your .emacs:
75 ;; (autoload 'woman "woman"
76 ;; "Decode and browse a UN*X man page." t)
77 ;; (autoload 'woman-find-file "woman"
78 ;; "Find, decode and browse a specific UN*X man-page file." t)
79
80 ;; Then either (1 -- *RECOMMENDED*): If the `MANPATH' environment
81 ;; variable is set then WoMan will use it; otherwise you may need to
82 ;; reset the Lisp variable `woman-manpath', and you may also want to
83 ;; set the Lisp variable `woman-path'. Please see the online
84 ;; documentation for these variables. Now you can execute the
85 ;; extended command `woman', enter or select a manual entry topic,
86 ;; using completion, and if necessary select a filename, using
87 ;; completion. By default, WoMan suggests the word nearest to the
88 ;; cursor in the current buffer as the topic.
89
90 ;; Or (2): Execute the extended command `woman-find-file' and enter a
91 ;; filename, using completion. This mode of execution may be useful
92 ;; for temporary files outside the standard UN*X manual directory
93 ;; structure.
94
95 ;; Or (3): Put the next two sexpr's in your .emacs:
96 ;; (autoload 'woman-dired-find-file "woman"
97 ;; "In dired, run the WoMan man-page browser on this file." t)
98 ;; (add-hook 'dired-mode-hook
99 ;; (lambda ()
100 ;; (define-key dired-mode-map "W" 'woman-dired-find-file)))
101 ;; and open the directory containing the man page file using dired,
102 ;; put the cursor on the file, and press `W'.
103
104 ;; In each case, the result should (!) be a buffer in Man mode showing
105 ;; a formatted manual entry. When called from WoMan, Man mode should
106 ;; work as advertised, but modified where necessary in the context of
107 ;; WoMan. (However, `Man' will still invoke the standard Emacs
108 ;; manual-browsing facility rather than `WoMan' -- this is
109 ;; intentional!)
110
111 ;; (By default, WoMan will automatically define the dired keys "W" and
112 ;; "w" when it loads, but only if they are not already defined. This
113 ;; behaviour is controlled by the user option `woman-dired-keys'.
114 ;; Note that the `dired-x' (dired extra) package binds
115 ;; `dired-copy-filename-as-kill' to the key "w" (as pointed out by Jim
116 ;; Davidson), although "W" appears to be really unused. The `dired-x'
117 ;; package will over-write the WoMan binding to "w", whereas (by
118 ;; default) WoMan will not overwrite the `dired-x' binding.)
119
120 ;; The following is based on suggestions by Guy Gascoigne-Piggford and
121 ;; Juanma Barranquero. If you really want to square the man-woman
122 ;; circle then you might care to define the following bash function in
123 ;; .bashrc:
124
125 ;; man() { gnudoit -q '(raise-frame (selected-frame)) (woman' \"$1\" ')' ; }
126
127 ;; If you use Microsoft COMMAND.COM then you can create a file called
128 ;; man.bat somewhere in your path containing the two lines:
129
130 ;; @echo off
131 ;; gnudoit -q (raise-frame (selected-frame)) (woman \"%1\")
132
133 ;; and then (e.g. from a command prompt or the Run... option in the
134 ;; Start menu) just execute
135
136 ;; man man_page_name
137
138
139 ;; Using the `word at point' as a topic suggestion
140 ;; ===============================================
141
142 ;; By default, the `woman' command uses the word nearest to point in
143 ;; the current buffer as a suggestion for the topic to look up. The
144 ;; topic must be confirmed or edited in the minibuffer. This
145 ;; suggestion can be turned off, or `woman' can use the suggested
146 ;; topic without confirmation* if possible, by setting the user-option
147 ;; `woman-topic-at-point' to nil or t respectively. (Its default
148 ;; value is neither nil nor t, meaning ask for confirmation.)
149
150 ;; [* Thanks to Benjamin Riefenstahl for suggesting this
151 ;; functionality.]
152
153 ;; The variable `woman-topic-at-point' can be rebound locally, which
154 ;; may be useful to provide special private key bindings, e.g.
155
156 ;; (global-set-key "\C-cw"
157 ;; (lambda ()
158 ;; (interactive)
159 ;; (let ((woman-topic-at-point t))
160 ;; (woman)))))
161
162
163 ;; Customization, Hooks and Imenu
164 ;; ==============================
165
166 ;; WoMan supports the GNU Emacs 20+ customization facility, and puts
167 ;; a customization group called `WoMan' in the `Help' group under the
168 ;; top-level `Emacs' group. In order to be able to customize WoMan
169 ;; without first loading it, add the following sexp to your .emacs:
170
171 ;; (defgroup woman nil
172 ;; "Browse UNIX manual pages `wo (without) man'."
173 ;; :tag "WoMan" :group 'help :load "woman")
174
175
176 ;; WoMan currently runs two hooks: `woman-pre-format-hook' immediately
177 ;; before formatting a buffer and `woman-post-format-hook' immediately
178 ;; after formatting a buffer. These hooks can be used for special
179 ;; customizations that require code to be executed, etc., although
180 ;; most customization should be possible by setting WoMan user option
181 ;; variables, e.g. in `.emacs' and should NOT require the use of the
182 ;; hooks. `woman-pre-format-hook' might be appropriate for face
183 ;; customization, whereas `woman-post-format-hook' might be
184 ;; appropriate for installing a dynamic menu using `imenu' (although
185 ;; it is better to use the built-in WoMan imenu support).
186
187 ;; The WoMan menu provides an option to make a contents menu for the
188 ;; current man page (using imenu). Alternatively, if you set the
189 ;; variable `woman-imenu' to `t' then WoMan will do it automatically
190 ;; for every man page. The menu title is the value of the variable
191 ;; `woman-imenu-title', which is "CONTENTS" by default. By default,
192 ;; the menu shows manual sections and subsections, but you can change
193 ;; this by changing the value of `woman-imenu-generic-expression'.
194 ;; This facility is not yet widely tested and may be fooled by obscure
195 ;; man pages that `break the rules'.
196
197 ;; WoMan is configured not to replace spaces in an imenu *Completion*
198 ;; buffer. For further documentation of the use of imenu, such as
199 ;; menu sorting, see the source file imenu.el, which is distributed
200 ;; with GNU Emacs.
201
202 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
203
204 ;; Howard Melman made (essentially) the following suggestions, which
205 ;; are slightly different from the expression that I currently use.
206 ;; You may prefer one of Howard's suggestions, which I think assume
207 ;; that `case-fold-search' is `t' (which it is by default):
208
209 ;; (setq woman-imenu-generic-expression
210 ;; '((nil "^\\( \\)?\\([A-Z][A-Z ]+[A-Z]\\)[ \t]*$" 2)))
211
212 ;; will give support for .SH and .SS, though it won't show the heading
213 ;; name hierarchy. If you just want .SH in the imenu then use:
214
215 ;; (setq woman-imenu-generic-expression
216 ;; '((nil "^\\([A-Z][A-Z ]+[A-Z]\\)[ \t]*$" 1)))
217
218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
219
220
221 ;; Vertical spacing and blank lines
222 ;; ================================
223
224 ;; The number of consecutive blank lines in the formatted buffer
225 ;; should be either 0 or 1. A blank line should leave a space like
226 ;; .sp 1 (p. 14). Current policy is to output vertical space only
227 ;; immediately before text is output.
228
229
230 ;; Horizontal and vertical spacing and resolution
231 ;; ==============================================
232
233 ;; WoMan currently assumes 10 characters per inch horizontally, hence
234 ;; a horizontal resolution of 24 basic units, and 5 lines per inch
235 ;; vertically, hence a vertical resolution of 48 basic units. (nroff
236 ;; uses 240 per inch).
237
238
239 ;; The *WoMan-Log* buffer
240 ;; ======================
241
242 ;; This is modelled on the byte-compiler. It logs all files formatted
243 ;; by WoMan, and if WoMan finds anything that it cannot handle then it
244 ;; writes a warning to this buffer. If the variable `woman-show-log'
245 ;; is non-nil (by default it is `nil') then WoMan automatically
246 ;; displays this buffer. Many WoMan warnings can be completely
247 ;; ignored, because they are reporting the fact that WoMan has ignored
248 ;; requests that it is correct to ignore. In some future version this
249 ;; level of paranoia will be reduced, but not until WoMan is more
250 ;; reliable. At present, all warnings should be treated with some
251 ;; suspicion. Uninterpreted escape sequences are also logged (in some
252 ;; cases).
253
254 ;; Uninterpreted ?roff requests can optionally be left in the
255 ;; formatted buffer to indicate precisely where they occur by
256 ;; resetting the variable `woman-ignore' to `nil' (by default it is
257 ;; `t').
258
259 ;; Automatic initiation of woman decoding
260
261 ;; (Probably not a good idea. If you use it, be careful!)
262
263 ;; Put something like this in your .emacs. The call to
264 ;; set-visited-file-name is to avoid font-locking triggered by
265 ;; automatic major mode selection.
266
267 ;; (autoload 'woman-decode-region "woman")
268
269 ;; (setq format-alist
270 ;; (cons
271 ;; '(man "UN*X man-page source format" "\\.\\(TH\\|ig\\) "
272 ;; woman-decode-region nil nil
273 ;; (lambda (arg)
274 ;; set-visited-file-name
275 ;; (file-name-sans-extension buffer-file-name)))))
276 ;; format-alist))
277
278
279 ;; Reporting Bugs
280 ;; ==============
281
282 ;; If WoMan fails completely, or formats a file incorrectly
283 ;; (i.e. obviously wrongly or significantly differently from man) or
284 ;; inelegantly, then please
285
286 ;; (a) check that you are running the latest version of woman.el
287 ;; available from my web site (see above),
288
289 ;; (b) check that the problem is not already described in the file
290 ;; woman.status, also available from my web site.
291
292 ;; If both of the above are true then please email me the entry from
293 ;; the *WoMan-Log* buffer relating to the problem file, together with
294 ;; a brief description of the problem. Please indicate where you got
295 ;; the source file from, but do not send it to me unless I ask you to!
296 ;; Thanks. (There is at present no automated bug-reporting facility
297 ;; for WoMan.)
298
299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
300
301 ;; NOTE:
302
303 ;; CASE-DEPENDENCE OF FILENAMES. By default, WoMan ignores case in
304 ;; file pathnames only when it seems appropriate. MS-Windows users
305 ;; who want complete case independence should set the NTEmacs variable
306 ;; `w32-downcase-file-names' to `t' and use all lower case when
307 ;; setting WoMan file paths.
308
309 ;; (1) INCOMPATIBLE CHANGE! WoMan no longer uses a persistent topic
310 ;; cache by default. (It caused too much confusion!) Explicitly set
311 ;; the variable `woman-cache-filename' to save the cache between Emacs
312 ;; sessions. This is recommended only if the command `woman' is too
313 ;; slow the first time that it is run in an Emacs session, while it
314 ;; builds its cache in main memory, which MAY be VERY slow.
315
316 ;; (2) The user option `woman-cache-level' controls the amount of
317 ;; information cached (in main memory and, optionally, saved to disc).
318
319 ;; (3) UPDATING THE CACHE. A prefix argument always causes the
320 ;; `woman' command (only) to rebuild its topic cache, and to re-save
321 ;; it to `woman-cache-filename' if this variable has a non-nil value.
322 ;; This is necessary if the NAMES (not contents) of any of the
323 ;; directories or files in the paths specified by `woman-manpath' or
324 ;; `woman-path' change. If WoMan user options that affect the cache
325 ;; are changed then WoMan will automatically update its cache file on
326 ;; disc (if one is in use) the next time it is run in a new Emacs
327 ;; session.
328
329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
330
331
332 ;; TO DO
333 ;; =====
334
335 ;; Reconsider case sensitivity of file names.
336 ;; MUST PROCESS .if, .nr IN ORDER ENCOUNTERED IN FILE! (rcsfile, mf).
337 ;; Allow general delimiter in `\v', cf. `\h'.
338 ;; Improve major-mode documentation.
339 ;; Pre-process conditionals in macro bodies if possible for speed?
340 ;; Emulate some preprocessor support for tbl (.TS/.TE) and eqn (.EQ/.EN)
341 ;; Re-write filling and adjusting code!
342 ;; Allow word wrap at comma (for long option lists)?
343 ;; Buffer list handling not quite right.
344 ;; Make 10 or 12 pitch (cpi) optional -- 12 => ll = 78
345 ;; Use unpaddable space for tabbing?
346 ;; Tidy up handling of fonts when filling and adjusting
347 ;; -- see text/text properties?
348 ;; Improve speed
349 ;; Add font-lock support (for quoted strings, etc.)?
350 ;; Optionally save large files in enriched format?
351 ;; Add apropos facility by searching NAME (?) entry in man files?
352 ;; Documentation -- optional auto-display of formatted WoMan man page?
353 ;; Implement a bug reporter?
354 ;; Support diversion and traps (to some extent) - for Tcl/tk pages?
355 ;; Add a menu of WoMan buffers?
356 ;; Fix .fc properly?
357
358
359 ;; Implementation strategy [this description is now well out of date!]
360 ;; -- three main passes, each to process respectively:
361
362 ;; 1) non-breaking `.' requests including font macros
363 ;; 2) \ escape sequences, mainly special characters and font changes
364 ;; 3) breaking `.' requests, mainly filling and justification
365
366 ;; For each pass, a control function finds and pre-processes the
367 ;; escape or request and then calls the appropriate function to
368 ;; perform the required formatting. Based originally on enriched.el
369 ;; and format.el.
370
371 ;; The background information that made this project possible is
372 ;; freely available courtesy of Bell Labs from
373 ;; http://cm.bell-labs.com/7thEdMan/
374
375
376 ;; Acknowledgements
377 ;; ================
378
379 ;; For Heather, Kathryn and Madelyn, the women in my life
380 ;; (although they will probably never use it)!
381
382 ;; I also thank the following for helpful suggestions, bug reports,
383 ;; code fragments, general interest, etc.:
384 ;; Jari Aalto <jari.aalto@cs.tpu.fi>
385 ;; Dean Andrews <dean@dra.com>
386 ;; Juanma Barranquero <barranquero@laley-actualidad.es>
387 ;; Karl Berry <kb@cs.umb.edu>
388 ;; Jim Chapman <jchapman@netcomuk.co.uk>
389 ;; Frederic Corne <frederic.corne@erli.fr>
390 ;; Peter Craft <craft@alacritech.com>
391 ;; Charles Curley <ccurley@trib.com>
392 ;; Jim Davidson <jdavidso@teknowledge.com>
393 ;; Kevin D'Elia <Kevin.DElia@mci.com>
394 ;; John Fitch <jpff@maths.bath.ac.uk>
395 ;; Hans Frosch <jwfrosch@rish.b17c.ingr.com>
396 ;; Guy Gascoigne-Piggford <ggp@informix.com>
397 ;; Brian Gorka <gorkab@sanchez.com>
398 ;; Nicolai Henriksen <nhe@lyngso-industri.dk>
399 ;; Thomas Herchenroeder <the@software-ag.de>
400 ;; Alexander Hinds <ahinds@thegrid.net>
401 ;; Stefan Hornburg <sth@hacon.de>
402 ;; Theodore Jump <tjump@cais.com>
403 ;; Paul Kinnucan <paulk@mathworks.com>
404 ;; Jonas Linde <jonas@init.se>
405 ;; Andrew McRae <andrewm@optimation.co.nz>
406 ;; Howard Melman <howard@silverstream.com>
407 ;; Dennis Pixton <dennis@math.binghamton.edu>
408 ;; T. V. Raman <raman@Adobe.COM>
409 ;; Bruce Ravel <bruce.ravel@nist.gov>
410 ;; Benjamin Riefenstahl <benny@crocodial.de>
411 ;; Kevin Ruland <kruland@seistl.com>
412 ;; Tom Schutter <tom@platte.com>
413 ;; Wei-Xue Shi <wxshi@ma.neweb.ne.jp>
414 ;; Fabio Somenzi <fabio@joplin.colorado.edu>
415 ;; Karel Sprenger <ks@ic.uva.nl>
416 ;; Chris Szurgot <szurgot@itribe.net>
417 ;; Paul A. Thompson <pat@po.cwru.edu>
418 ;; Arrigo Triulzi <arrigo@maths.qmw.ac.uk>
419 ;; Geoff Voelker <voelker@cs.washington.edu>
420 ;; Eli Zaretskii <eliz@is.elta.co.il>
421
422 (defvar woman-version "0.54 (beta)" "WoMan version information.")
423
424 ;;; History:
425 ;; For recent change log see end of file.
426
427 \f
428 ;;; Code:
429
430 (require 'man)
431 (eval-when-compile ; to avoid compiler warnings
432 (require 'dired)
433 (require 'apropos))
434
435 (defun woman-mapcan (fn x)
436 "Return concatenated list of FN applied to successive `car' elements of X.
437 FN must return a list, cons or nil. Useful for splicing into a list."
438 ;; Based on the Standard Lisp function MAPCAN but with args swapped!
439 (and x (nconc (funcall fn (car x)) (woman-mapcan fn (cdr x)))))
440
441 (defun woman-parse-colon-path (cd-path)
442 "Explode a search path CD-PATH into a list of directory names.
443 Replace null components by calling `woman-parse-man.conf'.
444 Allow UN*X-style search paths on Microsoft platforms, i.e. allow path
445 elements to be separated by colons and convert Cygwin-style drive
446 specifiers `//x/' to `x:'."
447 ;; Based on suggestions by Jari Aalto and Eli Zaretskii.
448 (mapcar
449 (lambda (path) ; //a/b -> a:/b
450 (when (and path (string-match "\\`//./" path))
451 (setq path (substring path 1)) ; //a/b -> /a/b
452 (aset path 0 (aref path 1)) ; /a/b -> aa/b
453 (aset path 1 ?:)) ; aa/b -> a:/b
454 path)
455 (woman-mapcan ; splice into list...
456 (lambda (path)
457 ;; parse-colon-path returns nil for a null path component and
458 ;; an empty substring of MANPATH denotes the default list...
459 (if path (list path) (woman-parse-man.conf)))
460 (if (and (memq system-type '(windows-nt ms-dos))
461 (not (string-match ";" cd-path)))
462 (let ((path-separator ":"))
463 (parse-colon-path cd-path))
464 (parse-colon-path cd-path)))))
465
466 \f
467 ;;; User options:
468
469 ;; NB: Group identifiers must be lowercase!
470
471 (defgroup woman nil
472 "Browse UNIX manual pages `wo (without) man'."
473 :tag "WoMan"
474 :group 'help)
475
476 (defcustom woman-show-log nil
477 "*If non-nil then show the *WoMan-Log* buffer if appropriate.
478 I.e. if any warning messages are written to it. Default is nil."
479 :type 'boolean
480 :group 'woman)
481
482 (defcustom woman-pre-format-hook nil
483 "*Hook run by WoMan immediately before formatting a buffer.
484 Change only via `Customization' or the function `add-hook'."
485 :type 'hook
486 :group 'woman)
487
488 (defcustom woman-post-format-hook nil
489 "*Hook run by WoMan immediately after formatting a buffer.
490 Change only via `Customization' or the function `add-hook'."
491 :type 'hook
492 :group 'woman)
493
494 \f
495 ;; Interface options
496
497 (defgroup woman-interface nil
498 "Interface options for browsing UNIX manual pages `wo (without) man'."
499 :tag "WoMan Interface"
500 :group 'woman)
501
502 (defcustom woman-man.conf-path
503 '("/etc" "/usr/local/lib")
504 "*List of dirs to search and/or files to try for man config file.
505 Default is '(\"/etc\" \"/usr/local/lib\") [for GNU/Linux, Cygwin resp.]
506 A trailing separator (`/' for UNIX etc.) on directories is optional
507 and the filename matched if a directory is specified is the first to
508 contain the string \"man.conf\".
509 If MANPATH is not set but a config file is found then it is parsed
510 instead to provide a default value for `woman-manpath'."
511 :type '(repeat string)
512 :group 'woman-interface)
513
514 (defun woman-parse-man.conf ()
515 "Parse if possible Linux-style configuration file for man command.
516 Used only if MANPATH is not set or contains null components.
517 Look in `woman-man.conf-path' and return a value for `woman-manpath'.
518 Concatenate data from all lines in the config file of the form
519
520 MANPATH /usr/man"
521 ;; Functionality suggested by Charles Curley.
522 (let ((path woman-man.conf-path)
523 file manpath)
524 (while (and
525 path
526 (not (and
527 (file-readable-p (setq file (car path)))
528 ;; If not a file then find the file:
529 (or (not (file-directory-p file))
530 (and
531 (setq file
532 (directory-files file t "man\\.conf" t))
533 (file-readable-p (setq file (car file)))))
534 ;; Parse the file -- if no MANPATH data ignore it:
535 (with-temp-buffer
536 (insert-file-contents file)
537 (while (re-search-forward
538 "^[ \t]*MANPATH[ \t]+\\(\\S-+\\)" nil t)
539 (setq manpath (cons (match-string 1) manpath)))
540 manpath))
541 ))
542 (setq path (cdr path)))
543 (nreverse manpath)))
544
545 (defcustom woman-manpath
546 (let ((manpath (getenv "MANPATH")))
547 (or
548 (and manpath (woman-parse-colon-path manpath))
549 (woman-parse-man.conf)
550 '("/usr/man" "/usr/local/man")
551 ))
552 "*List of DIRECTORY TREES to search for UN*X manual files.
553 Each element should be the name of a directory that contains
554 subdirectories of the form `man?', or more precisely subdirectories
555 selected by the value of `woman-manpath-man-regexp'. Non-directory
556 and unreadable files are ignored.
557
558 If not set then the environment variable MANPATH is used. If no such
559 environment variable is found, the default list is determined by
560 consulting the man configuration file if found. By default this is
561 either `/etc/man.config' or `/usr/local/lib/man.conf', which is
562 determined by the user option `woman-man.conf-path'. An empty
563 substring of MANPATH denotes the default list. Otherwise, the default
564 value of this variable is
565
566 (\"/usr/man\" \"/usr/local/man\").
567
568 Any environment variables (names must have the UN*X-style form $NAME,
569 e.g. $HOME, $EMACSDATA, $EMACS_DIR) are evaluated first but each
570 element must evaluate to a SINGLE directory name. Trailing `/'s are
571 ignored. (Specific directories in `woman-path' are also searched.)
572
573 Microsoft platforms:
574 I recommend including drive letters explicitly, e.g.
575
576 (\"C:/Cygnus/cygwin-b20/man\" \"C:/usr/man\" \"C:/usr/local/man\").
577
578 The MANPATH environment variable may be set using DOS semi-colon-
579 separated or UN*X / Cygwin colon-separated syntax (but not mixed)."
580 :type '(repeat string)
581 :group 'woman-interface)
582
583 (defcustom woman-manpath-man-regexp "[Mm][Aa][Nn]"
584 "Regexp to match man directories UNDER `woman-manpath' directories.
585 These normally have names of the form `man?'. Its default value is
586 \"[Mm][Aa][Nn]\", which is case-insensitive mainly for the benefit of
587 Microsoft platforms. Its purpose is to avoid `cat?', `.', `..', etc."
588 ;; Based on a suggestion by Wei-Xue Shi.
589 :type 'string
590 :group 'woman-interface)
591
592 (defcustom woman-path
593 (if (eq system-type 'ms-dos) '("$DJDIR/info" "$DJDIR/man/cat[1-9onlp]"))
594 "*List of SPECIFIC DIRECTORIES to search for UN*X manual files.
595 For example
596
597 (\"/emacs/etc\").
598
599 These directories are searched in addition to the directory trees
600 specified in `woman-manpath'. Each element should be a directory
601 string or nil, which represents the current directory when the path is
602 expanded and cached. However, the last component (only) of each
603 directory string is treated as a regexp \(Emacs, not shell) and the
604 string is expanded into a list of matching directories. Non-directory
605 and unreadable files are ignored. The default value is nil.
606
607 Any environment variables (which must have the UN*X-style form $NAME,
608 e.g. $HOME, $EMACSDATA, $EMACS_DIR) are evaluated first but each
609 element must evaluate to a SINGLE directory name (regexp, see above).
610 For example
611
612 (\"$EMACSDATA\") [or equivalently (\"$EMACS_DIR/etc\")].
613
614 Trailing `/'s are discarded. (The directory trees in `woman-manpath'
615 are also searched.) On Microsoft platforms I recommend including
616 drive letters explicitly."
617 :type '(repeat (choice string (const nil)))
618 :group 'woman-interface)
619
620 (defcustom woman-cache-level 2
621 "*The level of topic caching.
622 1 - cache only the topic and directory lists
623 (the only level before version 0.34 - only for compatibility);
624 2 - cache also the directories for each topic
625 (faster, without using much more memory);
626 3 - cache also the actual filenames for each topic
627 (fastest, but uses twice as much memory).
628 The default value is currently 2, a good general compromise.
629 If the `woman' command is slow to find files then try 3, which may be
630 particularly beneficial with large remote-mounted man directories.
631 Run the `woman' command with a prefix argument or delete the cache
632 file `woman-cache-filename' for a change to take effect.
633 \(Values < 1 behave like 1; values > 3 behave like 3.)"
634 :type '(choice (const :tag "Minimal" 1)
635 (const :tag "Default" 2)
636 (const :tag "Maximal" 3))
637 :group 'woman-interface)
638
639 (defcustom woman-cache-filename nil
640 "*The full pathname of the WoMan directory and topic cache file.
641 It is used to save and restore the cache between sessions. This is
642 especially useful with remote-mounted man page files! The default
643 value of nil suppresses this action. The `standard' non-nil
644 filename is \"~/.wmncach.el\". Remember that a prefix argument forces
645 the `woman' command to update and re-write the cache."
646 :type '(choice (const :tag "None" nil)
647 (const :tag "~/.wmncach.el" "~/.wmncach.el")
648 file)
649 :group 'woman-interface)
650
651 (defcustom woman-dired-keys t
652 "*List of `dired' mode keys to define to run WoMan on current file.
653 E.g. '(\"w\" \"W\"), or any non-null atom to automatically define
654 \"w\" and \"W\" if they are unbound, or nil to do nothing.
655 Default is t."
656 :type '(choice (const :tag "None" nil)
657 (repeat string)
658 (other :tag "Auto" t))
659 :group 'woman-interface)
660
661 (defcustom woman-imenu-generic-expression
662 '((nil "\n\\([A-Z].*\\)" 1) ; SECTION, but not TITLE
663 ("*Subsections*" "^ \\([A-Z].*\\)" 1))
664 "*Imenu support for Sections and Subsections.
665 An alist with elements of the form (MENU-TITLE REGEXP INDEX) --
666 see the documentation for `imenu-generic-expression'."
667 :type 'sexp
668 :group 'woman-interface)
669
670 (defcustom woman-imenu nil
671 "*If non-nil then WoMan adds a Contents menu to the menubar.
672 It does this by calling `imenu-add-to-menubar'. Default is nil."
673 :type 'boolean
674 :group 'woman-interface)
675
676 (defcustom woman-imenu-title "CONTENTS"
677 "*The title to use if WoMan adds a Contents menu to the menubar.
678 Default is \"CONTENTS\"."
679 :type 'string
680 :group 'woman-interface)
681
682 (defcustom woman-topic-at-point-default 'confirm
683 ;; `woman-topic-at-point' may be let-bound when woman is loaded, in
684 ;; which case its global value does not get defined.
685 ;; `woman-file-name' sets it to this value if it is unbound.
686 "*Default value for `woman-topic-at-point'."
687 :type '(choice (const :tag "Yes" t)
688 (const :tag "No" nil)
689 (other :tag "Confirm" confirm))
690 :group 'woman-interface)
691
692 (defcustom woman-topic-at-point woman-topic-at-point-default
693 "*Controls use by `woman' of `word at point' as a topic suggestion.
694 If non-nil then the `woman' command uses the word at point as an
695 initial topic suggestion when it reads a topic from the minibuffer; if
696 t then the `woman' command uses the word at point WITHOUT
697 INTERACTIVE CONFIRMATION if it exists as a topic. The default value
698 is `confirm', meaning suggest a topic and ask for confirmation."
699 :type '(choice (const :tag "Yes" t)
700 (const :tag "No" nil)
701 (other :tag "Confirm" confirm))
702 :group 'woman-interface)
703
704 (defvar woman-file-regexp nil
705 "Regexp used to select (possibly compressed) man source files, e.g.
706 \"\\.\\([0-9lmnt]\\w*\\)\\(\\.\\(g?z\\|bz2\\)\\)?\\'\".
707 Built automatically from the customizable user options
708 `woman-uncompressed-file-regexp' and `woman-file-compression-regexp'.")
709
710 (defvar woman-uncompressed-file-regexp) ; for the compiler
711 (defvar woman-file-compression-regexp) ; for the compiler
712
713 (defun set-woman-file-regexp (symbol value)
714 "Bind SYMBOL to VALUE and set `woman-file-regexp' as per user customizations.
715 Used as :set cookie by Customize when customizing the user options
716 `woman-uncompressed-file-regexp' and `woman-file-compression-regexp'."
717 (set-default symbol value)
718 (and (boundp 'woman-uncompressed-file-regexp)
719 (boundp 'woman-file-compression-regexp)
720 (setq woman-file-regexp
721 (concat woman-uncompressed-file-regexp
722 "\\("
723 (substring woman-file-compression-regexp 0 -2)
724 "\\)?\\'"))))
725
726 (defcustom woman-uncompressed-file-regexp
727 "\\.\\([0-9lmnt]\\w*\\)" ; disallow no extension
728 "*Do not change this unless you are sure you know what you are doing!
729 Regexp used to select man source files (ignoring any compression extension).
730
731 The SysV standard man pages use two character suffixes, and this is
732 becoming more common in the GNU world. For example, the man pages
733 in the ncurses package include `toe.1m', `form.3x', etc.
734
735 Note: an optional compression regexp will be appended, so this regexp
736 MUST NOT end with any kind of string terminator such as $ or \\'."
737 :type 'regexp
738 :set 'set-woman-file-regexp
739 :group 'woman-interface)
740
741 (defcustom woman-file-compression-regexp
742 "\\.\\(g?z\\|bz2\\)\\'"
743 "*Do not change this unless you are sure you know what you are doing!
744 Regexp used to match compressed man file extensions for which
745 decompressors are available and handled by auto-compression mode,
746 e.g. \"\\\\.\\\\(g?z\\\\|bz2\\\\)\\\\'\" for `gzip' or `bzip2'.
747 Should begin with \\. and end with \\' and MUST NOT be optional."
748 ;; Should be compatible with car of
749 ;; `jka-compr-file-name-handler-entry', but that is unduly
750 ;; complicated, includes an inappropriate extension (.tgz) and is
751 ;; not loaded by default!
752 :type 'regexp
753 :set 'set-woman-file-regexp
754 :group 'woman-interface)
755
756 (defcustom woman-use-own-frame ; window-system
757 (or (and (fboundp 'display-graphic-p) (display-graphic-p)) ; Emacs 21
758 (memq window-system '(x w32))) ; Emacs 20
759 "*If non-nil then use a dedicated frame for displaying WoMan windows.
760 Only useful when run on a graphic display such as X or MS-Windows."
761 :type 'boolean
762 :group 'woman-interface)
763
764 \f
765 ;; Formatting options
766
767 (defgroup woman-formatting nil
768 "Formatting options for browsing UNIX manual pages `wo (without) man'."
769 :tag "WoMan Formatting"
770 :group 'woman)
771
772 (defcustom woman-fill-column 65
773 "*Right margin for formatted text -- default is 65."
774 :type 'integer
775 :group 'woman-formatting)
776
777 (defcustom woman-fill-frame nil
778 ;; Based loosely on a suggestion by Theodore Jump:
779 "*If non-nil then most of the frame width is used."
780 :type 'boolean
781 :group 'woman-formatting)
782
783 (defcustom woman-default-indent 5
784 "*Default prevailing indent set by -man macros -- default is 5.
785 Set this variable to 7 to emulate Linux man formatting."
786 :type 'integer
787 :group 'woman-formatting)
788
789 (defcustom woman-bold-headings t
790 "*If non-nil then embolden section and subsection headings. Default is t.
791 Heading emboldening is NOT standard `man' behaviour."
792 :type 'boolean
793 :group 'woman-formatting)
794
795 (defcustom woman-ignore t
796 "*If non-nil then unrecognised requests etc. are ignored. Default is t.
797 This gives the standard ?roff behaviour. If nil then they are left in
798 the buffer, which may aid debugging."
799 :type 'boolean
800 :group 'woman-formatting)
801
802 (defcustom woman-preserve-ascii nil
803 "*If non-nil then preserve ASCII characters in the WoMan buffer.
804 Otherwise, non-ASCII characters (that display as ASCII) may remain.
805 This is irrelevant unless the buffer is to be saved to a file."
806 :type 'boolean
807 :group 'woman-formatting)
808
809 (defcustom woman-emulation 'nroff
810 "*WoMan emulation, currently either nroff or troff. Default is nroff.
811 Troff emulation is experimental and largely untested.
812 \(Add groff later?)"
813 :type '(choice (const nroff) (const troff))
814 :group 'woman-formatting)
815
816 \f
817 ;; Faces:
818
819 (defgroup woman-faces nil
820 "Face options for browsing UNIX manual pages `wo (without) man'."
821 :tag "WoMan Faces"
822 :group 'woman
823 :group 'faces)
824
825 (defcustom woman-fontify
826 (or (and (fboundp 'display-color-p) (display-color-p))
827 (and (fboundp 'display-graphic-p) (display-graphic-p))
828 (x-display-color-p))
829 "*If non-nil then WoMan assumes that face support is available.
830 It defaults to a non-nil value if the display supports either colors
831 or different fonts."
832 :type 'boolean
833 :group 'woman-faces)
834
835 (defface woman-italic-face
836 `((t (:italic t :underline t :foreground "red")))
837 "Face for italic font in man pages.
838 Default: italic, underlined, foreground red.
839 This is overkill! Troff uses just italic\; Nroff uses just underline.
840 You should probably select either italic or underline as you prefer,
841 but not both, although italic and underline work together perfectly well!"
842 :group 'woman-faces)
843
844 (defface woman-bold-face
845 '((t (:bold t :foreground "blue")))
846 "Face for bold font in man pages.
847 Default: bold, foreground blue."
848 :group 'woman-faces)
849
850 (defface woman-unknown-face
851 '((t (:foreground "brown")))
852 "Face for all unknown fonts in man pages.
853 Default: foreground brown.
854 Brown is a good compromise: it is distinguishable from the default but
855 not enough so to make font errors look terrible. (Files that use
856 non-standard fonts seem to do so badly or in idiosyncratic ways!)"
857 :group 'woman-faces)
858
859 (defface woman-addition-face
860 '((t (:foreground "orange")))
861 "Face for all additions made by WoMan to man pages.
862 Default: foreground orange."
863 :group 'woman-faces)
864
865 (defun woman-colour-faces ()
866 "Set foreground colours of italic and bold faces to red and blue."
867 (interactive)
868 (set-face-foreground 'woman-italic-face "Red")
869 (set-face-foreground 'woman-bold-face "Blue"))
870
871 (defun woman-black-faces ()
872 "Set foreground colours of italic and bold faces both to black."
873 (interactive)
874 (set-face-foreground 'woman-italic-face "Black")
875 (set-face-foreground 'woman-bold-face "Black"))
876
877 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
878 ;; Experimental font support, initially only for MS-Windows.
879 (defconst woman-font-support
880 (eq window-system 'w32) ; Support X later!
881 "If non-nil then non-ASCII characters and symbol font supported.")
882
883 (defun woman-select-symbol-fonts (fonts)
884 "Select symbol fonts from a list FONTS of font name strings."
885 (let (symbol-fonts)
886 ;; With NTEmacs 20.5, the PATTERN option to `x-list-fonts' does
887 ;; not seem to work and fonts may be repeated, so ...
888 (while fonts
889 (and (string-match "-Symbol-" (car fonts))
890 (not (member (car fonts) symbol-fonts))
891 (setq symbol-fonts (cons (car fonts) symbol-fonts)))
892 (setq fonts (cdr fonts)))
893 symbol-fonts))
894
895 (when woman-font-support
896 (make-face 'woman-symbol-face)
897
898 ;; Set the symbol font only if `woman-use-symbol-font' is true, to
899 ;; avoid unnecessarily upsetting the line spacing in NTEmacs 20.5!
900
901 (defcustom woman-use-extended-font t
902 "*If non-nil then may use non-ASCII characters from the default font."
903 :type 'boolean
904 :group 'woman-faces)
905
906 (defcustom woman-use-symbol-font nil
907 "*If non-nil then may use the symbol font. It is off by default,
908 mainly because it may change the line spacing (in NTEmacs 20.5)."
909 :type 'boolean
910 :group 'woman-faces)
911
912 (defconst woman-symbol-font-list
913 (or (woman-select-symbol-fonts (x-list-fonts "*" 'default))
914 (woman-select-symbol-fonts (x-list-fonts "*")))
915 "Symbol font(s), preferably same size as default when WoMan was loaded.")
916
917 (defcustom woman-symbol-font (car woman-symbol-font-list)
918 "*A string describing the symbol font to use for special characters.
919 It should be compatible with, and the same size as, the default text font.
920 Under MS-Windows, the default is
921 \"-*-Symbol-normal-r-*-*-*-*-96-96-p-*-ms-symbol\"."
922 :type `(choice
923 ,@(mapcar (lambda (x) (list 'const x))
924 woman-symbol-font-list)
925 string)
926 :group 'woman-faces)
927
928 )
929
930 ;; For non windows-nt ...
931 (defvar woman-use-extended-font nil)
932 (defvar woman-use-symbol-font nil)
933 (defvar woman-symbol-font nil)
934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
935
936 \f
937 ;;; Internal variables:
938
939 (defconst woman-justify-list
940 '(left right center full)
941 "Justify styles for `fill-region-as-paragraph'.")
942 (defconst woman-adjust-left 0 ; == adjust off, noadjust
943 "Adjustment indicator `l' -- adjust left margin only.")
944 (defconst woman-adjust-right 1
945 "Adjustment indicator `r' -- adjust right margin only.")
946 (defconst woman-adjust-center 2
947 "Adjustment indicator `c' -- center.")
948 (defconst woman-adjust-both 3 ; default -- adj,both
949 "Adjustment indicator `b' or `n' -- adjust both margins.")
950
951 (defvar woman-adjust woman-adjust-both
952 "Current adjustment number-register value.")
953 (defvar woman-adjust-previous woman-adjust
954 "Previous adjustment number-register value.")
955 (defvar woman-justify
956 (nth woman-adjust woman-justify-list) ; use vector?
957 "Current justification style for `fill-region-as-paragraph'.")
958 (defvar woman-justify-previous woman-justify
959 "Previous justification style for `fill-region-as-paragraph'.")
960
961 (defvar woman-left-margin woman-default-indent
962 "Current left margin.")
963 (defvar woman-prevailing-indent woman-default-indent
964 "Current prevailing indent.")
965 (defvar woman-interparagraph-distance 1
966 "Interparagraph distance in lines.
967 Set by .PD; used by .SH, .SS, .TP, .LP, .PP, .P, .IP, .HP.")
968 (defvar woman-leave-blank-lines nil
969 "Blank lines to leave as vertical space.")
970 (defconst woman-tab-width 5
971 "Default tab width set by -man macros.")
972 (defvar woman-nofill nil
973 "Current fill mode: nil for filling.")
974 (defvar woman-RS-left-margin nil
975 "Left margin stack for nested use of `.RS/.RE'.")
976 (defvar woman-RS-prevailing-indent nil
977 "Prevailing indent stack for nested use of `.RS/.RE'.")
978 (defvar woman-nospace nil
979 "Current no-space mode: nil for normal spacing.
980 Set by `.ns' request; reset by any output or `.rs' request")
981
982 (defsubst woman-reset-nospace ()
983 "Set `woman-nospace' to nil."
984 (setq woman-nospace nil))
985
986 (defconst woman-mode-line-format
987 ;; This is essentially the Man-mode format with page numbers removed
988 ;; and line numbers added. (Online documents do not have pages, but
989 ;; they do have lines!)
990 '("-" mode-line-mule-info mode-line-modified
991 mode-line-frame-identification mode-line-buffer-identification
992 " " global-mode-string
993 " %[(WoMan" mode-line-process minor-mode-alist ")%]--"
994 (line-number-mode "L%l--")
995 (-3 . "%p") "-%-")
996 "Mode line format for WoMan buffer.")
997
998 (defconst woman-request-regexp "^[.'][ \t]*\\(\\S +\\) *"
999 ;; Was "^\\.[ \t]*\\([a-z0-9]+\\) *" but cvs.1 uses a macro named
1000 ;; "`" and CGI.man uses a macro named "''"!
1001 ;; CGI.man uses ' as control character in places -- it *should*
1002 ;; suppress breaks!
1003 ;; Could end with "\\( +\\|$\\)" instead of " *"
1004 "Regexp to match a ?roff request plus trailing white space.")
1005
1006 (defvar woman-imenu-done nil
1007 "Buffer-local: set to true if function `woman-imenu' has been called.")
1008 (make-variable-buffer-local 'woman-imenu-done)
1009
1010 ;; From imenu.el -- needed when reformatting a file in its old buffer.
1011 ;; The latest buffer index used to update the menu bar menu.
1012 (eval-when-compile
1013 (require 'imenu))
1014 (make-variable-buffer-local 'imenu--last-menubar-index-alist)
1015
1016 (defvar woman-buffer-alist nil
1017 "An alist representing WoMan buffers that are already decoded.
1018 Each element is of the form (FILE-NAME . BUFFER-NAME).")
1019
1020 (defvar woman-buffer-number 0
1021 "Ordinal number of current buffer entry in `woman-buffer-alist'.
1022 The ordinal numbers start from 0.")
1023
1024 (defvar woman-if-conditions-true '(?n ?e ?o)
1025 "List of one-character built-in condition names that are true.
1026 Should include ?e, ?o (page even/odd) and either ?n (nroff) or ?t (troff).
1027 Default is '(?n ?e ?o). Set via `woman-emulation'.")
1028
1029 \f
1030 ;;; Specialized utility functions:
1031
1032 ;;; Fast deletion without saving on the kill ring (cf. simple.el):
1033
1034 (defun woman-delete-line (&optional arg)
1035 "Delete rest of current line; if all blank then delete thru newline.
1036 With a numeric argument ARG, delete that many lines from point.
1037 Negative arguments delete lines backward."
1038 ;; This is a non-interactive version of kill-line in simple.el that
1039 ;; deletes instead of killing and assumes kill-whole-line is nil,
1040 ;; which is essential!
1041 (delete-region (point)
1042 (progn
1043 (if arg
1044 (forward-line arg)
1045 (if (eobp)
1046 (signal 'end-of-buffer nil))
1047 (if (looking-at "[ \t]*$")
1048 (forward-line 1)
1049 (end-of-line)))
1050 (point))))
1051
1052 (defsubst woman-delete-whole-line ()
1053 "Delete current line from beginning including eol."
1054 (beginning-of-line)
1055 (woman-delete-line 1))
1056
1057 (defsubst woman-delete-following-space ()
1058 "Delete all spaces and tabs FOLLOWING point (cf. `delete-horizontal-space')."
1059 ;; cf. delete-horizontal-space in simple.el:
1060 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
1061
1062 (defsubst woman-delete-match (subexp)
1063 "Delete subexpression SUBEXP of buffer text matched by last search."
1064 (delete-region (match-beginning subexp) (match-end subexp)))
1065
1066 ;; delete-char does not kill by default
1067 ;; delete-backward-char does not kill by default
1068 ;; delete-horizontal-space does not kill
1069 ;; delete-blank-lines does not kill
1070
1071 \f
1072 ;;; File handling:
1073
1074 (defvar woman-expanded-directory-path nil
1075 "Expanded directory list cache. Resetting to nil forces update.")
1076
1077 (defvar woman-topic-all-completions nil
1078 "Expanded topic alist cache. Resetting to nil forces update.")
1079
1080 ;;;###autoload
1081 (defun woman (&optional topic re-cache)
1082 "Browse UN*X man page for TOPIC (Without using external Man program).
1083 The major browsing mode used is essentially the standard Man mode.
1084 Choose the filename for the man page using completion, based on the
1085 topic selected from the directories specified in `woman-manpath' and
1086 `woman-path'. The directory expansions and topics are cached for
1087 speed, but a non-nil interactive argument forces the caches to be
1088 updated (e.g. to re-interpret the current directory).
1089
1090 Used non-interactively, arguments are optional: if given then TOPIC
1091 should be a topic string and non-nil RE-CACHE forces re-caching."
1092 (interactive (list nil current-prefix-arg))
1093 ;; The following test is for non-interactive calls via gnudoit etc.
1094 (if (or (interactive-p) (not (stringp topic)) (string-match "\\S " topic))
1095 (let ((file-name (woman-file-name topic re-cache)))
1096 (if file-name
1097 (woman-find-file file-name)
1098 (message
1099 "WoMan Error: No matching manual files found in search path")
1100 (ding))
1101 )
1102 (message "WoMan Error: No topic specified in non-interactive call")
1103 (ding))
1104 )
1105
1106 ;; Allow WoMan to be called via the standard Help menu:
1107 (define-key-after menu-bar-manuals-menu [woman]
1108 '(menu-item "Read Man Page (WoMan)..." woman
1109 :help "Man-page documentation Without Man") t)
1110
1111 (defvar woman-cached-data nil
1112 "A list of cached data used to determine cache validity.
1113 Set from the cache by `woman-read-directory-cache'.")
1114
1115 (defun woman-cached-data ()
1116 "Generate a list of data used to determine cache validity.
1117 Called both to generate and to check the cache!"
1118 ;; Must use substituted paths because values of env vars may change!
1119 (list woman-cache-level
1120 (mapcar 'substitute-in-file-name woman-manpath)
1121 (mapcar 'substitute-in-file-name woman-path)))
1122
1123 (defun woman-read-directory-cache ()
1124 "Load the directory and topic cache.
1125 It is loaded from the file named by the variable `woman-cache-filename'.
1126 Return t if the file exists, nil otherwise."
1127 (and
1128 woman-cache-filename
1129 (load woman-cache-filename t nil t) ; file exists
1130 (equal woman-cached-data (woman-cached-data)))) ; cache valid
1131
1132 (defun woman-write-directory-cache ()
1133 "Save the directory and topic cache.
1134 It is saved to the file named by the variable `woman-cache-filename'."
1135 (if woman-cache-filename
1136 (save-excursion ; to restore current buffer
1137 ;; Make a temporary buffer; name starting with space "hides" it.
1138 (let ((standard-output
1139 (set-buffer (generate-new-buffer "WoMan tmp buffer")))
1140 (backup-inhibited t))
1141 ;; (switch-to-buffer standard-output t) ; only for debugging
1142 (buffer-disable-undo standard-output)
1143 (princ
1144 ";;; WoMan directory and topic cache -- generated automatically\n")
1145 (print
1146 ;; For data validity check:
1147 `(setq woman-cached-data ',(woman-cached-data)))
1148 (print
1149 `(setq woman-expanded-directory-path
1150 ',woman-expanded-directory-path))
1151 (print
1152 `(setq woman-topic-all-completions
1153 ',woman-topic-all-completions))
1154 (write-file woman-cache-filename) ; write CURRENT buffer
1155 (kill-buffer standard-output)
1156 ))))
1157
1158 (defvar woman-topic-history nil "Topic read history.")
1159 (defvar woman-file-history nil "File-name read history.")
1160
1161 (defun woman-file-name (topic &optional re-cache)
1162 "Get the name of the UN*X man-page file describing a chosen TOPIC.
1163 When `woman' is called interactively, the word at point may be used as
1164 the topic or initial topic suggestion, subject to the value of the
1165 user option `woman-topic-at-point'. Return nil if no file can be found.
1166 Optional argument RE-CACHE, if non-nil, forces the cache to be re-read."
1167 ;; Handle the caching of the directory and topic lists:
1168 (if (and (not re-cache)
1169 (or
1170 (and woman-expanded-directory-path woman-topic-all-completions)
1171 (woman-read-directory-cache)))
1172 ()
1173 (message "Building list of manual directory expansions...")
1174 (setq woman-expanded-directory-path
1175 (woman-expand-directory-path woman-manpath woman-path))
1176 (message "Building completion list of all manual topics...")
1177 (setq woman-topic-all-completions
1178 (woman-topic-all-completions woman-expanded-directory-path))
1179 (woman-write-directory-cache))
1180 ;; There is a problem in that I want to offer case-insensitive
1181 ;; completions, but to return only a case-sensitive match. This
1182 ;; does not seem to work properly by default, so I re-do the
1183 ;; completion if necessary.
1184 (let (files)
1185 (or (stringp topic)
1186 (and (eq t
1187 (if (boundp 'woman-topic-at-point)
1188 woman-topic-at-point
1189 ;; Was let-bound when file loaded, so ...
1190 (setq woman-topic-at-point woman-topic-at-point-default)))
1191 (setq topic
1192 (current-word t)) ; only within or adjacent to word
1193 (assoc topic woman-topic-all-completions))
1194 (setq topic
1195 (completing-read
1196 "Manual entry: "
1197 woman-topic-all-completions nil 1
1198 ;; Initial input suggestion (was nil), with
1199 ;; cursor at left ready to kill suggestion!:
1200 (and woman-topic-at-point
1201 (cons (current-word) 0)) ; nearest word
1202 'woman-topic-history)))
1203 ;; Note that completing-read always returns a string.
1204 (if (= (length topic) 0)
1205 nil ; no topic, so no file!
1206 (cond
1207 ((setq files (woman-file-name-all-completions topic)))
1208 ;; Complete topic more carefully, i.e. use the completion
1209 ;; rather than the string entered by the user:
1210 ((setq files (all-completions topic woman-topic-all-completions))
1211 (while (/= (length topic) (length (car files)))
1212 (setq files (cdr files)))
1213 (setq files (woman-file-name-all-completions (car files)))))
1214 (cond
1215 ((null files) nil) ; no file found for topic.
1216 ((null (cdr files)) (car (car files))) ; only 1 file for topic.
1217 (t
1218 ;; Multiple files for topic, so must select 1.
1219 ;; Unread the command event (TAB = ?\t = 9) that runs the command
1220 ;; `minibuffer-complete' in order to automatically complete the
1221 ;; minibuffer contents as far as possible.
1222 (setq unread-command-events '(9)) ; and delete any type-ahead!
1223 (completing-read "Manual file: " files nil 1
1224 (try-completion "" files) 'woman-file-history)))
1225 )))
1226
1227 (defun woman-select (predicate list)
1228 "Select unique elements for which PREDICATE is true in LIST.
1229 \(Note that this function changes the value of LIST.)"
1230 ;; Intended to be fast by avoiding recursion and list copying.
1231 (while (and list
1232 (or
1233 (member (car list) (cdr list))
1234 (not (funcall predicate (car list)))))
1235 (setq list (cdr list)))
1236 (if list
1237 (let ((newlist list) cdr_list)
1238 (while (setq cdr_list (cdr list))
1239 (if (and
1240 (not (member (car cdr_list) (cdr cdr_list)))
1241 (funcall predicate (car cdr_list)))
1242 (setq list cdr_list)
1243 (setcdr list (cdr cdr_list)))
1244 )
1245 newlist)))
1246
1247 (defun woman-file-readable-p (dir)
1248 "Return t if DIR is readable, otherwise log a warning."
1249 (or (file-readable-p dir)
1250 (WoMan-warn "Ignoring unreadable `manpath' directory tree `%s'!" dir)))
1251
1252 (defun woman-directory-files (head dir)
1253 "Return a sorted list of files in directory HEAD matching regexp in DIR.
1254 Value is a sorted list of the absolute pathnames of all the files in
1255 directory HEAD, or the current directory if HEAD is nil, that match the
1256 regexp that is the final component of DIR. Log a warning if list is empty."
1257 (or (directory-files
1258 (or head (directory-file-name default-directory)) ; was "."
1259 t
1260 (file-name-nondirectory dir))
1261 (WoMan-warn "No directories match `woman-path' entry `%s'!" dir)))
1262
1263 (defun woman-file-accessible-directory-p (dir)
1264 "Return t if DIR is accessible, otherwise log a warning."
1265 (or (file-accessible-directory-p dir)
1266 (WoMan-warn "Ignoring inaccessible `man-page' directory `%s'!" dir)))
1267
1268 (defun woman-expand-directory-path (woman-manpath woman-path)
1269 "Expand the manual directories in WOMAN-MANPATH and WOMAN-PATH.
1270 WOMAN-MANPATH should be a list of general manual directories, while
1271 WOMAN-PATH should be a list of specific manual directory regexps.
1272 Ignore any paths that are unreadable or not directories."
1273 ;; Allow each path to be a single string or a list of strings:
1274 (if (not (listp woman-manpath)) (setq woman-manpath (list woman-manpath)))
1275 (if (not (listp woman-path)) (setq woman-path (list woman-path)))
1276 (let (dir head dirs)
1277 (while woman-manpath
1278 (setq dir (car woman-manpath)
1279 woman-manpath (cdr woman-manpath))
1280 (if (and dir (woman-file-readable-p dir))
1281 ;; NB: `parse-colon-path' creates null elements for
1282 ;; redundant (semi-)colons and trailing `/'s!
1283 ;; If does not actually matter here if dir ends with `/'.
1284 ;; Need regexp "man" here to avoid "cat?", `.', `..', etc.
1285 (setq dir (woman-canonicalize-dir dir)
1286 dirs (nconc dirs (directory-files
1287 dir t woman-manpath-man-regexp)))))
1288 (while woman-path
1289 (setq dir (car woman-path)
1290 woman-path (cdr woman-path))
1291 (if (or (null dir)
1292 (null (setq dir (woman-canonicalize-dir dir)
1293 head (file-name-directory dir)))
1294 (woman-file-readable-p head))
1295 (setq dirs
1296 (if dir
1297 (nconc dirs (woman-directory-files head dir))
1298 (cons (directory-file-name default-directory) dirs))
1299 ;; was "." -- at head of list for later filtering
1300 )))
1301 (woman-select 'woman-file-accessible-directory-p dirs)))
1302
1303 (defun woman-canonicalize-dir (dir)
1304 "Canonicalize the directory name DIR.
1305 Any UN*X-style environment variables are evaluated first."
1306 (setq dir (expand-file-name (substitute-in-file-name dir)))
1307 ;; A path that ends with / matches all directories in it,
1308 ;; including `.' and `..', so remove any trailing / !!!
1309 (if (string= (substring dir -1) "/")
1310 (setq dir (substring dir 0 -1)))
1311 (if (memq system-type '(windows-nt ms-dos)) ; what else?
1312 ;; Match capitalization used by `file-name-directory':
1313 (setq dir (concat (file-name-directory dir)
1314 (file-name-nondirectory dir))))
1315 dir)
1316
1317 (defsubst woman-not-member (dir path)
1318 "Return t if DIR is not a member of the list PATH, nil otherwise.
1319 If DIR is `.' it is first replaced by the current directory."
1320 (not (member dir path)))
1321
1322 (defun woman-topic-all-completions (path)
1323 "Return an alist of the man files in all man directories in the list PATH.
1324 The cdr of each alist element is the path-index / filename."
1325 ;; Support 3 levels of caching: each element of the alist `files'
1326 ;; will be a list of the first `woman-cache-level' elements of the
1327 ;; following list: (topic path-index filename). This alist `files'
1328 ;; is re-processed by `woman-topic-all-completions-merge'.
1329 (let (dir files (path-index 0)) ; indexing starts at zero
1330 (while path
1331 (setq dir (car path)
1332 path (cdr path))
1333 (if (woman-not-member dir path) ; use each directory only once!
1334 (setq files
1335 (nconc files
1336 (woman-topic-all-completions-1 dir path-index))))
1337 (setq path-index (1+ path-index)))
1338 ;; Uniquefy topics:
1339 (woman-topic-all-completions-merge files)))
1340
1341 (defun woman-topic-all-completions-1 (dir path-index)
1342 "Return an alist of the man topics in directory DIR with index PATH-INDEX.
1343 A topic is a filename sans type-related extensions.
1344 Support 3 levels of caching: each element of the alist will be a list
1345 of the first `woman-cache-level' elements from the following list:
1346 \(topic path-index filename)."
1347 ;; This function used to check that each file in the directory was
1348 ;; not itself a directory, but this is very slow and should be
1349 ;; unnecessary. So let us assume that `woman-file-regexp' will
1350 ;; filter out any directories, which probably should not be there
1351 ;; anyway, i.e. it is a user error!
1352 (mapcar
1353 (lambda (file)
1354 (cons
1355 (file-name-sans-extension
1356 (if (string-match woman-file-compression-regexp file)
1357 (file-name-sans-extension file)
1358 file))
1359 (if (> woman-cache-level 1)
1360 (cons
1361 path-index
1362 (if (> woman-cache-level 2)
1363 (cons file nil))))))
1364 (directory-files dir nil woman-file-regexp)))
1365
1366 (defun woman-topic-all-completions-merge (alist)
1367 "Merge the alist ALIST so that the keys are unique.
1368 Also make each path-info component into a list.
1369 \(Note that this function changes the value of ALIST.)"
1370 ;; Intended to be fast by avoiding recursion and list copying.
1371 (if (> woman-cache-level 1)
1372 (let ((newalist alist))
1373 (while newalist
1374 (let ((tail newalist) (topic (car (car newalist))))
1375 ;; Make the path-info into a list:
1376 (setcdr (car newalist) (list (cdr (car newalist))))
1377 (while tail
1378 (while (and tail (not (string= topic (car (car (cdr tail))))))
1379 (setq tail (cdr tail)))
1380 (if tail ; merge path-info into (car newalist)
1381 (let ((path-info (cdr (car (cdr tail)))))
1382 (if (member path-info (cdr (car newalist)))
1383 ()
1384 ;; Make the path-info into a list:
1385 (nconc (car newalist) (list path-info)))
1386 (setcdr tail (cdr (cdr tail))))
1387 ))
1388 (setq newalist (cdr newalist))))
1389 alist)
1390 ;; woman-cache-level = 1 => elements are single-element lists ...
1391 (while (and alist (member (car alist) (cdr alist)))
1392 (setq alist (cdr alist)))
1393 (if alist
1394 (let ((newalist alist) cdr_alist)
1395 (while (setq cdr_alist (cdr alist))
1396 (if (not (member (car cdr_alist) (cdr cdr_alist)))
1397 (setq alist cdr_alist)
1398 (setcdr alist (cdr cdr_alist)))
1399 )
1400 newalist))))
1401
1402 (defun woman-file-name-all-completions (topic)
1403 "Return an alist of the files in all man directories that match TOPIC."
1404 ;; Support 3 levels of caching: each element of
1405 ;; woman-topic-all-completions is a list of one of the forms:
1406 ;; (topic)
1407 ;; (topic (path-index) (path-index) ... )
1408 ;; (topic (path-index filename) (path-index filename) ... )
1409 ;; where the are no duplicates in the value lists.
1410 ;; Topic must match first `word' of filename, so ...
1411 (let ((topic-regexp
1412 (concat
1413 "\\`" (regexp-quote topic) ; first `word'
1414 "\\(\\..+\\)*" ; optional subsequent `words'
1415 woman-file-regexp)) ; extension
1416 (topics woman-topic-all-completions)
1417 (path woman-expanded-directory-path)
1418 dir files)
1419 (if (cdr (car topics))
1420 ;; Use cached path-info to locate files for each topic:
1421 (let ((path-info (cdr (assoc topic topics)))
1422 filename)
1423 (while path-info
1424 (setq dir (nth (car (car path-info)) path)
1425 filename (car (cdr (car path-info)))
1426 path-info (cdr path-info)
1427 files (nconc files
1428 ;; Find the actual file name:
1429 (if filename
1430 (list (concat dir "/" filename))
1431 (directory-files dir t topic-regexp)
1432 )))))
1433 ;; Search path for the files for each topic:
1434 (while path
1435 (setq dir (car path)
1436 path (cdr path))
1437 (if (woman-not-member dir path) ; use each directory only once!
1438 (setq files (nconc files
1439 (directory-files dir t topic-regexp))))
1440 ))
1441 (mapcar 'list files)
1442 ))
1443
1444 \f
1445 ;;; dired support
1446
1447 (defun woman-dired-define-key (key)
1448 "Bind the argument KEY to the command `woman-dired-find-file'."
1449 (define-key dired-mode-map key 'woman-dired-find-file))
1450
1451 (defsubst woman-dired-define-key-maybe (key)
1452 "If KEY is undefined in Dired, bind it to command `woman-dired-find-file'."
1453 (if (eq (lookup-key dired-mode-map key) 'undefined)
1454 (woman-dired-define-key key)))
1455
1456 (defun woman-dired-define-keys ()
1457 "Define dired keys to run WoMan according to `woman-dired-keys'."
1458 (if woman-dired-keys
1459 (if (listp woman-dired-keys)
1460 (mapcar 'woman-dired-define-key woman-dired-keys)
1461 (woman-dired-define-key-maybe "w")
1462 (woman-dired-define-key-maybe "W")))
1463 (define-key-after (lookup-key dired-mode-map [menu-bar immediate])
1464 [woman] '("Read Man Page (WoMan)" . woman-dired-find-file) 'view))
1465
1466 (if (featurep 'dired)
1467 (woman-dired-define-keys)
1468 (add-hook 'dired-mode-hook 'woman-dired-define-keys))
1469
1470 ;;;###autoload
1471 (defun woman-dired-find-file ()
1472 "In dired, run the WoMan man-page browser on this file."
1473 (interactive)
1474 ;; dired-get-filename is defined in dired.el
1475 (woman-find-file (dired-get-filename)))
1476
1477
1478 ;;; tar-mode support
1479
1480 (defun woman-tar-extract-file ()
1481 "In tar mode, run the WoMan man-page browser on this file."
1482 (interactive)
1483 (or (eq major-mode 'tar-mode)
1484 (error "`woman-tar-extract-file' can be used only in `tar-mode'"))
1485 (buffer-disable-undo)
1486 (let (global-font-lock-mode)
1487 (funcall (symbol-function 'tar-extract)) ; defined in tar-mode
1488 (let ((WoMan-current-file buffer-file-name)) ; used for message logging
1489 (rename-buffer
1490 (woman-make-bufname (file-name-nondirectory buffer-file-name)))
1491 (woman-process-buffer)
1492 (goto-char (point-min)))))
1493
1494 ;; There is currently no `tar-mode-hook' so use ...
1495 (eval-after-load "tar-mode"
1496 '(progn
1497 (define-key tar-mode-map "w" 'woman-tar-extract-file)
1498 (define-key-after (lookup-key tar-mode-map [menu-bar immediate])
1499 [woman] '("Read Man Page (WoMan)" . woman-tar-extract-file) 'view)))
1500
1501
1502 (defvar woman-last-file-name nil
1503 "The full pathname of the last file formatted by WoMan.")
1504
1505 (defun woman-reformat-last-file ()
1506 "Reformat last file, e.g. after changing fill column."
1507 (interactive)
1508 (if woman-last-file-name
1509 (woman-find-file woman-last-file-name t)
1510 (call-interactively 'woman-find-file)))
1511
1512 ;;;###autoload
1513 (defun woman-find-file (file-name &optional reformat)
1514 "Find, decode and browse a specific UN*X man-page source file FILE-NAME.
1515 Use existing buffer if possible; reformat only if prefix arg given.
1516 When called interactively, optional argument REFORMAT forces reformatting
1517 of an existing WoMan buffer formatted earlier.
1518 No external programs are used, except that `gunzip' will be used to
1519 decompress the file if appropriate. See the documentation for the
1520 `woman' command for further details."
1521 (interactive "fBrowse UN*X manual file: \nP")
1522 (setq woman-last-file-name
1523 (setq file-name (expand-file-name file-name))) ; to canonicalize
1524 (let ((alist-tail woman-buffer-alist) exists)
1525 (setq woman-buffer-number 0)
1526 (while (and alist-tail (not (string= file-name (car (car alist-tail)))))
1527 (setq alist-tail (cdr alist-tail)
1528 woman-buffer-number (1+ woman-buffer-number)))
1529 (or (and (setq exists
1530 (and alist-tail (WoMan-find-buffer))) ; buffer exists
1531 (not reformat))
1532 ;; Format new buffer or reformat current buffer:
1533 (let* ((bufname (file-name-nondirectory file-name))
1534 (case-fold-search t)
1535 (compressed
1536 (not (not (string-match woman-file-compression-regexp bufname)))))
1537 (if compressed
1538 (setq bufname (file-name-sans-extension bufname)))
1539 (setq bufname (if exists
1540 (buffer-name)
1541 (woman-make-bufname bufname)))
1542 (woman-really-find-file file-name compressed bufname)
1543 (or exists
1544 (setq woman-buffer-alist
1545 (cons (cons file-name bufname) woman-buffer-alist)
1546 woman-buffer-number 0))
1547 )))
1548 (Man-build-section-alist)
1549 (Man-build-references-alist)
1550 (goto-char (point-min)))
1551
1552 (defun woman-make-bufname (bufname)
1553 "Create an unambiguous buffer name from BUFNAME."
1554 (let ((dot (string-match "\\." bufname)))
1555 (if dot (setq bufname (concat
1556 (substring bufname (1+ dot)) " "
1557 (substring bufname 0 dot))))
1558 (generate-new-buffer-name ; ensure uniqueness
1559 (concat "*WoMan " bufname "*"))))
1560
1561 (defvar woman-frame nil
1562 "Dedicated frame used for displaying WoMan windows.")
1563
1564 (defun woman-really-find-file (filename compressed bufname)
1565 "Find, decompress, and decode a UN*X man page FILENAME.
1566 If COMPRESSED is non-nil, turn on auto-compression mode to decompress
1567 the file if necessary. Set buffer name BUFNAME and major mode.
1568 Do not call directly!"
1569 (let ((WoMan-current-file filename)) ; used for message logging
1570 (if woman-use-own-frame
1571 (select-frame
1572 (or (and (frame-live-p woman-frame) woman-frame)
1573 (setq woman-frame (make-frame)))))
1574 (switch-to-buffer (get-buffer-create bufname))
1575 (buffer-disable-undo)
1576 (setq buffer-read-only nil)
1577 (erase-buffer) ; NEEDED for reformat
1578 (woman-insert-file-contents filename compressed)
1579 ;; Set buffer's default directory to that of the file.
1580 (setq default-directory (file-name-directory filename))
1581 (set (make-local-variable 'backup-inhibited) t)
1582 (set-visited-file-name "")
1583 (woman-process-buffer)))
1584
1585 (defun woman-process-buffer ()
1586 "The second half of `woman-really-find-file'!"
1587 (interactive)
1588 ;; Check (crudely) that this really is likely to be in UN*X
1589 ;; man-page source format, assuming we are at point-min:
1590 (goto-char (point-min))
1591 (if (re-search-forward "^[.']" 1000 t)
1592 (woman-decode-buffer)
1593 (message
1594 "File appears to be pre-formatted -- using source file may be better.")
1595 (woman-man-buffer))
1596 (woman-mode))
1597
1598 (defun woman-man-buffer ()
1599 "Post-process an nroff-preformatted man buffer."
1600 ;; Kill all leading whitespace:
1601 (if (looking-at "\\s-+") (woman-delete-match 0))
1602 ;; Delete all page footer/header pairs:
1603 (re-search-forward ".*") ; match header
1604 ;; Footer conventionally has page number at right, so ...
1605 (let ((regex (concat
1606 "^.*[0-9]\n\\s-*" ; footer and following blank lines
1607 (regexp-quote (match-string 0)) ; header
1608 "\\s-*\n"))) ; following blank lines
1609 (while (re-search-forward regex nil 1) ; finish at eob
1610 (woman-delete-match 0)))
1611 ;; Delete last text line (footer) and all following blank lines:
1612 (re-search-backward "\\S-")
1613 (beginning-of-line)
1614 (if (looking-at ".*[0-9]$")
1615 (delete-region (point) (point-max)))
1616
1617 ;; Squeeze multiple blank lines:
1618 (goto-char (point-min))
1619 (while (re-search-forward "^[ \t]*\n\\([ \t]*\n\\)+" nil t)
1620 (replace-match "\n" t t))
1621
1622 ;; Interpret overprinting to indicate bold face:
1623 (goto-char (point-min))
1624 (while (re-search-forward "\\(.\\)\\(\\(\b\\1\\)+\\)" nil t)
1625 (woman-delete-match 2)
1626 (woman-set-face (1- (point)) (point) 'woman-bold-face))
1627
1628 ;; Interpret underlining to indicate italic face:
1629 ;; (Must be AFTER emboldening to interpret bold _ correctly!)
1630 (goto-char (point-min))
1631 (while (search-forward "_\b" nil t)
1632 (delete-char -2)
1633 (woman-set-face (point) (1+ (point)) 'woman-italic-face))
1634
1635 ;; Leave any other uninterpreted ^H's in the buffer for now! (They
1636 ;; might indicate composite special characters, which could be
1637 ;; interpreted if I knew what to expect.)
1638
1639 ;; Optionally embolden section and subsection headings
1640 ;; (cf. `woman-imenu-generic-expression'):
1641 (cond
1642 (woman-bold-headings
1643 (goto-char (point-min))
1644 (forward-line)
1645 (while (re-search-forward "^\\( \\)?\\([A-Z].*\\)" nil t)
1646 (woman-set-face (match-beginning 2) (match-end 2) 'woman-bold-face))))
1647 )
1648
1649 (defun woman-insert-file-contents (filename compressed)
1650 "Insert file FILENAME into the current buffer.
1651 If COMPRESSED is t, or is non-nil and the filename implies compression,
1652 then turn on auto-compression mode to decompress the file.
1653 Leave point at end of new text. Return length of inserted text."
1654 ;; Leaves point at end of inserted text in GNU Emacs 20.3, but at
1655 ;; start in 19.34!
1656 (save-excursion
1657 (let ((case-fold-search t))
1658 ;; Co-operate with auto-compression mode:
1659 (if (and compressed
1660 (or (eq compressed t)
1661 (string-match woman-file-compression-regexp filename))
1662 ;; (not auto-compression-mode)
1663 (not (rassq 'jka-compr-handler file-name-handler-alist)) )
1664 ;; (error "Compressed file requires Auto File Decompression turned on")
1665 (auto-compression-mode 1))
1666 (nth 1
1667 (condition-case ()
1668 (insert-file-contents filename nil)
1669 (file-error
1670 ;; Run find-file-not-found-hooks until one returns non-nil.
1671 ;; (run-hook-with-args-until-success 'find-file-not-found-hooks)
1672 (insert "\n***** File " filename " not found! *****\n\n")
1673 )))
1674 )))
1675
1676 \f
1677 ;;; Major mode (Man) interface:
1678
1679 (defvar woman-mode-map nil "Keymap for woman mode.")
1680
1681 (if woman-mode-map
1682 ()
1683 ;; Set up the keymap, mostly inherited from Man-mode-map:
1684 (setq woman-mode-map (make-sparse-keymap))
1685 (set-keymap-parent woman-mode-map Man-mode-map)
1686 ;; Above two lines were
1687 ;; (setq woman-mode-map (cons 'keymap Man-mode-map))
1688 (define-key woman-mode-map "R" 'woman-reformat-last-file)
1689 (define-key woman-mode-map "w" 'woman)
1690 (define-key woman-mode-map "\en" 'WoMan-next-manpage)
1691 (define-key woman-mode-map "\ep" 'WoMan-previous-manpage)
1692 (define-key woman-mode-map [mouse-2] 'woman-mouse-2)
1693 (define-key woman-mode-map [M-mouse-2] 'woman-mouse-2))
1694
1695 (defun woman-mouse-2 (event)
1696 "Run WoMan with word under mouse as topic.
1697 Require it to be mouse-highlighted unless Meta key used.
1698 Argument EVENT is the invoking mouse event."
1699 (interactive "e") ; mouse event
1700 (let ((pos (cadr (cadr event)))) ; extract buffer position
1701 (when (or (eq (car event) 'M-mouse-2)
1702 (get-text-property pos 'mouse-face))
1703 (goto-char pos)
1704 (woman (current-word t)))))
1705
1706 ;; WoMan menu bar and pop-up menu:
1707 (easy-menu-define ; (SYMBOL MAPS DOC MENU)
1708 woman-menu
1709 woman-mode-map
1710 "WoMan Menu"
1711 `("WoMan"
1712 ["WoMan..." woman t] ; [NAME CALLBACK ENABLE]
1713 "--"
1714 ["Next Section" Man-next-section t]
1715 ["Previous Section" Man-previous-section t]
1716 ["Goto Section..." Man-goto-section t]
1717 ["Goto See-Also Section" Man-goto-see-also-section t]
1718 ["Follow Reference..." Man-follow-manual-reference t]
1719 "--"
1720 ["Previous WoMan Buffer" WoMan-previous-manpage t]
1721 ["Next WoMan Buffer" WoMan-next-manpage t]
1722 ["Bury WoMan Buffer" Man-quit t]
1723 ["Kill WoMan Buffer" Man-kill t]
1724 "--"
1725 ;; ["Toggle Fill Frame Width" woman-toggle-fill-frame t]
1726 ["Use Full Frame Width" woman-toggle-fill-frame
1727 :active t :style toggle :selected woman-fill-frame]
1728 ["Reformat Last Man Page" woman-reformat-last-file t]
1729 ["Use Coloured Main Faces" woman-colour-faces t]
1730 ["Use Black Main Faces" woman-black-faces t]
1731 ["Make Contents Menu" (woman-imenu t) (not woman-imenu-done)]
1732 "--"
1733 ["Describe (Wo)Man Mode" describe-mode t]
1734 ["Mini Help" woman-mini-help t]
1735 ,@(if (fboundp 'customize-group)
1736 '(["Customize..." (customize-group 'woman) t]))
1737 ["Show Version" (message "WoMan %s" woman-version) t]
1738 "--"
1739 ("Advanced"
1740 ["View Source" (view-file woman-last-file-name) woman-last-file-name]
1741 ["Show Log" (switch-to-buffer-other-window "*WoMan-Log*" t) t]
1742 ["Extended Font" woman-toggle-use-extended-font
1743 :included woman-font-support
1744 :active t :style toggle :selected woman-use-extended-font]
1745 ["Symbol Font" woman-toggle-use-symbol-font
1746 :included woman-font-support
1747 :active t :style toggle :selected woman-use-symbol-font]
1748 ["Font Map" woman-display-extended-fonts
1749 :included woman-font-support
1750 :active woman-use-symbol-font]
1751 "--"
1752 "Emulation"
1753 ["nroff" (woman-reset-emulation 'nroff)
1754 :active t :style radio :selected (eq woman-emulation 'nroff)]
1755 ["troff" (woman-reset-emulation 'troff)
1756 :active t :style radio :selected (eq woman-emulation 'troff)]
1757 )
1758 ))
1759
1760 (defun woman-toggle-use-extended-font ()
1761 "Toggle `woman-use-extended-font' and reformat, for menu use."
1762 (interactive)
1763 (setq woman-use-extended-font (not woman-use-extended-font))
1764 (woman-reformat-last-file))
1765
1766 (defun woman-toggle-use-symbol-font ()
1767 "Toggle `woman-use-symbol-font' and reformat, for menu use."
1768 (interactive)
1769 (setq woman-use-symbol-font (not woman-use-symbol-font))
1770 (woman-reformat-last-file))
1771
1772 (defun woman-reset-emulation (value)
1773 "Reset `woman-emulation' to VALUE and reformat, for menu use."
1774 (interactive)
1775 (setq woman-emulation value)
1776 (woman-reformat-last-file))
1777
1778 (defun woman-mode ()
1779 "Turn on (most of) Man mode to browse a buffer formatted by WoMan.
1780 WoMan is an ELisp emulation of much of the functionality of the Emacs
1781 `man' command running the standard UN*X man and ?roff programs.
1782 WoMan author: F.J.Wright@Maths.QMW.ac.uk
1783 WoMan version: see `woman-version'.
1784 See `Man-mode' for additional details."
1785 (let ((Man-build-page-list (symbol-function 'Man-build-page-list))
1786 (Man-strip-page-headers (symbol-function 'Man-strip-page-headers))
1787 (Man-unindent (symbol-function 'Man-unindent))
1788 (Man-goto-page (symbol-function 'Man-goto-page)))
1789 ;; Prevent inappropriate operations:
1790 (fset 'Man-build-page-list 'ignore)
1791 (fset 'Man-strip-page-headers 'ignore)
1792 (fset 'Man-unindent 'ignore)
1793 (fset 'Man-goto-page 'ignore)
1794 (unwind-protect
1795 (progn
1796 (set (make-local-variable 'Man-mode-map) woman-mode-map)
1797 ;; Install Man mode:
1798 (Man-mode)
1799 ;; Reset inappropriate definitions:
1800 (setq mode-line-format woman-mode-line-format)
1801 (put 'Man-mode 'mode-class 'special))
1802 ;; Restore the status quo:
1803 (fset 'Man-build-page-list Man-build-page-list)
1804 (fset 'Man-strip-page-headers Man-strip-page-headers)
1805 (fset 'Man-unindent Man-unindent)
1806 (fset 'Man-goto-page Man-goto-page)
1807 )
1808 ;; Imenu support:
1809 (set (make-local-variable 'imenu-generic-expression)
1810 ;; `make-local-variable' in case imenu not yet loaded!
1811 woman-imenu-generic-expression)
1812 (set (make-local-variable 'imenu-space-replacement) " ")
1813 ;; For reformat ...
1814 ;; necessary when reformatting a file in its old buffer:
1815 (setq imenu--last-menubar-index-alist nil)
1816 ;; necessary to avoid re-installing the same imenu:
1817 (setq woman-imenu-done nil)
1818 (if woman-imenu (woman-imenu))
1819 (setq buffer-read-only nil)
1820 (WoMan-highlight-references)
1821 (setq buffer-read-only t)
1822 (set-buffer-modified-p nil)))
1823
1824 (defun woman-imenu (&optional redraw)
1825 "Add a \"Contents\" menu to the menubar.
1826 Optional argument REDRAW, if non-nil, forces mode line to be updated."
1827 (interactive)
1828 (if woman-imenu-done
1829 ;; This is PRIMARILY to avoid a bug in imenu-add-to-menubar that
1830 ;; causes it to corrupt the menu bar if it is run more than once
1831 ;; in the same buffer.
1832 ()
1833 (setq woman-imenu-done t)
1834 (imenu-add-to-menubar woman-imenu-title)
1835 (if redraw (force-mode-line-update))))
1836
1837 (defun woman-toggle-fill-frame ()
1838 "Toggle formatting to fill (most of) the width of the current frame."
1839 (interactive)
1840 (setq woman-fill-frame (not woman-fill-frame))
1841 (message "Woman fill column set to %s."
1842 (if woman-fill-frame "frame width" woman-fill-column)
1843 ))
1844
1845 (defun woman-mini-help ()
1846 "Display WoMan commands and user options in an `apropos' buffer."
1847 ;; Based on apropos-command in apropos.el
1848 (interactive)
1849 (require 'apropos)
1850 (let ((message
1851 (let ((standard-output (get-buffer-create "*Apropos*")))
1852 (print-help-return-message 'identity))))
1853 (setq apropos-accumulator
1854 (apropos-internal "woman"
1855 (lambda (symbol)
1856 (or (commandp symbol)
1857 (user-variable-p symbol)))))
1858 ;; Filter out any inhibited symbols:
1859 (let ((tem apropos-accumulator))
1860 (while tem
1861 (if (get (car tem) 'apropos-inhibit)
1862 (setq apropos-accumulator (delq (car tem) apropos-accumulator)))
1863 (setq tem (cdr tem))))
1864 ;; Find documentation strings:
1865 (let ((p apropos-accumulator)
1866 doc symbol)
1867 (while p
1868 (setcar p (list ; must have 3 elements:
1869 (setq symbol (car p)) ; 1. name
1870 (if (functionp symbol) ; 2. command doc
1871 (if (setq doc (documentation symbol t))
1872 (substring doc 0 (string-match "\n" doc))
1873 "(not documented)"))
1874 (if (user-variable-p symbol) ; 3. variable doc
1875 (if (setq doc (documentation-property
1876 symbol 'variable-documentation t))
1877 (substring doc 0 (string-match "\n" doc))))))
1878 (setq p (cdr p))))
1879 ;; Output the result:
1880 (and (apropos-print t nil)
1881 message
1882 (message message))))
1883
1884
1885 (defun WoMan-getpage-in-background (topic)
1886 "Use TOPIC to start WoMan from `Man-follow-manual-reference'."
1887 ;; topic is a string, generally of the form "section topic"
1888 (let ((s (string-match " " topic)))
1889 (if s (setq topic (substring topic (1+ s))))
1890 (woman topic)))
1891
1892 (defvar WoMan-Man-start-time nil
1893 "Used to record formatting time used by the `man' command.")
1894
1895 (defadvice Man-getpage-in-background
1896 (around Man-getpage-in-background-advice (topic) activate)
1897 "Use WoMan unless invoked outside a WoMan buffer or invoked explicitly.
1898 Otherwise use Man and record start of formatting time."
1899 (if (and (eq mode-line-format woman-mode-line-format)
1900 (not (eq (caar command-history) 'man)))
1901 (WoMan-getpage-in-background topic)
1902 ;; Initiates man processing
1903 (setq WoMan-Man-start-time (current-time))
1904 ad-do-it))
1905
1906 (defadvice Man-bgproc-sentinel
1907 (after Man-bgproc-sentinel-advice activate)
1908 ;; Terminates man processing
1909 "Report formatting time."
1910 (let* ((time (current-time))
1911 (time (+ (* (- (car time) (car WoMan-Man-start-time)) 65536)
1912 (- (cadr time) (cadr WoMan-Man-start-time)))))
1913 (message "Man formatting done in %d seconds" time)))
1914
1915 (defun WoMan-highlight-references ()
1916 "Highlight the references (in the SEE ALSO section) on mouse-over."
1917 ;; Based on `Man-build-references-alist' in `man'.
1918 (when (Man-find-section Man-see-also-regexp)
1919 (forward-line 1)
1920 (let ((end (save-excursion
1921 (Man-next-section 1)
1922 (point))))
1923 (back-to-indentation)
1924 (while (re-search-forward Man-reference-regexp end t)
1925 ;; Highlight reference when mouse is over it.
1926 ;; (NB: WoMan does not hyphenate!)
1927 ;; [See (elisp)Clickable Text]
1928 (put-text-property (match-beginning 1) (match-end 1)
1929 'mouse-face 'highlight)
1930 ))))
1931
1932 \f
1933 ;;; Buffer handling:
1934
1935 (defun WoMan-previous-manpage ()
1936 "Find the previous WoMan buffer."
1937 ;; Assumes currently in a WoMan buffer!
1938 (interactive)
1939 (WoMan-find-buffer) ; find current existing buffer
1940 (if (null (cdr woman-buffer-alist))
1941 (error "No previous WoMan buffer"))
1942 (if (>= (setq woman-buffer-number (1+ woman-buffer-number))
1943 (length woman-buffer-alist))
1944 (setq woman-buffer-number 0))
1945 (if (WoMan-find-buffer)
1946 ()
1947 (if (< (setq woman-buffer-number (1- woman-buffer-number)) 0)
1948 (setq woman-buffer-number (1- (length woman-buffer-alist))))
1949 (WoMan-previous-manpage)))
1950
1951 (defun WoMan-next-manpage ()
1952 "Find the next WoMan buffer."
1953 ;; Assumes currently in a WoMan buffer!
1954 (interactive)
1955 (WoMan-find-buffer) ; find current existing buffer
1956 (if (null (cdr woman-buffer-alist))
1957 (error "No next WoMan buffer"))
1958 (if (< (setq woman-buffer-number (1- woman-buffer-number)) 0)
1959 (setq woman-buffer-number (1- (length woman-buffer-alist))))
1960 (if (WoMan-find-buffer)
1961 ()
1962 (WoMan-next-manpage)))
1963
1964 (defun WoMan-find-buffer ()
1965 "Switch to buffer corresponding to `woman-buffer-number' and return it.
1966 If such a buffer does not exist then remove its association from the
1967 alist in `woman-buffer-alist' and return nil."
1968 (if (zerop woman-buffer-number)
1969 (let ((buffer (get-buffer (cdr (car woman-buffer-alist)))))
1970 (if buffer
1971 (switch-to-buffer buffer)
1972 ;; Delete alist element:
1973 (setq woman-buffer-alist (cdr woman-buffer-alist))
1974 nil))
1975 (let* ((prev-ptr (nthcdr (1- woman-buffer-number) woman-buffer-alist))
1976 (buffer (get-buffer (cdr (car (cdr prev-ptr))))))
1977 (if buffer
1978 (switch-to-buffer buffer)
1979 ;; Delete alist element:
1980 (setcdr prev-ptr (cdr (cdr prev-ptr)))
1981 (if (>= woman-buffer-number (length woman-buffer-alist))
1982 (setq woman-buffer-number 0))
1983 nil)
1984 )))
1985
1986 \f
1987 ;;; Syntax and display tables:
1988
1989 (defconst woman-escaped-escape-char ?\1c
1990 ;; An arbitrary unused control character
1991 "Internal character representation of escaped escape characters.")
1992 (defconst woman-escaped-escape-string
1993 (char-to-string woman-escaped-escape-char)
1994 "Internal string representation of escaped escape characters.")
1995
1996 (defconst woman-unpadded-space-char ?\1d
1997 ;; An arbitrary unused control character
1998 "Internal character representation of unpadded space characters.")
1999 (defconst woman-unpadded-space-string
2000 (char-to-string woman-unpadded-space-char)
2001 "Internal string representation of unpadded space characters.")
2002
2003 (defvar woman-syntax-table nil
2004 "Syntax table to support special characters used internally by WoMan.")
2005
2006 (if woman-syntax-table
2007 ()
2008 (setq woman-syntax-table (make-syntax-table))
2009 ;; The following internal chars must NOT have whitespace syntax:
2010 (modify-syntax-entry woman-unpadded-space-char "." woman-syntax-table)
2011 (modify-syntax-entry woman-escaped-escape-char "." woman-syntax-table)
2012 )
2013
2014 (defun woman-set-buffer-display-table ()
2015 "Set up a display table for a WoMan buffer.
2016 This display table is used for displaying internal special characters, but
2017 does not interfere with any existing display table, e.g. for displaying
2018 European characters."
2019 (setq buffer-display-table
2020 ;; The following test appears to be necessary on some
2021 ;; non-Windows platforms, e.g. Solaris 2.6 when running on a
2022 ;; tty. Thanks to T. V. Raman <raman@Adobe.COM>.
2023 ;; The MS-DOS terminal also sets standard-display-table to
2024 ;; a non-nil value.
2025 (if standard-display-table ; default is nil !!!
2026 (copy-sequence standard-display-table)
2027 (make-display-table)))
2028 ;; Display the following internal chars correctly:
2029 (aset buffer-display-table woman-unpadded-space-char [?\ ])
2030 (aset buffer-display-table woman-escaped-escape-char [?\\]))
2031
2032 \f
2033 ;;; The main decoding driver:
2034
2035 (defvar font-lock-mode) ; for the compiler
2036
2037 (defun woman-decode-buffer ()
2038 "Decode a buffer in UN*X man-page source format.
2039 No external programs are used."
2040 (interactive) ; mainly for testing
2041 (WoMan-log-begin)
2042 (run-hooks 'woman-pre-format-hook)
2043 (and (boundp 'font-lock-mode) font-lock-mode (font-lock-mode -1))
2044 ;; (fundamental-mode)
2045 (let ((start-time (current-time)) ; (HIGH LOW MICROSEC)
2046 time) ; HIGH * 2**16 + LOW seconds
2047 (message "WoMan formatting buffer...")
2048 ; (goto-char (point-min))
2049 ; (cond
2050 ; ((re-search-forward "^\\.[ \t]*TH" nil t) ; wrong format if not found?
2051 ; (beginning-of-line)
2052 ; (delete-region (point-min) (point))) ; potentially dangerous!
2053 ; (t (message "WARNING: .TH request not found -- not man-page format?")))
2054 (woman-decode-region (point-min) (point-max))
2055 (setq time (current-time)
2056 time (+ (* (- (car time) (car start-time)) 65536)
2057 (- (cadr time) (cadr start-time))))
2058 (message "WoMan formatting buffer...done in %d seconds" time)
2059 (WoMan-log-end time))
2060 (run-hooks 'woman-post-format-hook))
2061
2062 (defvar woman-string-alist ; rebound in woman-decode-region
2063 '(("S" . "") ("R" . "(Reg.)") ("Tm" . "(TM)")
2064 ("lq" . "\"") ("rq" . "\"")
2065 ("''" . "\"") ; needed for gcc.1
2066 (".T" . "") ; output device from -T option?
2067 )
2068 "Alist of strings predefined in the -man macro package `tmac.an'.")
2069
2070 (defvar woman-negative-vertical-space nil ; rebound in woman-decode-region
2071 "Set to t if .sp N with N < 0 encountered.")
2072
2073 (defun woman-pre-process-region (from to)
2074 "Pre-process escapes and comments in the region of text between FROM and TO.
2075 To be called on original buffer and any .so insertions."
2076 ;; Hide escaped escapes \\ and printable escapes \e very early
2077 ;; (to be re-instated as just \ very late!):
2078 (goto-char from)
2079 ;; .eo turns off escape character processing
2080 (while (re-search-forward "\\(\\\\[\\e]\\)\\|^\\.eo" to t) ; \\
2081 (if (match-string 1)
2082 (replace-match woman-escaped-escape-string t t)
2083 (woman-delete-whole-line)
2084 ;; .ec turns on escape character processing (and sets the
2085 ;; escape character to its argument, if any, which I'm ignoring
2086 ;; for now!)
2087 (while (and (re-search-forward "\\(\\\\\\)\\|^\\.ec" to t) ; \
2088 (match-string 1))
2089 (replace-match woman-escaped-escape-string t t))
2090 ;; ***** Need test for .ec arg and warning here! *****
2091 (woman-delete-whole-line)))
2092
2093 ;; Delete comments .\"<anything>, \"<anything>, pre-processor
2094 ;; directives '\"<anything> (should give warning?) and null
2095 ;; requests. (However, should null . requests cause a break?)
2096 (goto-char from)
2097 (while (re-search-forward "^[.'][ \t]*\\(\\\\\".*\\)?\n\\|\\\\\".*" to t)
2098 (woman-delete-match 0))
2099 )
2100
2101 (defun woman-non-underline-faces ()
2102 "Prepare non-underlined versions of underlined faces."
2103 (let ((face-list (face-list)))
2104 (while face-list
2105 (let* ((face (car face-list))
2106 (face-name (symbol-name face)))
2107 (if (and (string-match "\\`woman-" face-name)
2108 (face-underline-p face))
2109 (let ((face-no-ul (intern (concat face-name "-no-ul"))))
2110 (copy-face face face-no-ul)
2111 (set-face-underline-p face-no-ul nil))))
2112 (setq face-list (cdr face-list)))))
2113
2114 (defun woman-decode-region (from to)
2115 "Decode the region between FROM and TO in UN*X man-page source format."
2116 ;; Suitable for use in format-alist.
2117 ;; But this requires care to control major mode implied font locking.
2118 ;; Must return the new end of file. See format.el for details.
2119 ;; NB: The `to' argument is bogus: it is not currently used, and if
2120 ;; it were it would need to be a marker rather than a position!
2121 ;; First force the correct environment:
2122 (let ((case-fold-search nil) ; This is necessary!
2123 (woman-string-alist woman-string-alist)
2124 (woman-fill-column woman-fill-column)
2125 woman-negative-vertical-space)
2126 (setq woman-left-margin woman-default-indent
2127 woman-prevailing-indent woman-default-indent
2128 woman-interparagraph-distance 1
2129 woman-leave-blank-lines nil
2130 woman-RS-left-margin nil
2131 woman-RS-prevailing-indent nil
2132 woman-adjust woman-adjust-both
2133 woman-justify (nth woman-adjust woman-justify-list)
2134 woman-nofill nil)
2135
2136 (setq woman-if-conditions-true
2137 (cons (string-to-char (symbol-name woman-emulation)) '(?e ?o)))
2138
2139 ;; Prepare non-underlined versions of underlined faces:
2140 (woman-non-underline-faces)
2141 ;; Set font of `woman-symbol-face' to `woman-symbol-font' if
2142 ;; `woman-symbol-font' is well defined.
2143 (and woman-use-symbol-font
2144 (stringp woman-symbol-font)
2145 (set-face-font 'woman-symbol-face woman-symbol-font
2146 (and (frame-live-p woman-frame) woman-frame)))
2147
2148 ;; Set syntax and display tables:
2149 (set-syntax-table woman-syntax-table)
2150 (woman-set-buffer-display-table)
2151
2152 ;; Based loosely on a suggestion by Theodore Jump:
2153 (if (or woman-fill-frame
2154 (not (and (integerp woman-fill-column) (> woman-fill-column 0))))
2155 (setq woman-fill-column (- (frame-width) woman-default-indent)))
2156
2157 (woman-pre-process-region from nil)
2158 ;; Process ignore requests, macro definitions,
2159 ;; conditionals and switch source requests:
2160 (woman0-roff-buffer from)
2161
2162 ;; Process \k escapes BEFORE changing tab width (?):
2163 (goto-char from)
2164 (woman-mark-horizonal-position)
2165
2166 ;; Set buffer-local variables:
2167 (setq fill-column woman-fill-column
2168 tab-width woman-tab-width)
2169
2170 ;; Hide unpaddable and digit-width spaces \(space) and \0:
2171 (goto-char from)
2172 (while (re-search-forward "\\\\[ 0]" nil t)
2173 (replace-match woman-unpadded-space-string t t))
2174
2175 ;; Discard optional hyphen \%; concealed newlines \<newline>;
2176 ;; point-size change function \sN,\s+N, \s-N:
2177 (goto-char from)
2178 (while (re-search-forward "\\\\\\([%\n]\\|s[-+]?[0-9]+\\)" nil t)
2179 (woman-delete-match 0))
2180
2181 ;; BEWARE: THIS SHOULD PROBABLY ALL BE DONE MUCH LATER!!!!!
2182 ;; Process trivial escapes \-, \`, \.
2183 ;; (\' must be done after tab processing!):
2184 (goto-char from)
2185 (while (re-search-forward "\\\\\\([-`.]\\)" nil t)
2186 (replace-match "\\1"))
2187 ;; NB: Must keep ALL zero-width characters \&, \|, and \^ until
2188 ;; ALL requests processed!
2189
2190 ;; Process no-break requests and macros (including font-change macros):
2191 (goto-char from)
2192 (woman1-roff-buffer)
2193
2194 ;; Process strings and special character escapes \(xx:
2195 ;; (Must do this BEFORE fontifying!)
2196 (goto-char from)
2197 (woman-strings)
2198 ;; Special chars moved after translation in
2199 ;; `woman2-process-escapes' (for pic.1):
2200 ; (goto-char from)
2201 ; (woman-special-characters)
2202
2203 ;; Process standard font-change requests and escapes:
2204 (goto-char from)
2205 (woman-change-fonts)
2206
2207 ;; 1/2 em vertical motion \d, \u and general local vertical motion
2208 ;; \v'+/-N' simulated using TeX ^ and _ symbols for now.
2209 (goto-char from)
2210 (let ((first t)) ; assume no nesting!
2211 (while (re-search-forward "\\\\\\([du]\\|v'[^']*'\\)" nil t)
2212 (let* ((esc (match-string 1))
2213 (repl (if (or (= (aref esc 0) ?u)
2214 (and (>= (length esc) 2) (= (aref esc 2) ?-)))
2215 "^" "_")))
2216 (cond (first
2217 (replace-match repl nil t)
2218 (put-text-property (1- (point)) (point)
2219 'face 'woman-addition-face)
2220 (WoMan-warn
2221 "Initial vertical motion escape \\%s simulated" esc)
2222 (WoMan-log
2223 " by TeX `%s' in woman-addition-face!" repl))
2224 (t
2225 (woman-delete-match 0)
2226 (WoMan-warn
2227 "Terminal vertical motion escape \\%s ignored!" esc)))
2228 (setq first (not first))
2229 )))
2230
2231 ; ;; \h'+/-N' local horizontal motion.
2232 ; ;; N may include width escape \w'...'
2233 ; ;; Implement arbitrary forward motion and non-overlapping backward
2234 ; ;; motion.
2235 ; (goto-char from)
2236 ; (while (re-search-forward
2237 ; ;; Delimiter can be a special char escape sequence \(.. or
2238 ; ;; a single normal char (usually '):
2239 ; "\\\\h\\(\\\\(..\\|.\\)\\(|\\)?"
2240 ; nil t)
2241 ; (let ((from (match-beginning 0))
2242 ; (delim (regexp-quote (match-string 1)))
2243 ; (absolute (match-string 2)) ; absolute position?
2244 ; (N (woman-parse-numeric-arg)) ; distance
2245 ; to
2246 ; msg) ; for warning
2247 ; (if (not (looking-at delim))
2248 ; ;; Warn but leave escape in buffer unprocessed:
2249 ; (WoMan-warn
2250 ; "Local horizontal motion (%s) delimiter error!"
2251 ; (buffer-substring from (1+ (point)))) ; point at end of arg
2252 ; (setq to (match-end 0)
2253 ; ;; For possible warning -- save before deleting:
2254 ; msg (buffer-substring from to))
2255 ; (delete-region from to)
2256 ; (if absolute ; make relative
2257 ; (setq N (- N (current-column))))
2258 ; (if (>= N 0)
2259 ; ;; Move forward by inserting hard spaces:
2260 ; (insert-char woman-unpadded-space-char N)
2261 ; ;; Move backwards by deleting space,
2262 ; ;; first backwards then forwards:
2263 ; (while (and
2264 ; (<= (setq N (1+ N)) 0)
2265 ; (cond ((memq (preceding-char) '(?\ ?\t))
2266 ; (delete-backward-char 1) t)
2267 ; ((memq (following-char) '(?\ ?\t))
2268 ; (delete-char 1) t)
2269 ; (t nil))))
2270 ; (if (<= N 0)
2271 ; (WoMan-warn
2272 ; "Negative horizontal motion (%s) would overwrite!" msg))))
2273 ; ))
2274
2275 ;; Process formatting macros
2276 (goto-char from)
2277 (woman2-roff-buffer)
2278
2279 ;; Go back and process negative vertical space if necessary:
2280 (if woman-negative-vertical-space
2281 (woman-negative-vertical-space from))
2282
2283 (if woman-preserve-ascii
2284 ;; Re-instate escaped escapes to just `\' and unpaddable
2285 ;; spaces to just `space', without inheriting any text
2286 ;; properties. This is not necessary, UNLESS the buffer is to
2287 ;; be saved as ASCII.
2288 (progn
2289 (goto-char from)
2290 (while (search-forward woman-escaped-escape-string nil t)
2291 (delete-char -1) (insert ?\\))
2292 (goto-char from)
2293 (while (search-forward woman-unpadded-space-string nil t)
2294 (delete-char -1) (insert ?\ ))
2295 ))
2296
2297 ;; Must return the new end of file if used in format-alist.
2298 (point-max)))
2299
2300 (defun woman-horizontal-escapes (to)
2301 "Process \\h'+/-N' local horizontal motion escapes upto TO.
2302 Implements arbitrary forward and non-overlapping backward motion.
2303 Preserves location of `point'."
2304 ;; Moved from `woman-decode-region' for version 0.50.
2305 ;; N may include width escape \w'...' (but may already be processed!
2306 (let ((from (point)))
2307 (while (re-search-forward
2308 ;; Delimiter can be a special char escape sequence \(.. or
2309 ;; a single normal char (usually '):
2310 "\\\\h\\(\\\\(..\\|.\\)\\(|\\)?"
2311 to t)
2312 (let ((from (match-beginning 0))
2313 (delim (regexp-quote (match-string 1)))
2314 (absolute (match-string 2)) ; absolute position?
2315 (N (woman-parse-numeric-arg)) ; distance
2316 to
2317 msg) ; for warning
2318 (if (not (looking-at delim))
2319 ;; Warn but leave escape in buffer unprocessed:
2320 (WoMan-warn
2321 "Local horizontal motion (%s) delimiter error!"
2322 (buffer-substring from (1+ (point)))) ; point at end of arg
2323 (setq to (match-end 0)
2324 ;; For possible warning -- save before deleting:
2325 msg (buffer-substring from to))
2326 (delete-region from to)
2327 (if absolute ; make relative
2328 (setq N (- N (current-column))))
2329 (if (>= N 0)
2330 ;; Move forward by inserting hard spaces:
2331 (insert-char woman-unpadded-space-char N)
2332 ;; Move backwards by deleting space,
2333 ;; first backwards then forwards:
2334 (while (and
2335 (<= (setq N (1+ N)) 0)
2336 (cond ((memq (preceding-char) '(?\ ?\t))
2337 (delete-backward-char 1) t)
2338 ((memq (following-char) '(?\ ?\t))
2339 (delete-char 1) t)
2340 (t nil))))
2341 (if (<= N 0)
2342 (WoMan-warn
2343 "Negative horizontal motion (%s) would overwrite!" msg))))
2344 ))
2345 (goto-char from)))
2346
2347
2348 \f
2349 ;; Process ignore requests (.ig), conditionals (.if etc.),
2350 ;; source-switch (.so), macro definitions (.de etc.) and macro
2351 ;; expansions.
2352
2353 (defvar woman0-if-to) ; marker bound in woman0-roff-buffer
2354 (defvar woman0-macro-alist) ; bound in woman0-roff-buffer
2355 (defvar woman0-search-regex) ; bound in woman0-roff-buffer
2356 (defvar woman0-search-regex-start ; bound in woman0-roff-buffer
2357 "^[.'][ \t]*\\(ig\\|if\\|ie\\|el\\|so\\|rn\\|de\\|am")
2358 (defconst woman0-search-regex-end "\\)\\([ \t]+\\|$\\)")
2359 ;; May need other terminal characters, e.g. \, but NOT \n!
2360 ;; Alternatively, force maximal match (Posix?)
2361
2362 (defvar woman0-rename-alist) ; bound in woman0-roff-buffer
2363
2364 (defun woman0-roff-buffer (from)
2365 "Process conditional-type requests and user-defined macros.
2366 Start at FROM and re-scan new text as appropriate."
2367 (goto-char from)
2368 (let ((woman0-if-to (make-marker))
2369 request woman0-macro-alist
2370 (woman0-search-regex-start woman0-search-regex-start)
2371 (woman0-search-regex
2372 (concat woman0-search-regex-start woman0-search-regex-end))
2373 woman0-rename-alist)
2374 (while (re-search-forward woman0-search-regex nil t)
2375 (setq request (match-string 1))
2376 (cond ((string= request "ig") (woman0-ig))
2377 ((string= request "if") (woman0-if "if"))
2378 ((string= request "ie") (woman0-if "ie"))
2379 ((string= request "el") (woman0-el))
2380 ((string= request "so") (woman0-so))
2381 ((string= request "rn") (woman0-rn))
2382 ((string= request "de") (woman0-de))
2383 ((string= request "am") (woman0-de 'append))
2384 (t (woman0-macro request))))
2385 (set-marker woman0-if-to nil)
2386 (woman0-rename)
2387 ;; Should now re-run `woman0-roff-buffer' if any renaming was
2388 ;; done, but let's just hope this is not necessary for now!
2389 ))
2390
2391 (defun woman0-ig ()
2392 ".ig yy -- Discard input up to `.yy', which defaults to `..')."
2393 ;; The terminal request MUST begin with . (not ')!
2394 (looking-at "\\(\\S +\\)?")
2395 (beginning-of-line)
2396 (let ((yy (or (match-string 1) "."))
2397 (from (point)))
2398 (if (re-search-forward
2399 (concat "^\\.[ \t]*" (regexp-quote yy) ".*\n") nil t)
2400 (delete-region from (point))
2401 (WoMan-warn
2402 "ig request ignored -- terminator `.%s' not found!" yy)
2403 (woman-delete-line 1))
2404 ))
2405
2406 (defsubst woman0-process-escapes (from to)
2407 "Process escapes within an if/ie condition between FROM and TO."
2408 (woman-strings to)
2409 (goto-char from) ; necessary!
2410 ;; Strip font-change escapes:
2411 (while (re-search-forward "\\\\f\\((..\\|.\\)" to t)
2412 (woman-delete-match 0))
2413 (goto-char from) ; necessary!
2414 (woman2-process-escapes to 'numeric))
2415
2416 (defun woman0-if (request)
2417 ".if/ie c anything -- Discard unless c evaluates to true.
2418 Remember condition for use by a subsequent `.el'.
2419 REQUEST is the invoking directive without the leading dot."
2420 ;; c evaluates to a one-character built-in condition name or
2421 ;; 'string1'string2' or a number > 0, prefix ! negates.
2422 ;; \{ ... \} for multi-line use.
2423 ;; Leaves point at start of new text.
2424 (woman-delete-match 0)
2425 ;; (delete-horizontal-space)
2426 ;; Process escapes in condition:
2427 (let ((from (point)) negated n (c 0))
2428 (set-marker woman0-if-to
2429 (save-excursion (skip-syntax-forward "^ ") (point)))
2430 ;; Process condition:
2431 (if (setq negated (= (following-char) ?!)) (delete-char 1))
2432 (cond
2433 ;; ((looking-at "[no]") (setq c t)) ; accept n(roff) and o(dd page)
2434 ;; ((looking-at "[te]") (setq c nil)) ; reject t(roff) and e(ven page)
2435 ((looking-at "[ntoe]")
2436 (setq c (memq (following-char) woman-if-conditions-true)))
2437 ;; Unrecognised letter so reject:
2438 ((looking-at "[A-Za-z]") (setq c nil)
2439 (WoMan-warn "%s %s -- unrecognised condition name rejected!"
2440 request (match-string 0)))
2441 ;; Accept strings if identical:
2442 ((save-restriction
2443 (narrow-to-region from woman0-if-to)
2444 ;; String delimiter can be any non-numeric character,
2445 ;; including a special character escape:
2446 (looking-at "\\(\\\\(..\\|[^0-9]\\)\\(.*\\)\\1\\(.*\\)\\1\\'"))
2447 (let ((end1 (copy-marker (match-end 2)))) ; end of first string
2448 ;; Delete 2nd and 3rd delimiters to avoid processing them:
2449 (delete-region (match-end 3) woman0-if-to)
2450 (delete-region (match-end 2) (match-beginning 3))
2451 (goto-char (match-end 1))
2452 (woman0-process-escapes (point) woman0-if-to)
2453 (setq c (string= (buffer-substring (point) end1)
2454 (buffer-substring end1 woman0-if-to)))
2455 (set-marker end1 nil)
2456 (goto-char from)))
2457 ;; Accept numeric value if > 0:
2458 ((numberp (setq n (progn
2459 (woman0-process-escapes from woman0-if-to)
2460 (woman-parse-numeric-arg))))
2461 (setq c (> n 0))
2462 (goto-char from))
2463 )
2464 (if (eq c 0)
2465 (woman-if-ignore woman0-if-to request) ; ERROR!
2466 (woman-if-body request woman0-if-to (eq c negated)))
2467 ))
2468
2469 (defun woman-if-body (request to delete) ; should be reversed as `accept'?
2470 "Process if-body, including \\{ ... \\}.
2471 REQUEST is the invoking directive without the leading dot.
2472 If TO is non-nil then delete the if-body.
2473 If DELETE is non-nil then delete from point."
2474 ;; Assume concealed newlines already processed.
2475 (let ((from (point)))
2476 (if to (delete-region (point) to))
2477 (delete-horizontal-space)
2478 (cond (;;(looking-at "[^{\n]*\\\\{\\s *") ; multi-line
2479 ;; allow escaped newlines:
2480 (looking-at "[^{\n]*\\(\\\\\n\\)*\\\\{\\s *\\(\\\\\n\\)*") ; multi-line
2481 ;; including preceding .if(s) and following newline
2482 (let ((from (point)))
2483 (woman-delete-match 0)
2484 ;; Allow for nested \{ ... \} -- BUT BEWARE that this
2485 ;; algorithm only supports one level of nesting!
2486 (while
2487 (and (re-search-forward
2488 ;; "\\(\\\\{\\)\\|\\(\n[.']\\)?[ \t]*\\\\}[ \t]*"
2489 ;; Interpret bogus `el \}' as `el \{',
2490 ;; especially for Tcl/Tk man pages:
2491 "\\(\\\\{\\|el[ \t]*\\\\}\\)\\|\\(\n[.']\\)?[ \t]*\\\\}[ \t]*")
2492 (match-string 1))
2493 (re-search-forward "\\\\}"))
2494 (delete-region (if delete from (match-beginning 0)) (point))
2495 (if (looking-at "^$") (delete-char 1))
2496 ))
2497 (delete (woman-delete-line 1)) ; single-line
2498 )
2499 ;; Process matching .el anything:
2500 (cond ((string= request "ie")
2501 ;; Discard unless previous .ie c `evaluated to false'.
2502 (cond ((re-search-forward "^[.'][ \t]*el[ \t]*" nil t)
2503 (woman-delete-match 0)
2504 (woman-if-body "el" nil (not delete)))))
2505 ;; Got here after processing a single-line `.ie' as a body
2506 ;; clause to be discarded:
2507 ((string= request "el")
2508 (cond ((re-search-forward "^[.'][ \t]*el[ \t]*" nil t)
2509 (woman-delete-match 0)
2510 (woman-if-body "el" nil t))))
2511 )
2512 (goto-char from)
2513 ))
2514
2515 (defun woman0-el ()
2516 "Isolated .el request -- should not happen!"
2517 (WoMan-warn "el request without matching `ie' rejected!")
2518 (cond (woman-ignore
2519 (woman-delete-match 0)
2520 (delete-horizontal-space)
2521 (woman-if-body "el" nil t))
2522 (t ; Ignore -- leave in buffer
2523 ;; This does not work too well, but it's only for debugging!
2524 (skip-chars-forward "^ \t")
2525 (if (looking-at "[ \t]*\\{") (search-forward "\\}"))
2526 (forward-line 1))))
2527
2528 (defun woman-if-ignore (to request)
2529 "Ignore but warn about an if request ending at TO, named REQUEST."
2530 (WoMan-warn-ignored request "ignored -- condition not handled!")
2531 (if woman-ignore
2532 (woman-if-body request to t)
2533 ;; Ignore -- leave in buffer
2534 ;; This does not work too well, but it's only for debugging!
2535 (skip-chars-forward "^ \t")
2536 (if (looking-at "[ \t]*\\{") (search-forward "\\}"))
2537 (forward-line 1)))
2538
2539 (defun woman0-so ()
2540 ".so filename -- Switch source file. `.so' requests may be nested."
2541 ;; Leaves point at start of new text.
2542 ;; (skip-chars-forward " \t")
2543 (let* ((beg (point))
2544 (end (progn (woman-forward-arg 'unquote) (point)))
2545 (name (buffer-substring beg end))
2546 (filename name))
2547 ;; If the specified file does not exist in this ...
2548 (or (file-exists-p filename)
2549 ;; or the parent directory ...
2550 (file-exists-p
2551 (setq filename (concat "../" name)))
2552 ;; then use the WoMan search mechanism to find the filename ...
2553 (setq filename
2554 (woman-file-name
2555 (file-name-sans-extension
2556 (file-name-nondirectory name))))
2557 ;; Cannot find the file, so ...
2558 (kill-buffer (current-buffer))
2559 (error "File `%s' not found" name))
2560 (beginning-of-line)
2561 (woman-delete-line 1)
2562 (let ((from (point))
2563 (to (make-marker))
2564 (length (woman-insert-file-contents filename 0)))
2565 (set-marker to (+ from length))
2566 (woman-pre-process-region from to)
2567 (set-marker to nil)
2568 (goto-char from)
2569 )))
2570
2571 \f
2572 ;;; Process macro definitions:
2573
2574 (defun woman0-rn ()
2575 "Process .rn xx yy -- rename macro xx to yy."
2576 ;; For now, done backwards AFTER all macro expansion.
2577 ;; Should also allow requests and strings to be renamed!
2578 (if (eolp) ; ignore if no argument
2579 ()
2580 (let* ((beg (point))
2581 (end (progn (woman-forward-arg 'unquote 'concat) (point)))
2582 (old (buffer-substring beg end))
2583 new)
2584 (if (eolp) ; ignore if no argument
2585 ()
2586 (setq beg (point)
2587 end (progn (woman-forward-arg 'unquote) (point))
2588 new (buffer-substring beg end)
2589 woman0-rename-alist (cons (cons new old) woman0-rename-alist)))
2590 ))
2591 (woman-delete-whole-line))
2592
2593 (defun woman0-rename ()
2594 "Effect renaming required by .rn requests."
2595 ;; For now, do this backwards AFTER all macro expansion.
2596 (while woman0-rename-alist
2597 (let* ((new (car woman0-rename-alist))
2598 (old (cdr new))
2599 (new (car new)))
2600 (setq woman0-rename-alist (cdr woman0-rename-alist))
2601 (goto-char (point-min))
2602 (setq new (concat "^[.'][ \t]*" (regexp-quote new)))
2603 (setq old (concat "." old))
2604 (while (re-search-forward new nil t)
2605 (replace-match old nil t)))))
2606
2607 (defconst woman-unescape-regex
2608 (concat woman-escaped-escape-string
2609 "\\(" woman-escaped-escape-string "\\)?"))
2610
2611 (defsubst woman-unescape (macro)
2612 "Replace escape sequences in the body of MACRO.
2613 Replaces || by |, but | by \, where | denotes the internal escape."
2614 (let (start)
2615 (while (setq start (string-match woman-unescape-regex macro start))
2616 (setq macro
2617 (if (match-string 1 macro)
2618 (replace-match "" t t macro 1)
2619 (replace-match "\\" t t macro))
2620 start (1+ start)))
2621 macro))
2622
2623 (defun woman0-de (&optional append)
2624 "Process .de/am xx yy -- (re)define/append macro xx; end at `..'.
2625 \(Should be up to call of yy, which defaults to `.')
2626 Optional argument APPEND, if non-nil, means append macro."
2627 ;; Modelled on woman-strings. BEWARE: Processing of .am is a hack!
2628 ;; Add support for .rm?
2629 ;; (skip-chars-forward " \t")
2630 (if (eolp) ; ignore if no argument
2631 ()
2632 (looking-at "[^ \t\n]+") ; macro name
2633 (let* ((macro (match-string 0)) from
2634 (previous (assoc macro woman0-macro-alist)))
2635 (if (not previous)
2636 (setq woman0-search-regex-start
2637 (concat woman0-search-regex-start "\\|" (regexp-quote macro))
2638 woman0-search-regex
2639 (concat woman0-search-regex-start woman0-search-regex-end)
2640 ))
2641 ;; Macro body runs from start of next line to line
2642 ;; beginning with `..'."
2643 ;; The terminal request MUST begin with `.' (not ')!
2644 (forward-line)
2645 (setq from (point))
2646 (re-search-forward "^\\.[ \t]*\\.")
2647 (beginning-of-line)
2648 (let ((body (woman-unescape (buffer-substring from (point)))))
2649 (if (and append previous)
2650 (setq previous (cdr previous)
2651 body (concat body (cdr previous))
2652 append (car previous)
2653 ))
2654 (setq macro (cons macro (cons append body))))
2655 ;; This should be an update, but consing a new string
2656 ;; onto the front of the alist has the same effect:
2657 (setq woman0-macro-alist (cons macro woman0-macro-alist))
2658 (forward-line)
2659 (delete-region from (point))
2660 (backward-char) ; return to end of .de/am line
2661 ))
2662 (beginning-of-line) ; delete .de/am line
2663 (woman-delete-line 1))
2664
2665 (defun woman0-macro (request)
2666 "Process the macro call named REQUEST."
2667 ;; Leaves point at start of new text.
2668 (let ((macro (assoc request woman0-macro-alist)))
2669 (if macro
2670 (woman-interpolate-macro (cdr macro))
2671 ;; SHOULD DELETE THE UNINTERPRETED REQUEST!!!!!
2672 ;; Output this message once only per call (cf. strings)?
2673 (WoMan-warn "Undefined macro %s not interpolated!" request))))
2674
2675 (defun woman-interpolate-macro (macro)
2676 "Interpolate (.de) or append (.am) expansion of MACRO into the buffer."
2677 ;; Could make this more efficient by checking which arguments are
2678 ;; actually used in the expansion!
2679 (skip-chars-forward " \t")
2680 ;; Process arguments:
2681 (let ((argno 0) (append (car macro))
2682 argno-string formal-arg from actual-arg start)
2683 (setq macro (cdr macro))
2684 (while (not (eolp))
2685 ;; Get next actual arg:
2686 (setq argno (1+ argno))
2687 (setq argno-string (format "%d" argno))
2688 (setq formal-arg (concat "\\\\\\$" argno-string)) ; regexp
2689 (setq from (point))
2690 (woman-forward-arg 'unquote 'noskip)
2691 (setq actual-arg (buffer-substring from (point)))
2692 (skip-chars-forward " \t") ; now skip following whitespace!
2693 ;; Replace formal arg with actual arg:
2694 (setq start nil)
2695 (while (setq start (string-match formal-arg macro start))
2696 (setq macro (replace-match actual-arg t t macro)))
2697 )
2698 ;; Delete any remaining formal arguments:
2699 (setq start nil)
2700 (while
2701 (setq start (string-match "\\\\\\$." macro start))
2702 (setq macro (replace-match "" t t macro)))
2703 ;; Replace .$ number register with actual arg:
2704 ;; (Do this properly via register mechanism later!)
2705 (setq start nil)
2706 (while
2707 (setq start (string-match "\\\\n(\\.\\$" macro start)) ; regexp
2708 (setq macro (replace-match argno-string t t macro)))
2709 (if append
2710 (forward-char)
2711 (beginning-of-line)
2712 (woman-delete-line 1))
2713 (save-excursion ; leave point at start of new text
2714 (insert macro))))
2715
2716 \f
2717 ;;; Process strings:
2718
2719 (defun woman-strings (&optional to)
2720 "Process ?roff string requests and escape sequences up to buffer position TO.
2721 Strings are defined/updated by `.ds xx string' requests and
2722 interpolated by `\*x' and `\*(xx' escapes."
2723 ;; Add support for .as and .rm?
2724 (while
2725 ;; Find .ds requests and \* escapes:
2726 (re-search-forward "\\(^[.'][ \t]*ds\\)\\|\\\\\\*" to t)
2727 (cond ((match-string 1) ; .ds
2728 (skip-chars-forward " \t")
2729 (if (eolp) ; ignore if no argument
2730 ()
2731 (re-search-forward "[^ \t\n]+")
2732 (let ((string (match-string 0)))
2733 (skip-chars-forward " \t")
2734 ; (setq string
2735 ; (cons string
2736 ; ;; hack (?) for CGI.man!
2737 ; (cond ((looking-at "\"\"") "\"")
2738 ; ((looking-at ".*") (match-string 0)))
2739 ; ))
2740 ;; Above hack causes trouble in arguments!
2741 (looking-at ".*")
2742 (setq string (cons string (match-string 0)))
2743 ;; This should be an update, but consing a new string
2744 ;; onto the front of the alist has the same effect:
2745 (setq woman-string-alist (cons string woman-string-alist))
2746 ))
2747 (beginning-of-line)
2748 (woman-delete-line 1))
2749 (t ; \*
2750 (let ((beg (match-beginning 0)))
2751 (cond ((= (following-char) ?\( )
2752 (forward-char)
2753 (re-search-forward ".."))
2754 (t (re-search-forward ".")))
2755 (let* ((stringname (match-string 0))
2756 (string (assoc stringname woman-string-alist)))
2757 (cond (string
2758 (delete-region beg (point))
2759 ;; Temporary hack in case string starts with a
2760 ;; control character:
2761 (if (bolp) (insert-before-markers "\\&"))
2762 (insert-before-markers (cdr string)))
2763 (t
2764 (WoMan-warn "Undefined string %s not interpolated!"
2765 stringname)
2766 (cond (woman-ignore
2767 ;; Output above message once only per call
2768 (delete-region beg (point))
2769 (setq woman-string-alist
2770 (cons (cons stringname "")
2771 woman-string-alist))))
2772 ))
2773 ))
2774 ))
2775 ))
2776
2777 \f
2778 ;;; Process special character escapes \(xx:
2779
2780 (defconst woman-special-characters
2781 ;; To be built heuristically as required!
2782 ;; MUST insert all characters as strings for correct conversion to
2783 ;; multibyte representation!
2784 '(("em" "--" "\276" . t) ; 3/4 Em dash
2785 ("bu" "*" "\267" . t) ; bullet
2786 ("fm" "'") ; foot mark
2787 ("co" "(C)" "\251") ; copyright
2788
2789 ("pl" "+" "+" . t) ; math plus
2790 ("mi" "-" "-" . t) ; math minus
2791 ("**" "*" "*" . t) ; math star
2792 ("aa" "'" "\242" . t) ; acute accent
2793 ("ul" "_") ; underrule
2794
2795 ("*S" "Sigma" "S" . t) ; Sigma
2796
2797 (">=" ">=" "\263" . t) ; >=
2798 ("<=" "<=" "\243" . t) ; <=
2799 ("->" "->" "\256" . t) ; right arrow
2800 ("<-" "<-" "\254" . t) ; left arrow
2801 ("mu" " x " "\264" . t) ; multiply
2802 ("+-" "+/-" "\261" . t) ; plus-minus
2803 ("bv" "|") ; bold vertical
2804
2805 ;; groff etc. extensions:
2806 ("lq" "\"")
2807 ("rq" "\"")
2808 ("aq" "'")
2809 ("ha" "^")
2810 ("ti" "~")
2811 )
2812 "Alist of special character codes with ASCII and extended-font equivalents.
2813 Each alist elements has the form
2814 (input-string ascii-string extended-font-string . use-symbol-font)
2815 where
2816 * `\\(input-string' is the ?roff encoding,
2817 * `ascii-string' is the (multi-character) ASCII simulation,
2818 * `extended-font-string' is the single-character string representing
2819 the character position in the extended 256-character font, and
2820 * `use-symbol-font' is t to indicate use of the symbol font or nil,
2821 i.e. omitted, to indicate use of the default font.
2822 Any element may be nil. Avoid control character codes (0 to \\37, \\180
2823 to \\237) in `extended-font-string' for now, since they can be
2824 displayed only with a modified display table.
2825
2826 Use the WoMan command `woman-display-extended-fonts' or a character
2827 map accessory to help construct this alist.")
2828
2829 (defsubst woman-replace-match (newtext &optional face)
2830 "Replace text matched by last search with NEWTEXT and return t.
2831 Set NEWTEXT in face FACE if specified."
2832 (woman-delete-match 0)
2833 (insert-before-markers newtext)
2834 (if face (put-text-property (1- (point)) (point)
2835 'face 'woman-symbol-face))
2836 t)
2837
2838 (defun woman-special-characters (to)
2839 "Process special character escapes \(xx up to buffer position TO.
2840 \(This must be done AFTER translation, which may use special characters.)"
2841 (while (re-search-forward "\\\\(\\(..\\)" to t)
2842 (let ((replacement
2843 (assoc (match-string-no-properties 1) woman-special-characters)))
2844 (if (and
2845 replacement
2846 (cond ((and (cddr replacement)
2847 (if (nthcdr 3 replacement)
2848 ;; Need symbol font:
2849 (if woman-use-symbol-font
2850 (woman-replace-match (nth 2 replacement)
2851 'woman-symbol-face))
2852 ;; Need extended font:
2853 (if woman-use-extended-font
2854 (woman-replace-match (nth 2 replacement))))))
2855 ((cadr replacement) ; Use ASCII simulation
2856 (woman-replace-match (cadr replacement)))))
2857 ()
2858 (WoMan-warn "Special character \\(%s not interpolated!"
2859 (match-string-no-properties 1))
2860 (if woman-ignore (woman-delete-match 0))))
2861 ))
2862
2863 (defun woman-display-extended-fonts ()
2864 "Display table of glyphs of graphic characters and their octal codes.
2865 All the octal codes in the ranges [32..127] and [160..255] are displayed
2866 together with the corresponding glyphs from the default and symbol fonts.
2867 Useful for constructing the alist variable `woman-special-characters'."
2868 (interactive)
2869 (with-output-to-temp-buffer "*WoMan Extended Font Map*"
2870 (save-excursion
2871 (set-buffer standard-output)
2872 (let ((i 32))
2873 (while (< i 256)
2874 (insert (format "\\%03o " i) (string i) " " (string i))
2875 (put-text-property (1- (point)) (point)
2876 'face 'woman-symbol-face)
2877 (insert " ")
2878 (setq i (1+ i))
2879 (when (= i 128) (setq i 160) (insert "\n"))
2880 (if (zerop (% i 8)) (insert "\n")))
2881 ))
2882 (print-help-return-message)))
2883
2884 \f
2885 ;;; Formatting macros that do not cause a break:
2886
2887 (defvar request) ; Bound locally by woman1-roff-buffer
2888 (defvar unquote) ; Bound locally by woman1-roff-buffer
2889
2890 (defun woman-unquote (to)
2891 "Delete any double-quote characters between point and TO.
2892 Leave point at TO (which should be a marker)."
2893 (let (in-quote)
2894 (while (search-forward "\"" to 1)
2895 (if (and in-quote (looking-at "\""))
2896 ;; Repeated double-quote represents single double-quote
2897 (delete-char 1)
2898 (if (or in-quote (looking-at ".*\"")) ; paired
2899 (delete-char -1))
2900 (setq in-quote (not in-quote))
2901 ))
2902 (if in-quote
2903 (WoMan-warn "Unpaired \" in .%s arguments." request))
2904 ))
2905
2906 (defsubst woman-unquote-args ()
2907 "Delete any double-quote characters up to the end of the line."
2908 (woman-unquote (save-excursion (end-of-line) (point-marker))))
2909
2910 (defun woman1-roff-buffer ()
2911 "Process non-breaking requests."
2912 (let ((case-fold-search t)
2913 request fn unquote)
2914 (while
2915 ;; Find next control line:
2916 (re-search-forward woman-request-regexp nil t)
2917 (cond
2918 ;; Construct woman function to call:
2919 ((setq fn (intern-soft
2920 (concat "woman1-"
2921 (setq request (match-string 1)))))
2922 (if (get fn 'notfont) ; not a font-change request
2923 (funcall fn)
2924 ;; Delete request or macro name:
2925 (woman-delete-match 0)
2926 ;; If no args then apply to next line else unquote args
2927 ;; (unquote is used by called function):
2928 (setq unquote (not (eolp)))
2929 (if (eolp) (delete-char 1))
2930 ; ;; Hide leading control character in unquoted argument:
2931 ; (cond ((memq (following-char) '(?. ?'))
2932 ; (insert "\\&")
2933 ; (beginning-of-line)))
2934 ;; Call the appropriate function:
2935 (funcall fn)
2936 ;; Hide leading control character in quoted argument (only):
2937 (if (and unquote (memq (following-char) '(?. ?')))
2938 (insert "\\&"))
2939 )
2940 )))))
2941
2942 ;;; Font-changing macros:
2943
2944 (defun woman1-B ()
2945 ".B -- Set words of current line in bold font."
2946 (woman1-B-or-I ".ft B\n"))
2947
2948 (defun woman1-I ()
2949 ".I -- Set words of current line in italic font."
2950 (woman1-B-or-I ".ft I\n"))
2951
2952 (defun woman1-B-or-I (B-or-I)
2953 ".B/I -- Set words of current line in bold/italic font.
2954 B-OR-I is the appropriate complete control line."
2955 ;; Should NOT concatenate the arguments!
2956 (insert B-or-I) ; because it might be a control line
2957 ;; Return to bol to process .SM/.B, .B/.if etc.
2958 ;; or start of first arg to hide leading control char.
2959 (save-excursion
2960 (if unquote
2961 (woman-unquote-args)
2962 (while (looking-at "^[.']") (forward-line))
2963 (end-of-line)
2964 (delete-horizontal-space))
2965 (insert "\\fR")))
2966
2967 (defun woman1-SM ()
2968 ".SM -- Set the current line in small font, i.e. IGNORE!"
2969 nil)
2970
2971 (defalias 'woman1-SB 'woman1-B)
2972 ;; .SB -- Set the current line in small bold font, i.e. just embolden!
2973 ;; (This is what /usr/local/share/groff/tmac/tmac.an does. The
2974 ;; Linux man.7 is wrong about this!)
2975
2976 (defun woman1-BI ()
2977 ".BI -- Join words of current line alternating bold and italic fonts."
2978 (woman1-alt-fonts (list "\\fB" "\\fI")))
2979
2980 (defun woman1-BR ()
2981 ".BR -- Join words of current line alternating bold and Roman fonts."
2982 (woman1-alt-fonts (list "\\fB" "\\fR")))
2983
2984 (defun woman1-IB ()
2985 ".IB -- Join words of current line alternating italic and bold fonts."
2986 (woman1-alt-fonts (list "\\fI" "\\fB")))
2987
2988 (defun woman1-IR ()
2989 ".IR -- Join words of current line alternating italic and Roman fonts."
2990 (woman1-alt-fonts (list "\\fI" "\\fR")))
2991
2992 (defun woman1-RB ()
2993 ".RB -- Join words of current line alternating Roman and bold fonts."
2994 (woman1-alt-fonts (list "\\fR" "\\fB")))
2995
2996 (defun woman1-RI ()
2997 ".RI -- Join words of current line alternating Roman and italic fonts."
2998 (woman1-alt-fonts (list "\\fR" "\\fI")))
2999
3000 (defun woman1-alt-fonts (fonts)
3001 "Join words using alternating fonts in FONTS, which MUST be a dynamic list."
3002 (nconc fonts fonts) ; circular list!
3003 (insert (car fonts))
3004 ;; Return to start of first arg to hide leading control char:
3005 (save-excursion
3006 (setq fonts (cdr fonts))
3007 (woman-forward-arg unquote 'concat) ; unquote is bound above
3008 (while (not (eolp))
3009 (insert (car fonts))
3010 (setq fonts (cdr fonts))
3011 (woman-forward-arg unquote 'concat)) ; unquote is bound above
3012 (insert "\\fR")
3013 ))
3014
3015 (defun woman-forward-arg (&optional unquote concat)
3016 "Move forward over one ?roff argument, optionally unquoting and/or joining.
3017 If optional arg UNQUOTE is non-nil then delete any argument quotes.
3018 If optional arg CONCAT is non-nil then join arguments."
3019 (if (eq (following-char) ?\")
3020 (progn
3021 (if unquote (delete-char 1) (forward-char))
3022 (re-search-forward "\"\\|$")
3023 ;; Repeated double-quote represents single double-quote
3024 (while (eq (following-char) ?\") ; paired
3025 (if unquote (delete-char 1) (forward-char))
3026 (re-search-forward "\"\\|$"))
3027 (if (eq (preceding-char) ?\")
3028 (if unquote (delete-backward-char 1))
3029 (WoMan-warn "Unpaired \" in .%s arguments." request)
3030 ))
3031 ;; (re-search-forward "[^\\\n] \\|$") ; inconsistent
3032 (skip-syntax-forward "^ "))
3033 (cond ((null concat) (skip-chars-forward " \t")) ; don't skip eol!
3034 ((eq concat 'noskip)) ; do not skip following whitespace
3035 (t (woman-delete-following-space)))
3036 )
3037
3038
3039 ;; The following requests are not explicit font-change requests and
3040 ;; so are flagged `notfont' to turn off automatic request deletion
3041 ;; and further processing.
3042
3043 (put 'woman1-TP 'notfont t)
3044 (defun woman1-TP ()
3045 ".TP -- After tag line, reset font to Roman for paragraph body."
3046 ;; Same for .IP, but forward only 1 line?
3047 (save-excursion
3048 ;; May be an `irrelevant' control line in the way, so ...
3049 (forward-line)
3050 (forward-line (if (looking-at "\\.\\S-+[ \t]*$") 2 1))
3051 ;; May be looking at control line, so ...
3052 (insert ".ft R\n")))
3053
3054 (put 'woman1-ul 'notfont t)
3055 (defun woman1-ul ()
3056 ".ul N -- Underline (italicize) the next N input lines, default N = 1."
3057 (let ((N (if (eolp) 1 (woman-parse-numeric-arg)))) ; woman-get-numeric-arg ?
3058 (woman-delete-whole-line)
3059 (insert ".ft I\n")
3060 (forward-line N)
3061 (insert ".ft R\n")
3062 ))
3063
3064 ;;; Other non-breaking requests:
3065
3066 ;; Hyphenation
3067 ;; Warnings commented out.
3068
3069 (put 'woman1-nh 'notfont t)
3070 (defun woman1-nh ()
3071 ".nh -- No hyphenation, i.e. IGNORE!"
3072 ;; Must be handled here to avoid breaking!
3073 ;; (WoMan-log-1 ".nh request ignored -- hyphenation not supported!")
3074 (woman-delete-whole-line))
3075
3076 (put 'woman1-hy 'notfont t)
3077 (defun woman1-hy ()
3078 ".hy N -- Set hyphenation mode to N, i.e. IGNORE!"
3079 ;; (WoMan-log-1 ".hy request ignored -- hyphenation not supported!")
3080 (woman-delete-whole-line))
3081
3082 (put 'woman1-hc 'notfont t)
3083 (defun woman1-hc ()
3084 ".hc c -- Set hyphenation character to c, i.e. delete it!"
3085 (let ((c (char-to-string (following-char))))
3086 ;; (WoMan-log
3087 ;; "Hyphenation character %s deleted -- hyphenation not supported!" c)
3088 (woman-delete-whole-line)
3089 (setq c (concat "\\(" c "\\)\\|^[.'][ \t]*hc"))
3090 (save-excursion
3091 (while (and (re-search-forward c nil t)
3092 (match-string 1))
3093 (delete-char -1)))
3094 ))
3095
3096 (put 'woman1-hw 'notfont t)
3097 (defun woman1-hw ()
3098 ".hw words -- Set hyphenation exception words, i.e. IGNORE!"
3099 ;; (WoMan-log-1 ".hw request ignored -- hyphenation not supported!")
3100 (woman-delete-whole-line))
3101
3102 ;;; Other non-breaking requests correctly ignored by nroff:
3103
3104 (put 'woman1-ps 'notfont t)
3105 (defalias 'woman1-ps 'woman-delete-whole-line)
3106 ;; .ps -- Point size -- IGNORE!
3107
3108 (put 'woman1-ss 'notfont t)
3109 (defalias 'woman1-ss 'woman-delete-whole-line)
3110 ;; .ss -- Space-character size -- IGNORE!
3111
3112 (put 'woman1-cs 'notfont t)
3113 (defalias 'woman1-cs 'woman-delete-whole-line)
3114 ;; .cs -- Constant character space (width) mode -- IGNORE!
3115
3116 (put 'woman1-ne 'notfont t)
3117 (defalias 'woman1-ne 'woman-delete-whole-line)
3118 ;; .ne -- Need vertical space -- IGNORE!
3119
3120 (put 'woman1-vs 'notfont t)
3121 (defalias 'woman1-vs 'woman-delete-whole-line)
3122 ;; .vs -- Vertical base line spacing -- IGNORE!
3123
3124 (put 'woman1-bd 'notfont t)
3125 (defalias 'woman1-bd 'woman-delete-whole-line)
3126 ;; .bd -- Embolden font -- IGNORE!
3127
3128 ;;; Non-breaking SunOS-specific macros:
3129
3130 (defun woman1-TX ()
3131 ".TX t p -- Resolve SunOS abbrev t and join to p (usually punctuation)."
3132 (insert "SunOS ")
3133 (woman-forward-arg 'unquote 'concat))
3134
3135 (put 'woman1-IX 'notfont t)
3136 (defalias 'woman1-IX 'woman-delete-whole-line)
3137 ;; .IX -- Index macro, for Sun internal use -- IGNORE!
3138
3139 \f
3140 ;;; Direct font selection:
3141
3142 (defconst woman-font-alist
3143 '(("R" . default)
3144 ("I" . woman-italic-face)
3145 ("B" . woman-bold-face)
3146 ("P" . previous)
3147 ("1" . default)
3148 ("2" . woman-italic-face)
3149 ("3" . woman-bold-face) ; used in bash.1
3150 )
3151 "Alist of ?roff font indicators and woman font variables and names.")
3152
3153 (defun woman-change-fonts ()
3154 "Process font changes."
3155 ;; ***** NEEDS REVISING IF IT WORKS OK *****
3156 ;; Paragraph .LP/PP/HP/IP/TP and font .B/.BI etc. macros reset font.
3157 ;; Should .SH/.SS reset font?
3158 ;; Font size setting macros (?) should reset font.
3159 (let ((woman-font-alist woman-font-alist) ; for local updating
3160 (previous-pos (point))
3161 (previous-font 'default)
3162 (current-font 'default))
3163 (while
3164 ;; Find font requests, paragraph macros and font escapes:
3165 (re-search-forward
3166 "^[.'][ \t]*\\(\\(\\ft\\)\\|\\(.P\\)\\)\\|\\(\\\\f\\)" nil 1)
3167 (let (font beg notfont)
3168 ;; Match font indicator and leave point at end of sequence:
3169 (cond ((match-string 2)
3170 ;; .ft request found
3171 (setq beg (match-beginning 0))
3172 (skip-chars-forward " \t")
3173 (if (eolp) ; default is previous font
3174 (setq font previous-font)
3175 (looking-at "[^ \t\n]+"))
3176 (forward-line)) ; end of control line and \n
3177 ((match-string 3)
3178 ;; Macro that resets font found
3179 (setq font 'default))
3180 ((match-string 4)
3181 ;; \f escape found
3182 (setq beg (match-beginning 0))
3183 (cond ((= (following-char) ?\( )
3184 (forward-char)
3185 (re-search-forward ".."))
3186 (t (re-search-forward ".")))
3187 )
3188 (t (setq notfont t)))
3189 (if notfont
3190 ()
3191 ;; Get font name:
3192 (or font
3193 (let ((fontstring (match-string 0)))
3194 (setq font (assoc fontstring woman-font-alist)
3195 ;; NB: woman-font-alist contains VARIABLE NAMES.
3196 font (if font
3197 (cdr font)
3198 (WoMan-warn "Unknown font %s." fontstring)
3199 ;; Output this message once only per call ...
3200 (setq woman-font-alist
3201 (cons (cons fontstring 'woman-unknown-face)
3202 woman-font-alist))
3203 'woman-unknown-face)
3204 )))
3205 ;; Delete font control line or escape sequence:
3206 (cond (beg (delete-region beg (point))
3207 (if (eq font 'previous) (setq font previous-font))))
3208 (woman-set-face previous-pos (point) current-font)
3209 (if beg
3210 ;; Explicit font control
3211 (setq previous-pos (point)
3212 previous-font current-font)
3213 ;; Macro that resets font
3214 ;; (forward-line) ; DOES NOT WORK! but unnecessary?
3215 ;; Must process font changes in any paragraph tag!
3216 (setq previous-pos (point)
3217 previous-font 'default))
3218 (setq current-font font)
3219 )))
3220 ;; Set font after last request up to eob:
3221 (woman-set-face previous-pos (point) current-font)
3222 ))
3223
3224 (defun woman-set-face (from to face)
3225 "Set the face of the text from FROM to TO to face FACE.
3226 Ignore the default face and underline only word characters."
3227 (or (eq face 'default) ; ignore
3228 (not woman-fontify)
3229 (if (face-underline-p face)
3230 (save-excursion
3231 (let ((face-no-ul (intern (concat (symbol-name face) "-no-ul"))))
3232 (goto-char from)
3233 (while (< (point) to)
3234 (skip-syntax-forward "w" to)
3235 (put-text-property from (point) 'face face)
3236 (setq from (point))
3237 (skip-syntax-forward "^w" to)
3238 (put-text-property from (point) 'face face-no-ul)
3239 (setq from (point))
3240 )))
3241 (put-text-property from to 'face face))
3242 ))
3243
3244 \f
3245 ;;; Output translation:
3246
3247 (defvar translations nil) ; Also bound locally by woman2-roff-buffer
3248 ;; A list of the form (\"[ace]\" (a . b) (c . d) (e . ?\ )) or nil.
3249
3250 (defun woman-get-next-char ()
3251 "Return and delete next char in buffer, including special chars."
3252 (if ;;(looking-at "\\\\(\\(..\\)")
3253 ;; Match special \(xx and strings \*x, \*(xx:
3254 (looking-at "\\\\\\((..\\|\\*\\((..\\|.\\)\\)")
3255 (prog1 (match-string 0)
3256 (woman-delete-match 0))
3257 (prog1 (char-to-string (following-char))
3258 (delete-char 1))))
3259
3260 (defun woman2-tr (to)
3261 ".tr abcde -- Translate a -> b, c -> d, ..., e -> space.
3262 Format paragraphs upto TO. Supports special chars.
3263 \(Breaks, but should not.)"
3264 ;; This should be an update, but consing onto the front of the alist
3265 ;; has the same effect and match duplicates should not matter.
3266 ;; Initialize translation data structures:
3267 (let ((matches (car translations))
3268 (alist (cdr translations))
3269 a b)
3270 ;; `matches' must be a string:
3271 (setq matches
3272 (concat (if matches (substring matches 1 -1)) "]"))
3273 ;; Process .tr arguments:
3274 (while (not (eolp)) ; (looking-at "[ \t]*$") ???
3275 (setq a (woman-get-next-char))
3276 (if (eolp)
3277 (setq b " ")
3278 (setq b (woman-get-next-char)))
3279 (setq matches
3280 (if (= (length a) 1)
3281 (concat a matches)
3282 (concat matches "\\|\\" a))
3283 alist (cons (cons a b) alist)))
3284 (delete-char 1) ; no blank line
3285 ;; Rebuild translations list:
3286 (setq matches
3287 (if (= (string-to-char matches) ?\])
3288 (substring matches 3)
3289 (concat "[" matches))
3290 translations (cons matches alist))
3291 ;; Format any following text:
3292 (woman2-format-paragraphs to)
3293 ))
3294
3295 (defsubst woman-translate (to)
3296 "Translate up to marker TO. Do this last of all transformations."
3297 (if translations
3298 (let ((matches (car translations))
3299 (alist (cdr translations)))
3300 (while (re-search-forward matches to t)
3301 ;; Done like this to retain text properties and
3302 ;; support translation of special characters:
3303 (insert-before-markers-and-inherit
3304 (cdr (assoc
3305 (buffer-substring-no-properties
3306 (match-beginning 0) (match-end 0))
3307 alist)))
3308 (woman-delete-match 0))
3309 )))
3310
3311 \f
3312 ;;; Registers:
3313
3314 (defvar woman-registers ; these are all read-only
3315 '((".H" 24) (".V" 48) ; resolution in basic units
3316 (".g" 0) ; not groff
3317 ;; (Iff emulating groff need to implement groff italic correction
3318 ;; \/, e.g. for pic.1)
3319 (".i" left-margin) ; current indent
3320 (".j" woman-adjust) ; current adjustment
3321 (".l" fill-column) ; current line length
3322 (".s" 12) ; current point size
3323 (".u" (if woman-nofill 0 1)) ; 1/0 in fill/nofill mode
3324 (".v" 48) ; current vertical line spacing
3325 )
3326 "Register alist: the key is the register name as a string.
3327 Each element has the form (KEY VALUE . INC) -- inc may be nil.
3328 Also bound locally in `woman2-roff-buffer'.")
3329
3330 (defun woman-mark-horizonal-position ()
3331 "\\kx -- Store current horizontal position in INPUT LINE in register x."
3332 (while (re-search-forward "\\\\k\\(.\\)" nil t)
3333 (goto-char (match-beginning 0))
3334 (setq woman-registers
3335 (cons (list (match-string 1) (current-column))
3336 woman-registers))
3337 (woman-delete-match 0)))
3338
3339 (defsubst woman2-process-escapes-to-eol (&optional numeric)
3340 "Process remaining escape sequences up to eol.
3341 Handle numeric arguments specially if optional argument NUMERIC is non-nil."
3342 (woman2-process-escapes
3343 (save-excursion (end-of-line) (point-marker))
3344 numeric))
3345
3346 (defun woman2-nr (to)
3347 ".nr R +/-N M -- Assign +/-N (wrt to previous value, if any) to register R.
3348 The increment for auto-incrementing is set to M.
3349 Format paragraphs upto TO. (Breaks, but should not!)"
3350 (let* ((name (buffer-substring
3351 (point)
3352 (progn (skip-syntax-forward "^ ") (point))))
3353 (pm (progn ; increment
3354 (skip-chars-forward " \t")
3355 (when (memq (char-after) '(?+ ?-))
3356 (forward-char) (char-before))))
3357 (value (if (eolp) ; no value
3358 nil ; to be interpreted as zero
3359 (woman2-process-escapes-to-eol 'numeric)
3360 (woman-parse-numeric-arg)))
3361 (inc (progn ; auto-increment
3362 (skip-chars-forward " \t")
3363 (if (eolp) ; no value
3364 nil ; to be interpreted as zero ???
3365 (woman-parse-numeric-arg))))
3366 (oldvalue (assoc name woman-registers)))
3367 (when oldvalue
3368 (setq oldvalue (cdr oldvalue)) ; (value . inc)
3369 (unless inc (setq inc (cdr oldvalue))))
3370 (cond ((null value)
3371 (setq value 0) ; correct?
3372 (WoMan-warn "nr %s -- null value assigned as zero!" name))
3373 ((symbolp value)
3374 (setq value (list 'quote value))))
3375 (if pm ; increment old value
3376 (setq oldvalue (if oldvalue (car oldvalue) 0)
3377 value (if (eq pm ?+)
3378 (+ oldvalue value)
3379 (- oldvalue value))))
3380 (setq woman-registers
3381 (cons (cons name (cons value inc)) woman-registers))
3382 (woman-delete-whole-line)
3383 (woman2-format-paragraphs to)))
3384
3385 \f
3386 ;;; Numeric (and "non-text") request arguments:
3387
3388 (defsubst woman-get-numeric-arg ()
3389 "Get the value of a numeric argument at or after point.
3390 The argument can include the width function and scale indicators.
3391 Assumes 10 characters per inch. Does not move point."
3392 (woman2-process-escapes-to-eol 'numeric)
3393 (save-excursion (woman-parse-numeric-arg)))
3394
3395 (defun woman-parse-numeric-arg ()
3396 "Get the value of a numeric expression at or after point.
3397 Unlike `woman-get-numeric-arg', leaves point after the argument.
3398 The expression may be an argument in quotes."
3399 (if (= (following-char) ?\") (forward-char))
3400 ;; Allow leading +/-:
3401 (let ((value (if (looking-at "[+-]") 0 (woman-parse-numeric-value)))
3402 op)
3403 (while (cond
3404 ((looking-at "[+-/*%]") ; arithmetic operators
3405 (forward-char)
3406 (setq op (intern-soft (match-string 0)))
3407 (setq value (funcall op value (woman-parse-numeric-value))))
3408 ((looking-at "[<=>]=?") ; relational operators
3409 (goto-char (match-end 0))
3410 (setq op (or (intern-soft (match-string 0))
3411 (intern-soft "=")))
3412 (setq value (if (funcall op value (woman-parse-numeric-value))
3413 1 0)))
3414 ((memq (setq op (following-char)) '(?& ?:)) ; Boolean and / or
3415 (forward-char)
3416 (setq value
3417 ;; and / or are special forms, not functions, in ELisp
3418 (if (eq op ?&)
3419 ;; and
3420 (if (> value 0)
3421 (if (> (woman-parse-numeric-value) 0) 1 0)
3422 ;; skip second operand
3423 (prog1 0 (woman-parse-numeric-value)))
3424 ;; or
3425 (if (> value 0)
3426 ;; skip second operand
3427 (prog1 1 (woman-parse-numeric-value))
3428 (if (> (woman-parse-numeric-value) 0) 1 0))
3429 )))
3430 ))
3431 ; (if (looking-at "[ \t\nRC\)\"]") ; R, C are tab types
3432 ; ()
3433 ; (WoMan-warn "Unimplemented numerical operator `%c' in %s"
3434 ; (following-char)
3435 ; (buffer-substring
3436 ; (save-excursion (beginning-of-line) (point))
3437 ; (save-excursion (end-of-line) (point))))
3438 ; (skip-syntax-forward "^ "))
3439 value
3440 ))
3441
3442 (defun woman-parse-numeric-value ()
3443 "Get a single numeric value at or after point.
3444 The value can be a number register or width function (which assumes 10
3445 characters per inch) and can include scale indicators. It may be an
3446 expression in parentheses. Leaves point after the value."
3447 ;; Must replace every \' by some different single character first
3448 ;; before calling this function by calling
3449 ;; (woman2-process-escapes-to-eol 'numeric)
3450 (if (eq (following-char) ?\()
3451 ;; Treat parenthesized expression as a single value.
3452 (let (n)
3453 (forward-char)
3454 (setq n (woman-parse-numeric-arg))
3455 (skip-syntax-forward " ")
3456 (if (eq (following-char) ?\))
3457 (forward-char)
3458 (WoMan-warn "Parenthesis confusion in numeric expression!"))
3459 n)
3460 (let ((n (cond ((looking-at "[-+]?[.0-9]+") ; single number
3461 ;; currently needed to set match-end, even though
3462 ;; string-to-number returns 0 if number not parsed.
3463 (string-to-number (match-string 0)))
3464 ((looking-at "\\\\n\\([-+]\\)?\\(\(\\(..\\)\\|\\(.\\)\\)")
3465 ;; interpolate number register, maybe auto-incremented
3466 (let* ((pm (match-string-no-properties 1))
3467 (name (or (match-string-no-properties 3)
3468 (match-string-no-properties 4)))
3469 (value (assoc name woman-registers)))
3470 (if value
3471 (let (inc)
3472 (setq value (cdr value) ; (value . inc)
3473 inc (cdr value)
3474 ;; eval internal (.X) registers
3475 ;; stored as lisp variable names:
3476 value (eval (car value)))
3477 (if (and pm inc) ; auto-increment
3478 (setq value
3479 (funcall (intern-soft pm) value inc)
3480 woman-registers
3481 (cons (cons name (cons value inc))
3482 woman-registers)))
3483 value)
3484 (WoMan-warn "Undefined register %s defaulted to 0."
3485 name)
3486 0) ; default to zero
3487 ))
3488 ((re-search-forward
3489 ;; Delimiter can be special char escape \(.. or
3490 ;; single normal char (usually '):
3491 "\\=\\\\w\\(\\\\(..\\|.\\)" nil t)
3492 (let ((from (match-end 0))
3493 (delim (regexp-quote (match-string 1))))
3494 (if (re-search-forward delim nil t)
3495 ;; Return width of string:
3496 (- (match-beginning 0) from)
3497 (WoMan-warn "Width escape delimiter error!"))))
3498 )))
3499 (if (null n)
3500 ;; ERROR -- should handle this better!
3501 (progn
3502 (WoMan-warn "Numeric/register argument error: %s"
3503 (buffer-substring
3504 (point)
3505 (save-excursion (end-of-line) (point))))
3506 (skip-syntax-forward "^ ")
3507 0)
3508 (goto-char (match-end 0))
3509 ;; Check for scale factor:
3510 (if
3511 (cond
3512 ((looking-at "\\s ") nil) ; stay put!
3513 ((looking-at "[mnuv]")) ; ignore for now
3514 ((looking-at "i") (setq n (* n 10))) ; inch
3515 ((looking-at "c") (setq n (* n 3.9))) ; cm
3516 ((looking-at "P") (setq n (* n 1.7))) ; Pica
3517 ((looking-at "p") (setq n (* n 0.14))) ; point
3518 ;; NB: May be immediately followed by + or -, etc.,
3519 ;; in which case do nothing and return nil.
3520 )
3521 (goto-char (match-end 0)))
3522 (if (numberp n) (round n) n))
3523 )))
3524
3525 \f
3526 ;;; VERTICAL FORMATTING -- Formatting macros that cause a break:
3527
3528 ;; Vertical spacing philosophy:
3529 ;; Delete all vertical space as it is encountered. Then insert
3530 ;; vertical space only before text, as required.
3531
3532 (defun woman2-roff-buffer ()
3533 "Process breaks. Format paragraphs and headings."
3534 (let ((case-fold-search t)
3535 (to (make-marker))
3536 (canonically-space-region
3537 (symbol-function 'canonically-space-region))
3538 (insert-and-inherit (symbol-function 'insert-and-inherit))
3539 (set-text-properties (symbol-function 'set-text-properties))
3540 (woman-registers woman-registers)
3541 fn request translations
3542 tab-stop-list)
3543 ;; ?roff does not squeeze multiple spaces, but does fill, so...
3544 (fset 'canonically-space-region 'ignore)
3545 ;; Try to avoid spaces inheriting underlines from preceding text!
3546 (fset 'insert-and-inherit (symbol-function 'insert))
3547 (fset 'set-text-properties 'ignore)
3548 (unwind-protect
3549 (while
3550 ;; Find next control line:
3551 (re-search-forward woman-request-regexp nil t)
3552 (cond
3553 ;; Construct woman function to call:
3554 ((setq fn (intern-soft
3555 (concat "woman2-"
3556 (setq request (match-string 1)))))
3557 ;; Delete request or macro name:
3558 (woman-delete-match 0))
3559 ;; Unrecognised request:
3560 ((prog1 nil
3561 ;; (WoMan-warn ".%s request ignored!" request)
3562 (WoMan-warn-ignored request "ignored!")
3563 ;; (setq fn 'woman2-LP)
3564 ;; AVOID LEAVING A BLANK LINE!
3565 ;; (setq fn 'woman2-format-paragraphs)
3566 ))
3567 ;; .LP assumes it is at eol and leaves a (blank) line,
3568 ;; so leave point at end of line before paragraph:
3569 ((or (looking-at "[ \t]*$") ; no argument
3570 woman-ignore) ; ignore all
3571 ;; (beginning-of-line) (kill-line)
3572 ;; AVOID LEAVING A BLANK LINE!
3573 (beginning-of-line) (woman-delete-line 1))
3574 (t (end-of-line) (insert ?\n))
3575 )
3576 (if (not (or fn
3577 (and (not (memq (following-char) '(?. ?')))
3578 (setq fn 'woman2-format-paragraphs))))
3579 ()
3580 ;; Find next control line:
3581 (set-marker to (woman-find-next-control-line))
3582 ;; Call the appropriate function:
3583 (funcall fn to)))
3584 (if (not (eobp)) ; This should not happen, but ...
3585 (woman2-format-paragraphs (point-max-marker) woman-left-margin))
3586 (fset 'canonically-space-region canonically-space-region)
3587 (fset 'set-text-properties set-text-properties)
3588 (fset 'insert-and-inherit insert-and-inherit)
3589 (set-marker to nil))))
3590
3591 (defun woman-find-next-control-line ()
3592 "Find and return start of next control line."
3593 ; (let ((to (save-excursion
3594 ; (re-search-forward "^\\." nil t))))
3595 ; (if to (1- to) (point-max)))
3596 (let (to)
3597 (save-excursion
3598 ;; Must handle
3599 ;; ...\c
3600 ;; .br (and other requests?)
3601 ;; by deleting both the \c and the following request.
3602 ;; BEWARE THAT THIS CODE MAY BE UNRELIABLE!!!!!
3603 (while
3604 (and
3605 (setq to (re-search-forward "\\(\\\\c\\)?\n[.']" nil t))
3606 (match-string 1)
3607 (looking-at "br"))
3608 (goto-char (match-beginning 0))
3609 (woman-delete-line 2)))
3610 (if to (1- to) (point-max))))
3611
3612 (defun woman2-PD (to)
3613 ".PD d -- Set the interparagraph distance to d.
3614 Round to whole lines, default 1 line. Format paragraphs upto TO.
3615 (Breaks, but should not.)"
3616 ;; .ie \\n[.$] .nr PD (v;\\$1)
3617 ;; .el .nr PD .4v>?\n[.V]
3618 (woman-set-interparagraph-distance)
3619 (woman2-format-paragraphs to))
3620
3621 (defun woman-set-interparagraph-distance ()
3622 "Set the interparagraph distance from a .PD request at point."
3623 (setq woman-interparagraph-distance
3624 (if (eolp) 1 (woman-get-numeric-arg)))
3625 ;; Should allow .PD 0 to set zero line spacing
3626 (woman-delete-line 1)) ; ignore remaining args
3627
3628 (defsubst woman-interparagraph-space ()
3629 "Set variable `woman-leave-blank-lines' from `woman-interparagraph-distance'."
3630 ; (if (> woman-interparagraph-distance 0)
3631 ; (forward-line 1) ; leave 1 blank line
3632 ; (woman-delete-line 1)) ; do not leave blank line
3633 (setq woman-leave-blank-lines woman-interparagraph-distance)
3634 )
3635
3636 (defun woman2-TH (to)
3637 ".TH n c x v m -- Begin a man page. Format paragraphs upto TO.
3638 n is the name of the page in chapter c\; x is extra commentary\;
3639 v alters page foot left; m alters page head center.
3640 \(Should set prevailing indent and tabs to 5.)"
3641 (woman-forward-arg 'unquote 'concat)
3642 (insert ?\()
3643 (woman-forward-arg 'unquote 'concat)
3644 (insert ?\))
3645 (let ((start (point)) here)
3646 (while (not (eolp))
3647 (cond ((looking-at "\"\"[ \t]")
3648 (delete-char 2)
3649 ;; (delete-horizontal-space)
3650 ))
3651 (delete-horizontal-space)
3652 (setq here (point))
3653 (insert " -- ")
3654 (woman-forward-arg 'unquote 'concat)
3655 ;; Delete repeated arguments:
3656 (if (string-match (buffer-substring here (point))
3657 (buffer-substring start here))
3658 (delete-region here (point)))
3659 ))
3660 ;; Embolden heading (point is at end of heading):
3661 (woman-set-face
3662 (save-excursion (beginning-of-line) (point)) (point) 'woman-bold-face)
3663 (forward-line)
3664 (delete-blank-lines)
3665 (setq woman-left-margin woman-default-indent)
3666 (setq woman-prevailing-indent woman-default-indent)
3667 (woman2-format-paragraphs to woman-left-margin))
3668
3669 (defun woman2-SH (to)
3670 ".SH -- Sub-head. Leave blank line and subhead.
3671 Format paragraphs upto TO. Set prevailing indent to 5."
3672 (if (eolp) ; If no args then
3673 (delete-char 1) ; apply to next line
3674 (woman-unquote-args) ; else unquote to end of heading
3675 (beginning-of-line))
3676 (woman2-process-escapes-to-eol)
3677 (woman-leave-blank-lines woman-interparagraph-distance)
3678 (setq woman-leave-blank-lines nil)
3679 ;; Optionally embolden heading (point is at beginning of heading):
3680 (if woman-bold-headings
3681 (woman-set-face
3682 (point) (save-excursion (end-of-line) (point)) 'woman-bold-face))
3683 (forward-line)
3684 (setq woman-left-margin woman-default-indent
3685 woman-nofill nil) ; fill output lines
3686 (setq woman-prevailing-indent woman-default-indent)
3687 (woman2-format-paragraphs to woman-left-margin))
3688
3689 (defun woman2-SS (to)
3690 ".SS -- Sub-sub-head. Like .SH but indent heading 3 spaces.
3691 Format paragraphs upto TO."
3692 (if (eolp) ; If no args then
3693 (delete-char 1)) ; apply to next line.
3694 (insert " ")
3695 (beginning-of-line)
3696 (woman2-SH to))
3697
3698 (defun woman2-LP (to)
3699 ".LP,.PP -- Begin paragraph. Set prevailing indent to 5.
3700 Leave 1 blank line. Format paragraphs upto TO."
3701 (woman-delete-line 1) ; ignore any arguments
3702 (woman-interparagraph-space)
3703 (setq woman-prevailing-indent woman-default-indent)
3704 (woman2-format-paragraphs to woman-left-margin))
3705
3706 (defalias 'woman2-PP 'woman2-LP)
3707 (defalias 'woman2-P 'woman2-LP)
3708
3709 (defun woman2-ns (to)
3710 ".ns -- Turn on no-space mode. Format paragraphs upto TO."
3711 ;; Should not cause a break!
3712 (woman-delete-line 1) ; ignore argument(s)
3713 (setq woman-nospace t)
3714 (woman2-format-paragraphs to))
3715
3716 (defun woman2-rs (to)
3717 ".rs -- Turn off no-space mode. Format paragraphs upto TO."
3718 ;; Should not cause a break!
3719 (woman-delete-line 1) ; ignore argument(s)
3720 (setq woman-nospace nil)
3721 (woman2-format-paragraphs to))
3722
3723 (defun woman2-sp (to)
3724 ".sp N -- If N > 0 then leave 1 blank line. Format paragraphs upto TO."
3725 (let ((N (if (eolp) 1 (woman-get-numeric-arg))))
3726 (if (>= N 0)
3727 (woman-delete-line 1) ; ignore argument(s)
3728 (setq woman-negative-vertical-space t)
3729 (insert ".sp ")
3730 (forward-line))
3731 (setq woman-leave-blank-lines N)
3732 (woman2-format-paragraphs to)))
3733
3734 (defun woman-negative-vertical-space (from)
3735 ".sp N with N < 0 => overlap following with preceding lines at FROM."
3736 ;; Run by woman-decode-region if necessary -- not usually required.
3737 (WoMan-warn "Negative vertical spacing support is experimental!")
3738 (goto-char from)
3739 (while
3740 ;; Find next control line:
3741 (re-search-forward "^\\.sp " nil t)
3742 (let ((N (woman-get-numeric-arg))
3743 overlap overwritten)
3744 (woman-delete-whole-line)
3745 (setq from (point)
3746 overlap (buffer-substring from
3747 (progn (forward-line (- N)) (point))))
3748 (delete-region from (point))
3749 (forward-line N)
3750 (let ((imax (length overlap))
3751 (i 0) c)
3752 (while (< i imax)
3753 (setq c (aref overlap i))
3754 (cond ((eq c ?\n) ; skip
3755 (forward-line))
3756 ((eolp) ; extend line
3757 ;; Insert character INCLUDING TEXT PROPERTIES:
3758 ;; (insert (substring overlap i (1+ i)))
3759 (let ((eol (string-match "\n" overlap i)))
3760 (insert (substring overlap i eol))
3761 (setq i (or eol imax)))
3762 )
3763 ((eq c ?\ ) ; skip
3764 (forward-char))
3765 ((eq c ?\t) ; skip
3766 (if (eq (following-char) ?\t)
3767 (forward-char) ; both tabs, just skip
3768 (let ((i woman-tab-width))
3769 (while (> i 0)
3770 (if (eolp)
3771 (insert ?\ ) ; extend line
3772 (forward-char)) ; skip
3773 (setq i (1- i)))
3774 )))
3775 (t
3776 (if (or (eq (following-char) ?\ ) ; overwrite OK
3777 overwritten) ; warning only once per ".sp -"
3778 ()
3779 (setq overwritten t)
3780 (WoMan-warn
3781 "Character(s) overwritten by negative vertical spacing in line %d"
3782 (count-lines 1 (point))))
3783 (delete-char 1) (insert (substring overlap i (1+ i)))))
3784 (setq i (1+ i))
3785 ))
3786 )))
3787
3788 \f
3789 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3790 ;; The following function should probably do ALL width and number
3791 ;; register interpolation.
3792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3793
3794 (defun woman2-process-escapes (to &optional numeric)
3795 "Process remaining escape sequences up to marker TO, preserving point.
3796 Optional argument NUMERIC, if non-nil, means the argument is numeric."
3797 ;; The first two cases below could be merged (maybe)!
3798 (let ((from (point)))
3799 ;; Discard zero width filler character used to hide leading dots
3800 ;; and zero width characters \|, \^:
3801 (while (re-search-forward "\\\\[&|^]" to t)
3802 (woman-delete-match 0))
3803 (goto-char from)
3804 ;; Interrupt text processing -- CONTINUE current text with the
3805 ;; next text line (after any control lines, unless processing to
3806 ;; eol):
3807 (while (re-search-forward "\\\\c.*\n?" to t)
3808 (woman-delete-match 0))
3809 ;; but do not delete the final newline ...
3810 (if (and (or (eobp) (= (point) to)) (not (bolp)))
3811 (insert-before-markers ?\n))
3812 (goto-char from)
3813 (woman-translate to)
3814 (goto-char from)
3815 (woman-special-characters to)
3816 (goto-char from)
3817 ;; Printable version of the current escape character, ASSUMED to be `\'
3818 ;; This must be done LAST of all escape processing!
3819 ;; Done like this to preserve any text properties of the `\'
3820 (while (search-forward "\\" to t)
3821 (let ((c (following-char)))
3822 (cond ((eq c ?') ; \' -> '
3823 (delete-char -1)
3824 (cond (numeric ; except in numeric args, \' -> `
3825 (delete-char 1)
3826 (insert ?`))))
3827 ((eq c ?\( )) ; uninterpreted special character
3828 ; \(.. -- do nothing
3829 ((eq c ?t) ; non-interpreted tab \t
3830 (delete-char 1)
3831 (delete-char -1)
3832 (insert "\t"))
3833 ((and numeric
3834 (memq c '(?w ?n ?h)))) ; leave \w, \n, \h (?????)
3835 ((eq c ?l) (woman-horizontal-line))
3836 (t
3837 ;; \? -> ? where ? is any remaining character
3838 (WoMan-warn "Escape ignored: \\%c -> %c" c c)
3839 (delete-char -1))
3840 )))
3841 (goto-char from)
3842 ;; Process non-default tab settings:
3843 (cond (tab-stop-list
3844 (while (search-forward "\t" to t)
3845 (woman-tab-to-tab-stop))
3846 (goto-char from)))
3847
3848 ;; Must replace \' by something before processing \w, done above.
3849
3850 ;; Replace all `\w' and `\n' escapes:
3851 ;; (This may be a bit too recursive!)
3852 (while (re-search-forward "\\\\[nw]" to t)
3853 (let ((from (match-beginning 0)) N)
3854 (goto-char from)
3855 (setq N (woman-parse-numeric-value))
3856 (delete-region from (point))
3857 ;; Interpolate value:
3858 (insert-before-markers (number-to-string N))))
3859 (goto-char from)))
3860
3861 (defun woman-horizontal-line ()
3862 "\\l'Nc' -- Draw a horizontal line of length N using character c, default _."
3863 (delete-char -1)
3864 (delete-char 1)
3865 (looking-at "\\(.\\)\\(.*\\)\\1")
3866 (let ((to (make-marker)) from N c)
3867 (set-marker to (match-end 2))
3868 (delete-char 1)
3869 (setq from (point)
3870 N (woman-parse-numeric-arg))
3871 (setq c (if (< (point) to) (following-char) ?_))
3872 (delete-region from to)
3873 (delete-char 1)
3874 (set-marker to nil)
3875 (insert (make-string N c))
3876 ))
3877
3878 ;;; 4. Text Filling, Adjusting, and Centering
3879
3880 (defun woman2-br (to)
3881 ".br -- Break. Leave no blank line. Format paragraphs upto TO."
3882 (woman-delete-line 1) ; ignore any arguments
3883 (woman2-format-paragraphs to))
3884
3885 (defun woman2-fi (to)
3886 ".fi -- Fill subsequent output lines. Leave no blank line.
3887 Format paragraphs upto TO."
3888 (setq woman-nofill nil)
3889 (woman-delete-line 1) ; ignore any arguments
3890 ;; Preserve any final blank line in the nofill region:
3891 (save-excursion
3892 (forward-line -1)
3893 (if (looking-at "[ \t]*$") (setq woman-leave-blank-lines 1)))
3894 (woman2-format-paragraphs to))
3895
3896 (defun woman2-nf (to)
3897 ".nf -- Nofill. Subsequent lines are neither filled nor adjusted.
3898 Input text lines are copied directly to output lines without regard
3899 for the current line length. Format paragraphs upto TO."
3900 (setq woman-nofill t)
3901 (woman-delete-line 1) ; ignore any arguments
3902 (woman2-format-paragraphs to))
3903
3904 (defun woman2-ad (to)
3905 ".ad c -- Line adjustment is begun (once fill mode is on).
3906 Set justification mode to c if specified.
3907 Format paragraphs upto TO. (Breaks, but should not.)"
3908 ;; c = l -- left, r -- right, c -- center, b or n -- both,
3909 ;; absent -- unchanged. Initial mode adj,both.
3910 (setq woman-adjust
3911 (cond ((eolp) woman-adjust-previous)
3912 ((eq (following-char) ?l) woman-adjust-left)
3913 ((eq (following-char) ?r) woman-adjust-right)
3914 ((eq (following-char) ?c) woman-adjust-center)
3915 ((memq (following-char) '(?b ?n)) woman-adjust-both)
3916 (t (woman-get-numeric-arg))
3917 )
3918 woman-justify (nth woman-adjust woman-justify-list))
3919 (woman-delete-line 1) ; ignore any remaining arguments
3920 (woman2-format-paragraphs to))
3921
3922 (defun woman2-na (to)
3923 ".na -- No adjusting. Format paragraphs upto TO.
3924 (Breaks, but should not.)"
3925 (setq woman-adjust-previous woman-adjust
3926 woman-justify-previous woman-justify
3927 woman-adjust woman-adjust-left ; fill but do not adjust
3928 woman-justify (nth woman-adjust woman-justify-list))
3929 (woman-delete-line 1) ; ignore any arguments
3930 (woman2-format-paragraphs to))
3931
3932 ;;; The main formatting functions:
3933
3934 (defun woman-leave-blank-lines (&optional leave)
3935 "Delete all blank lines around point.
3936 Leave one blank line if optional argument LEAVE is non-nil and
3937 non-zero, or if LEAVE is nil and variable `woman-leave-blank-lines' is
3938 non-nil and non-zero."
3939 ;; ***** It may suffice to delete only lines ABOVE point! *****
3940 ;; NOTE: Function arguments are evaluated left to right
3941 ;; (*note (elisp)Function Forms::.).
3942 (delete-region
3943 (save-excursion
3944 (if (not (eq (skip-syntax-backward " ") 0))
3945 (forward-line)) ; forward-char ?
3946 (point))
3947 (progn (skip-syntax-forward " ")
3948 (beginning-of-line)
3949 (point)))
3950 (if woman-nospace
3951 ()
3952 (if (or (null leave) (eq leave 0))
3953 ;; output any `pending' vertical space ...
3954 (setq leave woman-leave-blank-lines))
3955 (if (and leave (> leave 0)) (insert-before-markers ?\n))
3956 )
3957 (setq woman-leave-blank-lines nil)
3958 )
3959
3960 ;; `fill-region-as-paragraph' in `fill.el' appears to be the principal
3961 ;; text filling function, so that is what I use here.
3962
3963 (defvar woman-temp-indent nil)
3964
3965 (defun woman2-format-paragraphs (to &optional new-left)
3966 "Indent, fill and adjust paragraphs upto TO to current left margin.
3967 If optional arg NEW-LEFT is non-nil then reset current left margin.
3968 If `woman-nofill' is non-nil then indent without filling or adjusting."
3969 ;; Blank space should only ever be output before text.
3970 (if new-left (setq left-margin new-left))
3971 (if (looking-at "^\\s *$")
3972 ;; A blank line should leave a space like .sp 1 (p. 14).
3973 (setq woman-leave-blank-lines 1))
3974 (skip-syntax-forward " ")
3975 ;; Successive control lines are sufficiently common to be worth a
3976 ;; special case (maybe):
3977 (if (>= (point) to) ; >= as a precaution!
3978 ()
3979 ;; (woman-leave-blank-lines)
3980 (woman-reset-nospace)
3981 ;; (woman2-process-escapes to) ; 7 October 1999
3982 (woman2-process-escapes to 'numeric)
3983 (if woman-nofill
3984 ;; Indent without filling or adjusting ...
3985 (progn
3986 (woman-leave-blank-lines)
3987 (cond (woman-temp-indent
3988 (indent-to woman-temp-indent)
3989 (forward-line)))
3990 (indent-rigidly (point) to left-margin)
3991 (woman-horizontal-escapes to)) ; 7 October 1999
3992 ;; Fill and justify ...
3993 ;; Blank lines and initial spaces cause a break.
3994 ; (cond ((and (= (point) to) (not (looking-at ".nf"))) ; Yuk!!!
3995 ; ;; No text after a request that caused a break, so delete
3996 ; ;; any spurious blank line left:
3997 ; (forward-line -1)
3998 ; (if (looking-at "^\\s *$") (kill-line) (forward-line))))
3999 (while (< (point) to)
4000 (woman-leave-blank-lines)
4001 (let ((from (point)))
4002 ;; Indent first lin of paragraph:
4003 (indent-to (or woman-temp-indent left-margin))
4004 (woman-horizontal-escapes to) ; 7 October 1999
4005 ;; Find the beginning of the next paragraph:
4006 (forward-line)
4007 ; (if (re-search-forward "\\(^\\s *$\\)\\|\\(^\\s +\\)" to 1)
4008 ; ;; A blank line should leave a space like .sp 1 (p. 14).
4009 ; (if (eolp)
4010 ; (progn
4011 ; (skip-syntax-forward " ")
4012 ; (setq woman-leave-blank-lines 1))
4013 ; (setq woman-leave-blank-lines nil)))
4014 (and (re-search-forward "\\(^\\s *$\\)\\|\\(^\\s +\\)" to 1)
4015 ;; A blank line should leave a space like .sp 1 (p. 14).
4016 (eolp)
4017 (skip-syntax-forward " ")
4018 (setq woman-leave-blank-lines 1))
4019 (beginning-of-line)
4020 ;; If a single short line then just leave it.
4021 ;; This is necessary to preserve some table layouts.
4022 ;; PROBABLY NOT NECESSARY WITH SQUEEZE MODIFICATION !!!!!
4023 (if (or (> (count-lines from (point)) 1)
4024 (save-excursion
4025 (backward-char)
4026 (> (current-column) fill-column)))
4027 ;; ?roff does not squeeze multiple spaces
4028 ;; (fill-region-as-paragraph from (point) woman-justify t)
4029 ;; NOSQUEEZE has no effect if JUSTIFY is full, so
4030 ;; redefine canonically-space-region, see above.
4031 (progn
4032 ;; Needs a re-write of the paragraph formatter to
4033 ;; avoid this nonsense to handle temporary indents!
4034 (if (and woman-temp-indent (< woman-temp-indent left-margin))
4035 (let ((left-margin woman-temp-indent))
4036 (fill-region-as-paragraph from (point) woman-justify)
4037 (save-excursion
4038 (goto-char from)
4039 (forward-line)
4040 (setq from (point)))))
4041 (fill-region-as-paragraph from (point) woman-justify))
4042 )
4043 ;; A blank line should leave a space like .sp 1 (p. 14).
4044 ;; Delete all but 1 trailing blank lines:
4045 ;;(woman-leave-blank-lines 1)
4046 ))
4047 )
4048 (setq woman-temp-indent nil)
4049 ;; Non-white-space text has been processed, so ...
4050 ;;(setq woman-leave-blank-lines nil)
4051 ))
4052
4053 \f
4054 ;;; Tagged, indented and hanging paragraphs:
4055
4056 (defun woman2-TP (to)
4057 ".TP i -- Set prevailing indent to i. Format paragraphs upto TO.
4058 Begin indented paragraph with hanging tag given by next text line.
4059 If tag doesn't fit, place it on a separate line."
4060 (let ((i (woman2-get-prevailing-indent)))
4061 (woman-leave-blank-lines woman-interparagraph-distance)
4062 (woman2-tagged-paragraph to i)))
4063
4064 (defun woman2-IP (to)
4065 ".IP x i -- Same as .TP with tag x. Format paragraphs upto TO."
4066 (woman-interparagraph-space)
4067 (if (eolp) ; no args
4068 ;; Like LP without resetting prevailing indent
4069 (woman2-format-paragraphs to (+ woman-left-margin
4070 woman-prevailing-indent))
4071 (woman-forward-arg 'unquote)
4072 (let ((i (woman2-get-prevailing-indent 'leave-eol)))
4073 (beginning-of-line)
4074 (woman-leave-blank-lines) ; must be here,
4075 (woman2-tagged-paragraph to i))))
4076
4077 (defun woman-find-next-control-line-carefully ()
4078 "Find and return start of next control line, even if already there!"
4079 (if (looking-at "^[.']")
4080 (point)
4081 (woman-find-next-control-line)))
4082
4083 (defun woman2-tagged-paragraph (to i)
4084 "Begin indented paragraph with hanging tag given by current text line.
4085 If tag doesn't fit, leave it on separate line.
4086 Format paragraphs upto TO. Set prevailing indent to I."
4087 (if (not (looking-at "\\s *$")) ; non-empty tag
4088 (setq woman-leave-blank-lines nil))
4089
4090 ;; Temporary hack for bash.1 and groff_mmse.7 until code is revised
4091 ;; to process all requests uniformly:
4092 (cond ((and (= (point) to) (looking-at "^[.'][ \t]*\\(PD\\|br\\|ta\\) *"))
4093 (if (string= (match-string 1) "br")
4094 (woman-delete-line 1)
4095 (woman-delete-match 0)
4096 (if (string= (match-string 1) "ta") ; for GetInt.3
4097 (woman2-ta to)
4098 (woman-set-interparagraph-distance)))
4099 (set-marker to (woman-find-next-control-line-carefully))
4100 ))
4101
4102 (let ((tag (point)))
4103 (woman-reset-nospace)
4104 ;; Format the tag:
4105 (woman2-process-escapes-to-eol)
4106 ;; TIDY UP THE FOLLOWING CODE
4107 ;; (indent-to woman-left-margin)
4108 (setq left-margin woman-left-margin)
4109 (forward-line)
4110 (fill-region-as-paragraph (save-excursion (forward-line -1) (point))
4111 (point) woman-justify)
4112
4113 ;; Temporary hack for bash.1 until all requests processed uniformly:
4114 (cond ((and (= (point) to) (looking-at "^[.'][ \t]*PD *"))
4115 (woman-delete-match 0)
4116 (woman-set-interparagraph-distance)
4117 (set-marker to (woman-find-next-control-line-carefully))
4118 ))
4119
4120 ;; Format the paragraph body, if there is one! Set indented left
4121 ;; margin anyway, because the paragraph body may begin with a
4122 ;; control line:
4123 (setq left-margin (+ woman-left-margin i))
4124 (cond ((< (point) to)
4125 (woman2-format-paragraphs to)
4126 (goto-char tag) (end-of-line)
4127 (cond ((> (setq i (- left-margin (current-column))) 0)
4128 (delete-char 1)
4129 (delete-horizontal-space)
4130 ;; Necessary to avoid spaces inheriting underlines.
4131 ;; Cannot simply delete (current-column) whitespace
4132 ;; characters because some may be tabs!
4133 (while (> i 0) (insert ? ) (setq i (1- i)))))
4134 (goto-char to) ; necessary ???
4135 ))
4136 ))
4137
4138 (defun woman2-HP (to)
4139 ".HP i -- Set prevailing indent to i. Format paragraphs upto TO.
4140 Begin paragraph with hanging indent."
4141 (let ((i (woman2-get-prevailing-indent)))
4142 (woman-interparagraph-space)
4143 (setq woman-temp-indent woman-left-margin)
4144 (woman2-format-paragraphs to (+ woman-left-margin i))
4145 ))
4146
4147 (defun woman2-get-prevailing-indent (&optional leave-eol)
4148 "Set prevailing indent to integer argument at point, and return it.
4149 If no argument then return the existing prevailing indent.
4150 Delete line from point and eol unless LEAVE-EOL is non-nil."
4151 (if (eolp)
4152 (or leave-eol (delete-char 1))
4153 (let ((i (woman-get-numeric-arg)))
4154 (woman-delete-line) (or leave-eol (delete-char 1))
4155 ;; i = 0 if the argument was not a number
4156 (if (> i 0) (setq woman-prevailing-indent i))))
4157 woman-prevailing-indent)
4158
4159 (defmacro woman-push (value stack)
4160 "Push VALUE onto STACK."
4161 `(setq ,stack (cons ,value ,stack)))
4162
4163 (defmacro woman-pop (variable stack)
4164 "Pop into VARIABLE the value at the top of STACK.
4165 Allow for mismatched requests!"
4166 `(if ,stack
4167 (setq ,variable (car ,stack)
4168 ,stack (cdr ,stack))))
4169
4170 (defun woman2-RS (to)
4171 ".RS i -- Start relative indent, move left margin in distance i.
4172 Set prevailing indent to 5 for nested indents. Format paragraphs upto TO."
4173 (woman-push woman-left-margin woman-RS-left-margin)
4174 (woman-push woman-prevailing-indent woman-RS-prevailing-indent)
4175 (setq woman-left-margin (+ woman-left-margin
4176 (woman2-get-prevailing-indent))
4177 woman-prevailing-indent woman-default-indent)
4178 (woman2-format-paragraphs to woman-left-margin))
4179
4180 (defun woman2-RE (to)
4181 ".RE -- End of relative indent. Format paragraphs upto TO.
4182 Set prevailing indent to amount of starting .RS."
4183 (woman-pop woman-left-margin woman-RS-left-margin)
4184 (woman-pop woman-prevailing-indent woman-RS-prevailing-indent)
4185 (woman-delete-line 1) ; ignore any arguments
4186 (woman2-format-paragraphs to woman-left-margin))
4187
4188 \f
4189 ;;; Line Length and Indenting:
4190
4191 (defun woman-set-arg (arg &optional previous)
4192 "Reset, increment or decrement argument ARG, which must be quoted.
4193 If no argument then use value of optional arg PREVIOUS if non-nil,
4194 otherwise set PREVIOUS. Delete the whole remaining control line."
4195 (if (eolp) ; space already skipped
4196 (set arg (if previous (eval previous) 0))
4197 (if previous (set previous (eval arg)))
4198 (woman2-process-escapes-to-eol 'numeric)
4199 (let ((pm (if (looking-at "[+-]")
4200 (prog1 (following-char)
4201 (forward-char 1))))
4202 (i (woman-parse-numeric-arg)))
4203 (cond ((null pm) (set arg i))
4204 ((= pm ?+) (set arg (+ (eval arg) i)))
4205 ((= pm ?-) (set arg (- (eval arg) i)))
4206 ))
4207 (beginning-of-line))
4208 (woman-delete-line 1)) ; ignore any remaining arguments
4209
4210 ;; NEED TO RATIONALIZE NAMES FOR PREVIOUS VALUES!
4211 (defvar woman-ll-fill-column woman-fill-column)
4212 (defvar woman-in-left-margin woman-left-margin)
4213
4214 (defun woman2-ll (to)
4215 ".ll +/-N -- Set, increment or decrement line length.
4216 Format paragraphs upto TO. (Breaks, but should not.)"
4217 (woman-set-arg 'fill-column 'woman-ll-fill-column)
4218 (woman2-format-paragraphs to))
4219
4220 (defun woman2-in (to)
4221 ".in +/-N -- Set, increment or decrement the indent.
4222 Format paragraphs upto TO."
4223 (woman-set-arg 'left-margin 'woman-in-left-margin)
4224 (woman2-format-paragraphs to))
4225
4226 (defun woman2-ti (to)
4227 ".ti +/-N -- Temporary indent. Format paragraphs upto TO."
4228 ;; Ignore if no argument.
4229 ;; Indent next output line only wrt current indent.
4230 ;; Current indent is not changed.
4231 (setq woman-temp-indent left-margin)
4232 (woman-set-arg 'woman-temp-indent)
4233 (woman2-format-paragraphs to nil))
4234
4235 \f
4236 ;;; Tabs, Leaders, and Fields:
4237
4238 (defun woman2-ta (to)
4239 ".ta Nt ... -- Set tabs, left type, unless t=R(right), C(centered).
4240 \(Breaks, but should not.) The tab stops are separated by spaces\;
4241 a value preceded by + represents an increment to the previous stop value.
4242 Format paragraphs upto TO."
4243 (setq tab-stop-list nil)
4244 (woman2-process-escapes-to-eol 'numeric)
4245 (save-excursion
4246 (let ((tab-stop 0))
4247 (while (not (eolp))
4248 (let ((plus (cond ((eq (following-char) ?+) (forward-char 1) t)))
4249 (i (woman-parse-numeric-arg)))
4250 (setq tab-stop (if plus (+ tab-stop i) i)))
4251 (if (memq (following-char) '(?R ?C))
4252 (setq tab-stop (cons tab-stop (following-char))))
4253 (setq tab-stop-list (cons tab-stop tab-stop-list))
4254 (skip-syntax-forward "^ ") ; skip following R, C, `;', etc.
4255 (skip-chars-forward " \t")
4256 )))
4257 (woman-delete-line 1) ; ignore any remaining arguments
4258 (setq tab-stop-list (reverse tab-stop-list))
4259 (woman2-format-paragraphs to))
4260
4261 (defsubst woman-get-tab-stop (tab-stop-list)
4262 "If TAB-STOP-LIST is a cons, return its car, else return TAB-STOP-LIST."
4263 (if (consp tab-stop-list) (car tab-stop-list) tab-stop-list))
4264
4265 (defun woman-tab-to-tab-stop ()
4266 "Insert spaces to next defined tab-stop column.
4267 The variable `tab-stop-list' is a list whose elements are either left
4268 tab stop columns or pairs (COLUMN . TYPE) where TYPE is R or C."
4269 ;; Based on tab-to-tab-stop in indent.el.
4270 ;; R & C tabs probably not quite right!
4271 (delete-backward-char 1)
4272 (let ((tabs tab-stop-list))
4273 (while (and tabs (>= (current-column)
4274 (woman-get-tab-stop (car tabs))))
4275 (setq tabs (cdr tabs)))
4276 (if tabs
4277 (let* ((tab (car tabs))
4278 (type (and (consp tab) (cdr tab)))
4279 eol n)
4280 (if type
4281 (setq tab (woman-get-tab-stop tab)
4282 eol (save-excursion (end-of-line) (point))
4283 n (save-excursion
4284 (search-forward "\t" eol t))
4285 n (- (if n (1- n) eol) (point))
4286 tab (- tab (if (eq type ?C) (/ n 2) n))) )
4287 (setq n (- tab (current-column)))
4288 (while (> n 0)
4289 (insert ?\ )
4290 (setq n (1- n))))
4291 (insert ?\ ))))
4292
4293 (defun woman2-DT (to)
4294 ".DT -- Restore default tabs. Format paragraphs upto TO.
4295 \(Breaks, but should not.)"
4296 ;; Currently just terminates special tab processing.
4297 (setq tab-stop-list nil)
4298 (woman-delete-line 1) ; ignore any arguments
4299 (woman2-format-paragraphs to))
4300
4301 (defun woman2-fc (to)
4302 ".fc a b -- Set field delimiter a and pad character b.
4303 Format paragraphs upto TO.
4304 A VERY FIRST ATTEMPT to make fields at least readable!
4305 Needs doing properly!"
4306 (if (eolp)
4307 (woman-delete-whole-line) ; ignore!
4308 (let ((delim (following-char))
4309 (pad ?\ ) end) ; pad defaults to space
4310 (forward-char)
4311 (skip-chars-forward " \t")
4312 (or (eolp) (setq pad (following-char)))
4313 (woman-delete-whole-line)
4314 (save-excursion
4315 (if (re-search-forward "^[.'][ \t]*fc\\s " nil t)
4316 (setq end (match-beginning 0))))
4317 ;; A field is contained between a pair of field delimiter
4318 ;; characters and consists of sub-strings separated by padding
4319 ;; indicator characters:
4320 (setq delim (string delim ?[ ?^ delim ?] ?* delim))
4321 (save-excursion
4322 (while (re-search-forward delim end t)
4323 (goto-char (match-beginning 0))
4324 (delete-char 1)
4325 (insert woman-unpadded-space-char)
4326 (goto-char (match-end 0))
4327 (delete-backward-char 1)
4328 (insert-before-markers woman-unpadded-space-char)
4329 (subst-char-in-region
4330 (match-beginning 0) (match-end 0)
4331 pad woman-unpadded-space-char t)
4332 ))
4333 ))
4334 (woman2-format-paragraphs to))
4335
4336 \f
4337 ;;; WoMan message logging:
4338
4339 ;; The basis for this logging code was shamelessly pirated from bytecomp.el
4340 ;; by Jamie Zawinski <jwz@lucid.com> & Hallvard Furuseth <hbf@ulrik.uio.no>
4341
4342 (defvar WoMan-current-file nil) ; bound in woman-really-find-file
4343 (defvar WoMan-Log-header-point-max nil)
4344
4345 (defun WoMan-log-begin ()
4346 "Log the beginning of formatting in *WoMan-Log*."
4347 (let ((WoMan-current-buffer (buffer-name)))
4348 (save-excursion
4349 (set-buffer (get-buffer-create "*WoMan-Log*"))
4350 (or (eq major-mode 'view-mode) (view-mode 1))
4351 (setq buffer-read-only nil)
4352 (goto-char (point-max))
4353 (insert "\n\^L\nFormatting "
4354 (if (stringp WoMan-current-file)
4355 (concat "file " WoMan-current-file)
4356 (concat "buffer " WoMan-current-buffer))
4357 " at " (current-time-string) "\n")
4358 (setq WoMan-Log-header-point-max (point-max))
4359 )))
4360
4361 (defun WoMan-log (format &rest args)
4362 "Log a message out of FORMAT control string and optional ARGS."
4363 (WoMan-log-1 (apply 'format format args)))
4364
4365 (defun WoMan-warn (format &rest args)
4366 "Log a warning message out of FORMAT control string and optional ARGS."
4367 (setq format (apply 'format format args))
4368 (WoMan-log-1 (concat "** " format)))
4369
4370 (defun WoMan-warn-ignored (request ignored)
4371 "Log a warning message about ignored directive REQUEST.
4372 IGNORED is a string appended to the log message."
4373 (let ((tail
4374 (buffer-substring (point)
4375 (save-excursion (end-of-line) (point)))))
4376 (if (and (> (length tail) 0)
4377 (/= (string-to-char tail) ?\ ))
4378 (setq tail (concat " " tail)))
4379 (WoMan-log-1
4380 (concat "** " request tail " request " ignored))))
4381
4382 (defun WoMan-log-end (time)
4383 "Log the end of formatting in *WoMan-Log*.
4384 TIME specifies the time it took to format the man page, to be printed
4385 with the message."
4386 (WoMan-log-1 (format "Formatting time %d seconds." time) 'end))
4387
4388 (defun WoMan-log-1 (string &optional end)
4389 "Log a message STRING in *WoMan-Log*.
4390 If optional argument END is non-nil then make buffer read-only after
4391 logging the message."
4392 (save-excursion
4393 (set-buffer (get-buffer-create "*WoMan-Log*"))
4394 (goto-char (point-max))
4395 (or end (insert " ")) (insert string "\n")
4396 (if end
4397 (setq buffer-read-only t)
4398 (if woman-show-log
4399 (select-window ; to return to
4400 (prog1 (selected-window) ; WoMan window
4401 (select-window (display-buffer (current-buffer)))
4402 (cond (WoMan-Log-header-point-max
4403 (goto-char WoMan-Log-header-point-max)
4404 (forward-line -1)
4405 (recenter 0)))
4406 )))))
4407 nil) ; for woman-file-readable-p etc.
4408
4409 (provide 'woman)
4410
4411 ;; RECENT CHANGE LOG
4412 ;; =================
4413
4414 ;; Changes in version 0.50 ([*] => user interface change)
4415 ;; [*] Requires GNU Emacs 20.3+.
4416 ;; [*] `defface' used to define faces.
4417 ;; [*] Follow `see also' references with mouse-2 click.
4418 ;; Number register increment support added (woman-registers).
4419 ;; .j must be a NUMBER acceptable by .ad request.
4420 ;; Very crude field support added.
4421 ;; Vertical unit specifier `v' added to register handling.
4422 ;; Improvement to local horizontal motion processing.
4423 ;; Minor fix to handle negative numeric arguments.
4424 ;; Handle horizontal motion escapes `\h' better.
4425 ;; Allow arbitrary delimiters in `.if', inc. special character escapes.
4426 ;; Allow `\n' within `.if' string comparisons.
4427 ;; Allow arbitrary delimiters in `\w', inc. special character escapes.
4428 ;; Processing of `\h' moved much later -- after indenting etc!
4429
4430 ;; Changes in version 0.51 ([*] => user interface change)
4431 ;; [*] Improved handling of underlined faces (mainly for "italics").
4432 ;; [*] Allow environment variables in directory path elements.
4433 ;; Display of pre-formatted files improved.
4434 ;; [*] Unintentional interaction with standard Man mode reduced.
4435 ;; [*] bzip2 decompression support added. All decompression now
4436 ;; works by turning on `auto-compression-mode' to decompress the
4437 ;; file if necessary, rather than decompressing explicitly.
4438 ;; Filename and compression regexps are now customizable user
4439 ;; options.
4440
4441 ;; Changes in version 0.52 ([*] => user interface change)
4442 ;; Speeded up handling of underlined faces (mainly for "italics").
4443 ;; [*] WoMan formatting time display and log added. Emacs `man'
4444 ;; formatting time display advice added. (This suggests that
4445 ;; WoMan formatting is faster than Emacs `man' *formatting*,
4446 ;; i.e. when man is not using `catman' caching. E.g. `woman
4447 ;; bash' takes 27s whereas `man bash' takes 35s and for smaller
4448 ;; files `woman' can be relatively much faster than `man'.)
4449 ;; [*] Experimental support for non-ASCII characters from the
4450 ;; default and symbol fonts added, initially only for MS-Windows.
4451 ;; NOTE: It is off by default, mainly because it may increase the
4452 ;; line spacing; customize `woman-use-symbols' to `on' to use it.
4453 ;; Pad character handling for .fc fixed.
4454 ;; Tested: see `woman.status'.
4455
4456 ;; Changes in version 0.53 ([*] => user interface change)
4457 ;; [*] Customization option to use a separate frame for WoMan windows.
4458 ;; [*] Experimental option to emulate nroff (default) or troff (not tested).
4459 ;; [*] Separation of extended and symbol font options.
4460 ;; Only symbol font size 16 seems to work, and only with Win 95, not NT!
4461 ;; [*] `Advanced' sub-menu containing:
4462 ;; `View Source' option;
4463 ;; `Show Log' option;
4464 ;; `Extended Font' toggle and reformat;
4465 ;; `Symbol Font' toggle and reformat;
4466 ;; `Font Map' option;
4467 ;; `Emulation' radio buttons.
4468 ;; [*] Support for man config file added for default manpath.
4469
4470 ;; Changes in version 0.54
4471 ;; Revised for distribution with Emacs 21.
4472 ;; Comment order and doc strings changed substantially.
4473 ;; MS-DOS support added (by Eli Zaretskii).
4474 ;; checkdoc run: no real errors.
4475 ;; woman topic interface speeded up.
4476
4477 ;;; woman.el ends here