summaryrefslogtreecommitdiff
path: root/lisp/net/rcirc.el
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2022-07-31 12:45:29 +0200
committerPhilip Kaludercic <philipk@posteo.net>2022-07-31 12:47:11 +0200
commitdf8dede8585257a2ee76ed93d6ecb6cf117e124a (patch)
treebc335589d4060a90edd2d1e3083b14172083d82b /lisp/net/rcirc.el
parentca2d3ed74c63167c7d8378482016efea9756dd17 (diff)
downloademacs-df8dede8585257a2ee76ed93d6ecb6cf117e124a.tar.gz
emacs-df8dede8585257a2ee76ed93d6ecb6cf117e124a.tar.bz2
emacs-df8dede8585257a2ee76ed93d6ecb6cf117e124a.zip
Fix electric paring in rcirc buffers
* rcirc.el (rcirc--electric-pair-inhibit): Add new predicate function. (rcirc-mode): Use rcirc--electric-pair-inhibit.
Diffstat (limited to 'lisp/net/rcirc.el')
-rw-r--r--lisp/net/rcirc.el18
1 files changed, 18 insertions, 0 deletions
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index 54d7861f445..065398b64af 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -1388,6 +1388,21 @@ Each element looks like (FILENAME . TEXT).")
"The current number of responses printed in this channel.
This number is independent of the number of lines in the buffer.")
+(defun rcirc--electric-pair-inhibit (char)
+ "Check whether CHAR should be paired by `electric-pair-mode'.
+This uses the default value inhibition predicate (as set by
+`electric-pair-inhibit-predicate'), but ignores all text prior to
+the prompt so that mismatches parentheses by some other message
+does not confuse the pairing."
+ (let ((fallback (default-value 'electric-pair-inhibit-predicate)))
+ ;; The assumption is that this function is only bound by
+ ;; `rcirc-mode', and should never be the global default.
+ (cl-assert (not (eq fallback #'rcirc--electric-pair-inhibit)))
+ (save-restriction
+ (widen)
+ (narrow-to-region rcirc-prompt-start-marker (point-max))
+ (funcall fallback char))))
+
(defun rcirc-mode (process target)
"Initialize an IRC buffer for writing with TARGET.
PROCESS is the process object used for communication.
@@ -1459,6 +1474,9 @@ PROCESS is the process object used for communication.
(when rcirc-cycle-completion-flag
(setq-local completion-cycle-threshold t))
+ (setq-local electric-pair-inhibit-predicate
+ #'rcirc--electric-pair-inhibit)
+
(run-mode-hooks 'rcirc-mode-hook))
(defun rcirc-update-prompt (&optional all)