unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#51082: [PATCH] erc-prompt: support substitution patterns "%target" and "%network"
@ 2021-10-07 13:05 Stefan Kangas
  2021-10-09  0:53 ` Amin Bandali
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Stefan Kangas @ 2021-10-07 13:05 UTC (permalink / raw)
  To: 51082; +Cc: emacs-erc, Amin Bandali

[-- Attachment #1: Type: text/plain, Size: 267 bytes --]

Severity: wishlist

The attached patch adds substitution patterns "%target" and "%network"
so you can do stuff like

    (setq erc-prompt "[%target]")
    (setq erc-prompt "[%target@%network]")

to get prompts that looks like this:

    [#erc]
    [#erc@Libera.Chat]

[-- Attachment #2: 0001-Support-two-substitution-patterns-in-erc-prompt.patch --]
[-- Type: text/x-diff, Size: 2379 bytes --]

From d6ac0356afa366276f1a0be26b81cf2d4b076b8d Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
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) <defun>: Use the above new function.
(erc-prompt) <defcustom>: 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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-15  1:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-07 13:05 bug#51082: [PATCH] erc-prompt: support substitution patterns "%target" and "%network" Stefan Kangas
2021-10-09  0:53 ` Amin Bandali
     [not found] ` <871r4vc92w.fsf@gnu.org>
2021-10-09  8:03   ` J.P.
2022-09-10  5:20 ` Lars Ingebrigtsen
2023-11-20 21:17 ` J.P.
     [not found] ` <875y1wi0q2.fsf@neverwas.me>
2023-11-20 21:22   ` J.P.
2023-11-22 19:25   ` J.P.
     [not found]   ` <87pm01d1yy.fsf@neverwas.me>
2023-11-24 22:12     ` J.P.
     [not found]     ` <87plzy2433.fsf@neverwas.me>
2023-12-15  1:18       ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).