Function: woman-decode-region
woman-decode-region is a byte-compiled function defined in
woman.el.gz.
Signature
(woman-decode-region FROM TO)
Documentation
Decode the region between FROM and TO in UN*X man-page source format.
Source Code
;; Defined in /usr/src/emacs/lisp/woman.el.gz
(defun woman-decode-region (from _to)
"Decode the region between FROM and TO in UN*X man-page source format."
;; Suitable for use in format-alist.
;; But this requires care to control major mode implied font locking.
;; Must return the new end of file. See format.el for details.
;; NB: The `to' argument is bogus: it is not currently used, and if
;; it were it would need to be a marker rather than a position!
;; First force the correct environment:
(let ((case-fold-search nil) ; This is necessary!
(woman-string-alist woman-string-alist)
(woman-fill-column woman-fill-column)
woman-negative-vertical-space)
(setq woman-left-margin woman-default-indent
woman-prevailing-indent woman-default-indent
woman-interparagraph-distance 1
woman-leave-blank-lines nil
woman-RS-left-margin nil
woman-RS-prevailing-indent nil
woman-adjust woman-adjust-both
woman-justify (aref woman-justify-styles woman-adjust)
woman-nofill nil)
(setq woman-if-conditions-true
(cons (string-to-char (symbol-name woman-emulation)) '(?e ?o)))
;; Prepare non-underlined versions of underlined faces:
(woman-non-underline-faces)
;; Set font of `woman-symbol' face to `woman-symbol-font' if
;; `woman-symbol-font' is well defined.
(and woman-use-symbol-font
(stringp woman-symbol-font)
(set-face-font 'woman-symbol woman-symbol-font
(and (frame-live-p woman-frame) woman-frame)))
(setq-local adaptive-fill-mode nil) ; No special "%" "#" etc filling.
;; Set syntax and display tables:
(set-syntax-table woman-syntax-table)
(woman-set-buffer-display-table)
;; Based loosely on a suggestion by Theodore Jump:
(if (or woman-fill-frame
(not (and (integerp woman-fill-column) (> woman-fill-column 0))))
(setq woman-fill-column (- (window-width) woman-default-indent)))
;; Check for preprocessor requests:
(goto-char from)
(if (looking-at "'\\\\\"[ \t]*\\([a-z]+\\)")
(let ((letters (append (match-string 1) nil)))
(if (memq ?t letters)
(setq woman-emulate-tbl t
letters (delete ?t letters)))
(if letters
(WoMan-warn "Unhandled preprocessor request letters %s"
(concat letters)))
(woman-delete-line 1)))
(woman-pre-process-region from nil)
;; Process ignore requests, macro definitions,
;; conditionals and switch source requests:
(woman0-roff-buffer from)
;; Check for macro sets that woman cannot handle. We can only
;; because do this after processing source-switch directives.
(goto-char (point-min))
(let ((case-fold-search nil))
(unless (and (re-search-forward "^\\.SH[ \n]" (point-max) t)
(progn (goto-char (point-min))
(re-search-forward "^\\.TH[ \n]" (point-max) t))
(progn (goto-char (point-min))
(not (re-search-forward "^\\.\\([pnil]p\\|sh\\)[ \n]"
(point-max) t))))
(error "WoMan can only format man pages written with the usual `-man' macros")))
;; Process \k escapes BEFORE changing tab width (?):
(goto-char from)
(woman-mark-horizontal-position)
;; Set buffer-local variables:
(setq fill-column woman-fill-column
tab-width woman-tab-width)
;; Ignore the \, and \/ kerning operators. See
;; https://www.gnu.org/software/groff/manual/groff.html#Ligatures-and-Kerning
(goto-char (point-min))
(while (re-search-forward "\\\\[,/]" nil t)
(replace-match "" t t))
;; Hide unpaddable and digit-width spaces \(space) and \0:
(goto-char from)
(while (re-search-forward "\\\\[ 0]" nil t)
(replace-match woman-unpadded-space-string t t))
;; Discard optional hyphen \%; concealed newlines \<newline>;
;; kerning \/, \,; point-size change function \sN,\s+N, \s-N:
(goto-char from)
(while (re-search-forward "\\\\\\([%\n/,]\\|s[-+]?[0-9]+\\)" nil t)
(woman-delete-match 0))
;; BEWARE: THIS SHOULD PROBABLY ALL BE DONE MUCH LATER!!!!!
;; Process trivial escapes \-, \`, \.
;; (\' must be done after tab processing!):
(goto-char from)
(while (re-search-forward "\\\\\\([-`.]\\)" nil t)
(replace-match "\\1"))
;; NB: Must keep ALL zero-width characters \&, \|, and \^ until
;; ALL requests processed!
;; Process no-break requests and macros (including font-change macros):
(goto-char from)
(woman1-roff-buffer)
;; Process strings and special character escapes \(xx:
;; (Must do this BEFORE fontifying!)
(goto-char from)
(woman-strings)
;; Special chars moved after translation in
;; `woman2-process-escapes' (for pic.1):
; (goto-char from)
; (woman-special-characters)
;; Process standard font-change requests and escapes:
(goto-char from)
(woman-change-fonts)
;; 1/2 em vertical motion \d, \u and general local vertical motion
;; \v'+/-N' simulated using TeX ^ and _ symbols for now.
(goto-char from)
(let ((first t)) ; assume no nesting!
(while (re-search-forward "\\\\\\([du]\\|v'[^']*'\\)" nil t)
(let* ((esc (match-string 1))
(repl (if (or (= (aref esc 0) ?u)
(and (>= (length esc) 2) (= (aref esc 2) ?-)))
"^" "_")))
(cond (first
(replace-match repl nil t)
(put-text-property (1- (point)) (point) 'face 'woman-addition)
(WoMan-warn
"Initial vertical motion escape \\%s simulated" esc)
(WoMan-log
" by TeX `%s' in woman-addition-face!" repl))
(t
(woman-delete-match 0)
(WoMan-warn
"Terminal vertical motion escape \\%s ignored!" esc)))
(setq first (not first)))))
;; Process formatting macros
(goto-char from)
(woman2-roff-buffer)
;; Go back and process negative vertical space if necessary:
(if woman-negative-vertical-space
(woman-negative-vertical-space from))
(when woman-preserve-ascii
;; Re-instate escaped escapes to just `\' and unpaddable spaces
;; to just `space'. This is not necessary for display since
;; there are display table entries for the escaped chars, but it
;; is necessary if the buffer might be saved as ASCII.
;;
;; `subst-char-in-region' preserves text properties on the
;; characters, which is necessary for bold, underline, etc on
;; \e. There's usually no face on spaces, but if there is then
;; it's good to keep that too.
(subst-char-in-region from (point-max)
woman-escaped-escape-char ?\\)
(subst-char-in-region from (point-max)
woman-unpadded-space-char ?\s))
;; Must return the new end of file if used in format-alist.
(point-max)))