Subject: bug#68401: 30.0.50; ERC 5.6-git: `erc-cmd-GMSG', `erc-cmd-AMSG', `erc-cmd-GME', `erc-cmd-AME'. 2nd attempt

From: Emanuel Berg <[email-masked]>
Date: Tue, 23 Jan 2024 07:20:34 +0100

>>>> (defun erc-drop-leading-whitespace (str)
>>>>   (if (string-match "^ \\(.*\\)$" str)
>>>>       (match-string 1 str)
>>>>     str) )
>>>
>>> Why not use `string-prefix-p' and `substring' to
>>> accomplish this? Also, please name this using the internal
>>> "--" convention, something like
>>> `erc--drop-initial-space-char' or
>>> `erc--drop-single-leading-space'.
>>
>> Good idea to use `string-prefix-p' and `substring', but it
>> hasn't anything to do with ERC at this point - it should be
>> put in some string manipulation library and then ERC should
>> `require' it. [...]

Someone told me (thanks) there is already
a `string-remove-prefix' to do this so that whole thing can
be dropped.

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/erc/erc-misc.el
;;
;; Make erc-cmd-AMSG session-local, add /GMSG /AME /GME
;;
;; * lisp/erc/erc.el (erc-cmd-AMSG): Make good on behavior described in
;; the doc string by limiting damage to the current connection.
;; (erc-cmd-GMSG, erc-cmd-GME, erc-cmd-AME): New functions, all IRC
;; "slash commands". (Bug#68401)

(require 'erc)

(defun erc--connected-and-joined-p ()
  (and (erc--current-buffer-joined-p)
       erc-server-connected))

(defun erc-cmd-GMSG (line)
  "Send LINE to all channels on all networks you are on."
  (setq line (string-remove-prefix " " line))
  (erc-with-all-buffers-of-server nil
      (lambda () (erc-channel-p (erc-default-target)))
    (when (erc--connected-and-joined-p)
      (erc-send-message line))))
(put 'erc-cmd-GMSG 'do-not-parse-args t)

(defun erc-cmd-AMSG (line)
  "Send LINE to all channels of the current network.
Interactively, prompt for the line of text to send."
  (interactive "sSend to all channels on this network: ")
  (setq line (string-remove-prefix " " line))
  (erc-with-all-buffers-of-server erc-server-process
      (lambda () (erc-channel-p (erc-default-target)))
    (when (erc--connected-and-joined-p)
      (erc-send-message line))))
(put 'erc-cmd-AMSG 'do-not-parse-args t)

(defun erc-cmd-GME (line)
  "Send LINE as an action to all channels on all networks you are on."
  (erc-with-all-buffers-of-server nil
      (lambda () (erc-channel-p (erc-default-target)))
    (when (erc--connected-and-joined-p)
      (erc-cmd-ME line))))
(put 'erc-cmd-GME 'do-not-parse-args t)

(defun erc-cmd-AME (line)
  "Send LINE as an action to all channels on the current network."
  (erc-with-all-buffers-of-server erc-server-process
      (lambda () (erc-channel-p (erc-default-target)))
    (when (erc--connected-and-joined-p)
      (erc-cmd-ME line))))
(put 'erc-cmd-AME 'do-not-parse-args t)

(provide 'erc-misc)

-- 
underground experts united
https://dataswamp.org/~incal