From d6ac0356afa366276f1a0be26b81cf2d4b076b8d Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Thu, 7 Oct 2021 14:26:36 +0200 Subject: [PATCH] Support two substitution patterns in erc-prompt * lisp/erc/erc.el (erc-prompt--subsitutions): New function to support substitution patters "%target" and "%network". (erc-prompt) : Use the above new function. (erc-prompt) : Document the new substitution patterns. --- lisp/erc/erc.el | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 308812f0eb..aa5002c2ea 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -640,17 +640,44 @@ erc-string-no-properties newstring)) (defcustom erc-prompt "ERC>" - "Prompt used by ERC. Trailing whitespace is not required." + "Prompt used by ERC. Trailing whitespace is not required. + +You can also use these substitution patterns: + \"%target\" - channel, user, or server + \"%network\" - IRC network" :group 'erc-display :type '(choice string function)) +(defun erc-prompt--subsitutions (prompt) + "Make \"%target\" substitutions in PROMPT. + +See also the variable `erc-prompt'." + (while (string-match (rx "%" (or "target" + "network" + ;; "modes" + )) + prompt) + (setq prompt + (replace-match + (pcase (match-string 0 prompt) + ("%target" (or (erc-format-target) + (erc-format-target-and/or-server) + "ERC")) + ("%network" (and (fboundp 'erc-network-name) (erc-network-name))) + ;; TODO: Maybe have one variable for the prompt in the + ;; server window and one for channels and queries? + ;;("%modes" (erc-format-channel-modes)) + (_ "")) + nil nil prompt 0))) + prompt) + (defun erc-prompt () "Return the input prompt as a string. See also the variable `erc-prompt'." (let ((prompt (if (functionp erc-prompt) (funcall erc-prompt) - erc-prompt))) + (erc-prompt--subsitutions erc-prompt)))) (if (> (length prompt) 0) (concat prompt " ") prompt))) -- 2.30.2