Function: erc-extract-command-from-line

erc-extract-command-from-line is a byte-compiled function defined in erc.el.gz.

Signature

(erc-extract-command-from-line LINE)

Documentation

Extract a "slash command" and its args from a prompt-input LINE.

If LINE doesn't start with a slash command, return nil. If it does, meaning the pattern erc-command-regexp matches, return a list of the form (COMMAND ARGS), where COMMAND is either a symbol for a known handler function or erc-cmd-default if unknown. When COMMAND has the symbol property do-not-parse-args, return a string in place of ARGS: that is, either LINE itself, when LINE consists of only whitespace, or LINE stripped of any trailing whitespace, including a final newline. When COMMAND lacks the symbol property do-not-parse-args, return a possibly empty list of non-whitespace tokens. Do not perform any shell-style parsing of quoted or escaped substrings.

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc-extract-command-from-line (line)
  "Extract a \"slash command\" and its args from a prompt-input LINE.
If LINE doesn't start with a slash command, return nil.  If it
does, meaning the pattern `erc-command-regexp' matches, return a
list of the form (COMMAND ARGS), where COMMAND is either a symbol
for a known handler function or `erc-cmd-default' if unknown.
When COMMAND has the symbol property `do-not-parse-args', return
a string in place of ARGS: that is, either LINE itself, when LINE
consists of only whitespace, or LINE stripped of any trailing
whitespace, including a final newline.  When COMMAND lacks the
symbol property `do-not-parse-args', return a possibly empty list
of non-whitespace tokens.  Do not perform any shell-style parsing
of quoted or escaped substrings."
  (when (string-match erc-command-regexp line)
    (let* ((cmd (erc-command-symbol (match-string 1 line)))
           ;; note: return is nil, we apply this simply for side effects
           (_canon-defun (while (and cmd (symbolp (symbol-function cmd)))
                           (setq cmd (symbol-function cmd))))
           (cmd-fun (or cmd #'erc-cmd-default))
           (arg (if cmd
                    (if (get cmd-fun 'do-not-parse-args)
                        (format "%s" (match-string 2 line))
                      (delete "" (split-string (erc-trim-string
                                                (match-string 2 line)) " ")))
                  line)))
      (list cmd-fun arg))))