Function: erc-process-script-line
erc-process-script-line is a byte-compiled function defined in
erc.el.gz.
Signature
(erc-process-script-line LINE &optional ARGS)
Documentation
Process an IRC script LINE.
Does script-specific substitutions (script arguments, current nick, server, etc.) in LINE and returns it.
Substitutions are: %C and %c = current target (channel or nick),
%S %s = current server, %N %n = my current nick, and %x is x verbatim,
where x is any other character;
$* = the entire argument string, $1 = the first argument, $2 = the second,
and so on.
Source Code
;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc-process-script-line (line &optional args)
"Process an IRC script LINE.
Does script-specific substitutions (script arguments, current nick,
server, etc.) in LINE and returns it.
Substitutions are: %C and %c = current target (channel or nick),
%S %s = current server, %N %n = my current nick, and %x is x verbatim,
where x is any other character;
$* = the entire argument string, $1 = the first argument, $2 = the second,
and so on."
(if (not args) (setq args ""))
(let* ((arg-esc-regexp "\\(\\$\\(\\*\\|[1-9][0-9]*\\)\\)\\([^0-9]\\|$\\)")
(percent-regexp "\\(%.\\)")
(esc-regexp (concat arg-esc-regexp "\\|" percent-regexp))
(tgt (erc-default-target))
(server (and (boundp 'erc-session-server) erc-session-server))
(nick (erc-current-nick))
(res "")
(tmp nil)
(arg-list nil)
(arg-num 0))
(if (not tgt) (setq tgt ""))
(if (not server) (setq server ""))
(if (not nick) (setq nick ""))
;; First, compute the argument list
(setq tmp args)
(while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" tmp)
(setq arg-list (cons (match-string 1 tmp) arg-list))
(setq tmp (match-string 2 tmp)))
(setq arg-list (nreverse arg-list))
(setq arg-num (length arg-list))
;; now do the substitution
(setq tmp (string-match esc-regexp line))
(while tmp
;;(message "beginning of while: tmp=%S" tmp)
(let* ((hd (substring line 0 tmp))
(esc "")
(subst "")
(tail (substring line tmp)))
(cond ((string-match (concat "^" arg-esc-regexp) tail)
(setq esc (match-string 1 tail))
(setq tail (substring tail (match-end 1))))
((string-match (concat "^" percent-regexp) tail)
(setq esc (match-string 1 tail))
(setq tail (substring tail (match-end 1)))))
;;(message "hd=%S, esc=%S, tail=%S, arg-num=%S" hd esc tail arg-num)
(setq res (concat res hd))
(setq subst
(cond ((string= esc "") "")
((string-match "^\\$\\*$" esc) args)
((string-match "^\\$\\([0-9]+\\)$" esc)
(let ((n (string-to-number (match-string 1 esc))))
(message "n = %S, integerp(n)=%S" n (integerp n))
(if (<= n arg-num) (nth (1- n) arg-list) "")))
((string-match "^%[Cc]$" esc) tgt)
((string-match "^%[Ss]$" esc) server)
((string-match "^%[Nn]$" esc) nick)
((string-match "^%\\(.\\)$" esc) (match-string 1 esc))
(t (erc-log (format "BUG in erc-process-script-line: bad escape sequence: %S\n" esc))
(message "BUG IN ERC: esc=%S" esc)
"")))
(setq line tail)
(setq tmp (string-match esc-regexp line))
(setq res (concat res subst))
;;(message "end of while: line=%S, res=%S, tmp=%S" line res tmp)
))
(setq res (concat res line))
res))