Function: erc-parse-modes
erc-parse-modes is a byte-compiled function defined in erc.el.gz.
Signature
(erc-parse-modes MODE-STRING)
Documentation
Parse MODE-STRING into a list.
Returns a list of three elements:
(ADD-MODES REMOVE-MODES ARG-MODES).
The add-modes and remove-modes are lists of single-character strings for modes without parameters to add and remove respectively. The arg-modes is a list of triples of the form:
(MODE-CHAR ON/OFF ARGUMENT).
Source Code
;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc-parse-modes (mode-string)
"Parse MODE-STRING into a list.
Returns a list of three elements:
(ADD-MODES REMOVE-MODES ARG-MODES).
The add-modes and remove-modes are lists of single-character strings
for modes without parameters to add and remove respectively. The
arg-modes is a list of triples of the form:
(MODE-CHAR ON/OFF ARGUMENT)."
(if (string-match "^\\s-*\\(\\S-+\\)\\(\\s-.*$\\|$\\)" mode-string)
(let ((chars (mapcar #'char-to-string (match-string 1 mode-string)))
;; arguments in channel modes
(args-str (match-string 2 mode-string))
(args nil)
(add-modes nil)
(remove-modes nil)
(arg-modes nil); list of triples: (mode-char 'on/'off argument)
(add-p t))
;; make the argument list
(while (string-match "^\\s-*\\(\\S-+\\)\\(\\s-+.*$\\|$\\)" args-str)
(setq args (cons (match-string 1 args-str) args))
(setq args-str (match-string 2 args-str)))
(setq args (nreverse args))
;; collect what modes changed, and match them with arguments
(while chars
(cond ((string= (car chars) "+") (setq add-p t))
((string= (car chars) "-") (setq add-p nil))
((string-match "^[qaovhbQAOVHB]" (car chars))
(setq arg-modes (cons (list (car chars)
(if add-p 'on 'off)
(if args (car args) nil))
arg-modes))
(if args (setq args (cdr args))))
((string-match "^[LlKk]" (car chars))
(setq arg-modes (cons (list (car chars)
(if add-p 'on 'off)
(if (and add-p args)
(car args) nil))
arg-modes))
(if (and add-p args) (setq args (cdr args))))
(add-p (setq add-modes (cons (car chars) add-modes)))
(t (setq remove-modes (cons (car chars) remove-modes))))
(setq chars (cdr chars)))
(setq add-modes (nreverse add-modes))
(setq remove-modes (nreverse remove-modes))
(setq arg-modes (nreverse arg-modes))
(list add-modes remove-modes arg-modes))
nil))