diff options
| author | Lars Ingebrigtsen | 2019-06-14 14:56:04 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-06-14 14:56:04 +0200 |
| commit | 37a61055ffdfcd3b00bc9e972556e8c18262d781 (patch) | |
| tree | 3d6f7940a023482189733b075c32a3a9ea4d2dd1 | |
| parent | fe12ec4b0d71f8adb572c68c6f662d7783382fb1 (diff) | |
| download | emacs-37a61055ffdfcd3b00bc9e972556e8c18262d781.tar.gz emacs-37a61055ffdfcd3b00bc9e972556e8c18262d781.zip | |
Adjust erc functions after previous erc-pre-send-function change
* lisp/erc/erc-goodies.el (noncommands): Use
erc-pre-send-functions instead of the hook.
(erc-send-distinguish-noncommands): Adjust function to new interface.
* lisp/erc/erc-ring.el (ring): Ditto.
(erc-add-to-input-ring): Ditto.
* lisp/erc/erc.el (erc-send-this): Really make obsolete.
(erc-pre-send-functions): Change to a list of functions to allow
erc-goodies and erc-ring to work as before.
| -rw-r--r-- | lisp/erc/erc-goodies.el | 15 | ||||
| -rw-r--r-- | lisp/erc/erc-ring.el | 8 | ||||
| -rw-r--r-- | lisp/erc/erc.el | 25 |
3 files changed, 28 insertions, 20 deletions
diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index 884c594b9ed..41083829bac 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el | |||
| @@ -177,18 +177,21 @@ does not appear in the ERC buffer after the user presses ENTER.") | |||
| 177 | "This mode distinguishes non-commands. | 177 | "This mode distinguishes non-commands. |
| 178 | Commands listed in `erc-insert-this' know how to display | 178 | Commands listed in `erc-insert-this' know how to display |
| 179 | themselves." | 179 | themselves." |
| 180 | ((add-hook 'erc-send-pre-hook 'erc-send-distinguish-noncommands)) | 180 | ((push 'erc-send-distinguish-noncommands erc-pre-send-functions)) |
| 181 | ((remove-hook 'erc-send-pre-hook 'erc-send-distinguish-noncommands))) | 181 | ((setq erc-pre-send-functions (delq 'erc-send-distinguish-noncommands |
| 182 | erc-pre-send-functions)))) | ||
| 182 | 183 | ||
| 183 | (defun erc-send-distinguish-noncommands (str) | 184 | (defun erc-send-distinguish-noncommands (str) |
| 184 | "If STR is an ERC non-command, set `erc-insert-this' to nil." | 185 | "If STR is an ERC non-command, set `erc-insert-this' to nil." |
| 185 | (let* ((command (erc-extract-command-from-line str)) | 186 | (let* ((command (erc-extract-command-from-line str)) |
| 186 | (cmd-fun (and command | 187 | (cmd-fun (and command |
| 187 | (car command)))) | 188 | (car command)))) |
| 188 | (when (and cmd-fun | 189 | (if (and cmd-fun |
| 189 | (not (string-match "\n.+$" str)) | 190 | (not (string-match "\n.+$" str)) |
| 190 | (memq cmd-fun erc-noncommands-list)) | 191 | (memq cmd-fun erc-noncommands-list)) |
| 191 | (setq erc-insert-this nil)))) | 192 | ;; Inhibit sending this string. |
| 193 | nil | ||
| 194 | str))) | ||
| 192 | 195 | ||
| 193 | ;;; IRC control character processing. | 196 | ;;; IRC control character processing. |
| 194 | (defgroup erc-control-characters nil | 197 | (defgroup erc-control-characters nil |
diff --git a/lisp/erc/erc-ring.el b/lisp/erc/erc-ring.el index 5459d8b01e5..2ee78f4d46d 100644 --- a/lisp/erc/erc-ring.el +++ b/lisp/erc/erc-ring.el | |||
| @@ -46,10 +46,11 @@ | |||
| 46 | (define-erc-module ring nil | 46 | (define-erc-module ring nil |
| 47 | "Stores input in a ring so that previous commands and messages can | 47 | "Stores input in a ring so that previous commands and messages can |
| 48 | be recalled using M-p and M-n." | 48 | be recalled using M-p and M-n." |
| 49 | ((add-hook 'erc-send-pre-hook 'erc-add-to-input-ring) | 49 | ((push 'erc-add-to-input-ring erc-pre-send-functions) |
| 50 | (define-key erc-mode-map "\M-p" 'erc-previous-command) | 50 | (define-key erc-mode-map "\M-p" 'erc-previous-command) |
| 51 | (define-key erc-mode-map "\M-n" 'erc-next-command)) | 51 | (define-key erc-mode-map "\M-n" 'erc-next-command)) |
| 52 | ((remove-hook 'erc-send-pre-hook 'erc-add-to-input-ring) | 52 | ((setq erc-pre-send-functions (delq 'erc-add-to-input-ring |
| 53 | erc-pre-send-functions)) | ||
| 53 | (define-key erc-mode-map "\M-p" 'undefined) | 54 | (define-key erc-mode-map "\M-p" 'undefined) |
| 54 | (define-key erc-mode-map "\M-n" 'undefined))) | 55 | (define-key erc-mode-map "\M-n" 'undefined))) |
| 55 | 56 | ||
| @@ -75,7 +76,8 @@ Call this function when setting up the mode." | |||
| 75 | "Add string S to the input ring and reset history position." | 76 | "Add string S to the input ring and reset history position." |
| 76 | (unless erc-input-ring (erc-input-ring-setup)) | 77 | (unless erc-input-ring (erc-input-ring-setup)) |
| 77 | (ring-insert erc-input-ring s) | 78 | (ring-insert erc-input-ring s) |
| 78 | (setq erc-input-ring-index nil)) | 79 | (setq erc-input-ring-index nil) |
| 80 | s) | ||
| 79 | 81 | ||
| 80 | (defun erc-clear-input-ring () | 82 | (defun erc-clear-input-ring () |
| 81 | "Remove all entries from the input ring, then call garbage-collect. | 83 | "Remove all entries from the input ring, then call garbage-collect. |
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 82360a66f98..0165f2c4703 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el | |||
| @@ -1051,16 +1051,17 @@ Note that it's useless to set `erc-send-this' to nil and | |||
| 1051 | anyway." | 1051 | anyway." |
| 1052 | :group 'erc-hooks | 1052 | :group 'erc-hooks |
| 1053 | :type 'hook) | 1053 | :type 'hook) |
| 1054 | (make-obsolete-variable 'erc-send-pre-hook 'erc-pre-send-function "27.1") | 1054 | (make-obsolete-variable 'erc-send-pre-hook 'erc-pre-send-functions "27.1") |
| 1055 | 1055 | ||
| 1056 | (defcustom erc-pre-send-function nil | 1056 | (defcustom erc-pre-send-functions nil |
| 1057 | "Function called to possibly alter the string that is sent. | 1057 | "List of functions called to possibly alter the string that is sent. |
| 1058 | It's called with one argument, the string, and should return a | 1058 | The functions are called with one argument, the string, and |
| 1059 | string. | 1059 | should return a string. |
| 1060 | 1060 | ||
| 1061 | To suppress the string completely, return nil." | 1061 | To suppress the string completely, one of the functions should |
| 1062 | return nil." | ||
| 1062 | :group 'erc | 1063 | :group 'erc |
| 1063 | :type 'function | 1064 | :type '(repeat function) |
| 1064 | :version "27.1") | 1065 | :version "27.1") |
| 1065 | 1066 | ||
| 1066 | (defvar erc-insert-this t | 1067 | (defvar erc-insert-this t |
| @@ -1072,7 +1073,7 @@ if they wish to avoid insertion of a particular string.") | |||
| 1072 | "Send the text to the target or not. | 1073 | "Send the text to the target or not. |
| 1073 | Functions on `erc-send-pre-hook' can set this variable to nil | 1074 | Functions on `erc-send-pre-hook' can set this variable to nil |
| 1074 | if they wish to avoid sending of a particular string.") | 1075 | if they wish to avoid sending of a particular string.") |
| 1075 | (make-obsolete-variable 'erc-send-pre-hook 'erc-pre-send-function "27.1") | 1076 | (make-obsolete-variable 'erc-insert-this 'erc-pre-send-functions "27.1") |
| 1076 | 1077 | ||
| 1077 | (defcustom erc-insert-modify-hook () | 1078 | (defcustom erc-insert-modify-hook () |
| 1078 | "Insertion hook for functions that will change the text's appearance. | 1079 | "Insertion hook for functions that will change the text's appearance. |
| @@ -5462,11 +5463,13 @@ This returns non-nil only if we actually send anything." | |||
| 5462 | ;; The calling convention of `erc-send-pre-hook' is that it | 5463 | ;; The calling convention of `erc-send-pre-hook' is that it |
| 5463 | ;; should change the dynamic variable `str' or set | 5464 | ;; should change the dynamic variable `str' or set |
| 5464 | ;; `erc-send-this' to nil. This has now been deprecated: | 5465 | ;; `erc-send-this' to nil. This has now been deprecated: |
| 5465 | ;; Instead `erc-pre-send-function' is used as a filter to do | 5466 | ;; Instead `erc-pre-send-functions' is used as a filter to do |
| 5466 | ;; allow both changing and suppressing the string. | 5467 | ;; allow both changing and suppressing the string. |
| 5467 | (run-hook-with-args 'erc-send-pre-hook input) | 5468 | (run-hook-with-args 'erc-send-pre-hook input) |
| 5468 | (when erc-pre-send-function | 5469 | (dolist (func erc-pre-send-functions) |
| 5469 | (setq str (funcall erc-pre-send-function str))) | 5470 | ;; The functions can return nil to inhibit sending. |
| 5471 | (when str | ||
| 5472 | (setq str (funcall func str)))) | ||
| 5470 | (when (and erc-send-this | 5473 | (when (and erc-send-this |
| 5471 | str) | 5474 | str) |
| 5472 | (if (or (string-match "\n" str) | 5475 | (if (or (string-match "\n" str) |