* lisp/erc/erc.el: Use run-hook-with-args for erc-pre-send-functions

(erc-process-input-line): A function can be `listp`.
(erc-send-input): Use `run-hook-with-args` for `erc-pre-send-functions`.
(erc-display-command): Comment out, unused.
This commit is contained in:
Stefan Monnier 2021-01-04 00:21:02 -05:00
parent 535a25164b
commit 0c599ee2e2

View file

@ -1046,8 +1046,8 @@ anyway."
(make-obsolete-variable 'erc-send-pre-hook 'erc-pre-send-functions "27.1") (make-obsolete-variable 'erc-send-pre-hook 'erc-pre-send-functions "27.1")
(defcustom erc-pre-send-functions nil (defcustom erc-pre-send-functions nil
"List of functions called to possibly alter the string that is sent. "Special hook run to possibly alter the string that is sent.
The functions are called with one argument, a `erc-input' struct, The functions are called with one argument, an `erc-input' struct,
and should alter that struct. and should alter that struct.
The struct has three slots: The struct has three slots:
@ -1056,7 +1056,7 @@ The struct has three slots:
`insertp': Whether the string should be inserted into the erc buffer. `insertp': Whether the string should be inserted into the erc buffer.
`sendp': Whether the string should be sent to the irc server." `sendp': Whether the string should be sent to the irc server."
:group 'erc :group 'erc
:type '(repeat function) :type 'hook
:version "27.1") :version "27.1")
(defvar erc-insert-this t (defvar erc-insert-this t
@ -1295,9 +1295,9 @@ Example:
(define-erc-module replace nil (define-erc-module replace nil
\"This mode replaces incoming text according to `erc-replace-alist'.\" \"This mode replaces incoming text according to `erc-replace-alist'.\"
((add-hook \\='erc-insert-modify-hook ((add-hook \\='erc-insert-modify-hook
\\='erc-replace-insert)) #\\='erc-replace-insert))
((remove-hook \\='erc-insert-modify-hook ((remove-hook \\='erc-insert-modify-hook
\\='erc-replace-insert)))" #\\='erc-replace-insert)))"
(declare (doc-string 3)) (declare (doc-string 3))
(let* ((sn (symbol-name name)) (let* ((sn (symbol-name name))
(mode (intern (format "erc-%s-mode" (downcase sn)))) (mode (intern (format "erc-%s-mode" (downcase sn))))
@ -1495,7 +1495,7 @@ Defaults to the server buffer."
(setq-local paragraph-start (setq-local paragraph-start
(concat "\\(" (regexp-quote (erc-prompt)) "\\)")) (concat "\\(" (regexp-quote (erc-prompt)) "\\)"))
(setq-local completion-ignore-case t) (setq-local completion-ignore-case t)
(add-hook 'completion-at-point-functions 'erc-complete-word-at-point nil t)) (add-hook 'completion-at-point-functions #'erc-complete-word-at-point nil t))
;; activation ;; activation
@ -2585,7 +2585,7 @@ This function adds `erc-lurker-update-status' to
most recent PRIVMSG as well as initializing the state variable most recent PRIVMSG as well as initializing the state variable
storing this information." storing this information."
(setq erc-lurker-state (make-hash-table :test 'equal)) (setq erc-lurker-state (make-hash-table :test 'equal))
(add-hook 'erc-insert-pre-hook 'erc-lurker-update-status)) (add-hook 'erc-insert-pre-hook #'erc-lurker-update-status))
(defun erc-lurker-cleanup () (defun erc-lurker-cleanup ()
"Remove all last PRIVMSG state older than `erc-lurker-threshold-time'. "Remove all last PRIVMSG state older than `erc-lurker-threshold-time'.
@ -2694,7 +2694,7 @@ otherwise `erc-server-announced-name'. SERVER is matched against
(defun erc-add-targets (scope target-list) (defun erc-add-targets (scope target-list)
(let ((targets (let ((targets
(mapcar (lambda (targets) (member scope targets)) target-list))) (mapcar (lambda (targets) (member scope targets)) target-list)))
(cdr (apply 'append (delete nil targets))))) (cdr (apply #'append (delete nil targets)))))
(defun erc-hide-current-message-p (parsed) (defun erc-hide-current-message-p (parsed)
"Predicate indicating whether the parsed ERC response PARSED should be hidden. "Predicate indicating whether the parsed ERC response PARSED should be hidden.
@ -2821,9 +2821,9 @@ this function from interpreting the line as a command."
(let* ((cmd (nth 0 command-list)) (let* ((cmd (nth 0 command-list))
(args (nth 1 command-list))) (args (nth 1 command-list)))
(condition-case nil (condition-case nil
(if (listp args) (if (functionp args)
(apply cmd args) (funcall cmd args)
(funcall cmd args)) (apply cmd args))
(wrong-number-of-arguments (wrong-number-of-arguments
(erc-display-message nil 'error (current-buffer) 'incorrect-args (erc-display-message nil 'error (current-buffer) 'incorrect-args
?c (erc-command-name cmd) ?c (erc-command-name cmd)
@ -3038,7 +3038,7 @@ If no USER argument is specified, list the contents of `erc-ignore-list'."
(erc-display-message (erc-display-message
nil 'notice (current-buffer) 'ops nil 'notice (current-buffer) 'ops
?i (length ops) ?s (if (> (length ops) 1) "s" "") ?i (length ops) ?s (if (> (length ops) 1) "s" "")
?o (mapconcat 'identity ops " ")) ?o (mapconcat #'identity ops " "))
(erc-display-message nil 'notice (current-buffer) 'ops-none))) (erc-display-message nil 'notice (current-buffer) 'ops-none)))
t) t)
@ -3209,7 +3209,7 @@ command."
(defun erc-cmd-KICK (target &optional reason-or-nick &rest reasonwords) (defun erc-cmd-KICK (target &optional reason-or-nick &rest reasonwords)
"Kick the user indicated in LINE from the current channel. "Kick the user indicated in LINE from the current channel.
LINE has the format: \"#CHANNEL NICK REASON\" or \"NICK REASON\"." LINE has the format: \"#CHANNEL NICK REASON\" or \"NICK REASON\"."
(let ((reasonstring (mapconcat 'identity reasonwords " "))) (let ((reasonstring (mapconcat #'identity reasonwords " ")))
(if (string= "" reasonstring) (if (string= "" reasonstring)
(setq reasonstring (format "Kicked by %s" (erc-current-nick)))) (setq reasonstring (format "Kicked by %s" (erc-current-nick))))
(if (erc-channel-p target) (if (erc-channel-p target)
@ -3744,7 +3744,7 @@ the message given by REASON."
" -" " -"
(make-string (length people) ?o) (make-string (length people) ?o)
" " " "
(mapconcat 'identity people " "))) (mapconcat #'identity people " ")))
t)) t))
(defun erc-cmd-OP (&rest people) (defun erc-cmd-OP (&rest people)
@ -3754,7 +3754,7 @@ the message given by REASON."
" +" " +"
(make-string (length people) ?o) (make-string (length people) ?o)
" " " "
(mapconcat 'identity people " "))) (mapconcat #'identity people " ")))
t)) t))
(defun erc-cmd-TIME (&optional line) (defun erc-cmd-TIME (&optional line)
@ -3952,7 +3952,7 @@ Unban all currently banned users in the current channel."
(erc-server-send (erc-server-send
(format "MODE %s -%s %s" (erc-default-target) (format "MODE %s -%s %s" (erc-default-target)
(make-string (length x) ?b) (make-string (length x) ?b)
(mapconcat 'identity x " ")))) (mapconcat #'identity x " "))))
(erc-group-list bans 3)))) (erc-group-list bans 3))))
t)))) t))))
@ -4183,7 +4183,7 @@ Displays PROC and PARSED appropriately using `erc-display-message'."
(erc-display-message (erc-display-message
parsed 'notice proc parsed 'notice proc
(mapconcat (mapconcat
'identity #'identity
(let (res) (let (res)
(mapc #'(lambda (x) (mapc #'(lambda (x)
(if (stringp x) (if (stringp x)
@ -5553,12 +5553,10 @@ This returns non-nil only if we actually send anything."
;; Instead `erc-pre-send-functions' is used as a filter to do ;; Instead `erc-pre-send-functions' is used as a filter to do
;; allow both changing and suppressing the string. ;; allow both changing and suppressing the string.
(run-hook-with-args 'erc-send-pre-hook input) (run-hook-with-args 'erc-send-pre-hook input)
(setq state (make-erc-input :string str (setq state (make-erc-input :string str ;May be != from `input' now!
:insertp erc-insert-this :insertp erc-insert-this
:sendp erc-send-this)) :sendp erc-send-this))
(dolist (func erc-pre-send-functions) (run-hook-with-args 'erc-pre-send-functions state)
;; The functions can return nil to inhibit sending.
(funcall func state))
(when (and (erc-input-sendp state) (when (and (erc-input-sendp state)
erc-send-this) erc-send-this)
(let ((string (erc-input-string state))) (let ((string (erc-input-string state)))
@ -5579,26 +5577,26 @@ This returns non-nil only if we actually send anything."
(erc-process-input-line (concat string "\n") t nil)) (erc-process-input-line (concat string "\n") t nil))
t)))))) t))))))
(defun erc-display-command (line) ;; (defun erc-display-command (line)
(when erc-insert-this ;; (when erc-insert-this
(let ((insert-position (point))) ;; (let ((insert-position (point)))
(unless erc-hide-prompt ;; (unless erc-hide-prompt
(erc-display-prompt nil nil (erc-command-indicator) ;; (erc-display-prompt nil nil (erc-command-indicator)
(and (erc-command-indicator) ;; (and (erc-command-indicator)
'erc-command-indicator-face))) ;; 'erc-command-indicator-face)))
(let ((beg (point))) ;; (let ((beg (point)))
(insert line) ;; (insert line)
(erc-put-text-property beg (point) ;; (erc-put-text-property beg (point)
'font-lock-face 'erc-command-indicator-face) ;; 'font-lock-face 'erc-command-indicator-face)
(insert "\n")) ;; (insert "\n"))
(when (processp erc-server-process) ;; (when (processp erc-server-process)
(set-marker (process-mark erc-server-process) (point))) ;; (set-marker (process-mark erc-server-process) (point)))
(set-marker erc-insert-marker (point)) ;; (set-marker erc-insert-marker (point))
(save-excursion ;; (save-excursion
(save-restriction ;; (save-restriction
(narrow-to-region insert-position (point)) ;; (narrow-to-region insert-position (point))
(run-hooks 'erc-send-modify-hook) ;; (run-hooks 'erc-send-modify-hook)
(run-hooks 'erc-send-post-hook)))))) ;; (run-hooks 'erc-send-post-hook))))))
(defun erc-display-msg (line) (defun erc-display-msg (line)
"Display LINE as a message of the user to the current target at the "Display LINE as a message of the user to the current target at the
@ -6563,7 +6561,7 @@ If optional argument HERE is non-nil, insert version number at point."
If optional argument HERE is non-nil, insert version number at point." If optional argument HERE is non-nil, insert version number at point."
(interactive "P") (interactive "P")
(let ((string (let ((string
(mapconcat 'identity (mapconcat #'identity
(let (modes (case-fold-search nil)) (let (modes (case-fold-search nil))
(dolist (var (apropos-internal "^erc-.*mode$")) (dolist (var (apropos-internal "^erc-.*mode$"))
(when (and (boundp var) (when (and (boundp var)
@ -6817,7 +6815,8 @@ See also `format-spec'."
;;; Various hook functions ;;; Various hook functions
(add-hook 'kill-buffer-hook 'erc-kill-buffer-function) ;; FIXME: Don't set the hook globally!
(add-hook 'kill-buffer-hook #'erc-kill-buffer-function)
(defcustom erc-kill-server-hook '(erc-kill-server) (defcustom erc-kill-server-hook '(erc-kill-server)
"Invoked whenever a server buffer is killed via `kill-buffer'." "Invoked whenever a server buffer is killed via `kill-buffer'."