Function: woman-horizontal-escapes

woman-horizontal-escapes is a byte-compiled function defined in woman.el.gz.

Signature

(woman-horizontal-escapes TO)

Documentation

Process \h'+/-N' local horizontal motion escapes up to TO.

Implements arbitrary forward and non-overlapping backward motion. Preserves location of point.

Source Code

;; Defined in /usr/src/emacs/lisp/woman.el.gz
(defun woman-horizontal-escapes (to)
  "Process \\h'+/-N' local horizontal motion escapes up to TO.
Implements arbitrary forward and non-overlapping backward motion.
Preserves location of `point'."
  ;; Moved from `woman-decode-region' for version 0.50.
  ;; N may include width escape \w'...' (but may already be processed!
  (let ((from (point)))
    (while (re-search-forward
	    ;; Delimiter can be a special char escape sequence \(.. or
	    ;; a single normal char (usually '):
	    "\\\\h\\(\\\\(..\\|.\\)\\(|\\)?"
	    to t)
      (let ((from (match-beginning 0))
	    (delim (regexp-quote (match-string 1)))
	    (absolute (match-beginning 2)) ; absolute position?
	    (N (woman-parse-numeric-arg)) ; distance
	    to
	    msg)			; for warning
	(if (not (looking-at delim))
	    ;; Warn but leave escape in buffer unprocessed:
	    (WoMan-warn
	     "Local horizontal motion (%s) delimiter error!"
	     (buffer-substring from (1+ (point)))) ; point at end of arg
	  (setq to (match-end 0)
		;; For possible warning -- save before deleting:
		msg (buffer-substring from to))
	  (delete-region from to)
	  (if absolute			; make relative
	      (setq N (- N (current-column))))
	  (if (>= N 0)
	      ;; Move forward by inserting hard spaces:
	      (insert-char woman-unpadded-space-char N)
	    ;; Move backwards by deleting space,
	    ;; first backwards then forwards:
	    (while (and
		    (<= (setq N (1+ N)) 0)
		    (cond ((memq (preceding-char) '(?\s ?\t))
			   (delete-char -1) t)
			  ((memq (following-char) '(?\s ?\t))
			   (delete-char 1) t)
			  (t nil))))
	    (if (<= N 0)
		(WoMan-warn
		 "Negative horizontal motion (%s) would overwrite!" msg))))))
    (goto-char from)))