Function: woman-interpolate-macro

woman-interpolate-macro is a byte-compiled function defined in woman.el.gz.

Signature

(woman-interpolate-macro MACRO)

Documentation

Interpolate (.de) or append (.am) expansion of MACRO into the buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/woman.el.gz
(defun woman-interpolate-macro (macro)
  "Interpolate (.de) or append (.am) expansion of MACRO into the buffer."
  ;; Could make this more efficient by checking which arguments are
  ;; actually used in the expansion!
  (skip-chars-forward " \t")
  ;; Process arguments:
  (let ((argno 0) (append (car macro))
	argno-string formal-arg from actual-arg start)
    (setq macro (cdr macro))
    (while (not (eolp))
      ;; Get next actual arg:
      (setq argno (1+ argno))
      (setq argno-string (format "%d" argno))
      (setq formal-arg (concat "\\\\\\$" argno-string)) ; regexp
      (setq from (point))
      (woman-forward-arg 'unquote 'noskip)
      (setq actual-arg (buffer-substring from (point)))
      (skip-chars-forward " \t")  ; now skip following whitespace!
      ;; Replace formal arg with actual arg:
      (setq start nil)
      (while (setq start (string-match formal-arg macro start))
	(setq macro (replace-match actual-arg t t macro))))
    ;; Delete any remaining formal arguments:
    (setq start nil)
    (while
	(setq start (string-match "\\\\\\$." macro start))
      (setq macro (replace-match "" t t macro)))
    ;; Replace .$ number register with actual arg:
    ;; (Do this properly via register mechanism later!)
    (setq start nil)
    (while
	(setq start (string-match "\\\\n(\\.\\$" macro start)) ; regexp
      (setq macro (replace-match argno-string t t macro)))
    (if append
	(forward-char)
      (beginning-of-line)
      (woman-delete-line 1))
    (save-excursion			; leave point at start of new text
      (insert macro))))