From: Po Lu Date: Mon, 11 Sep 2023 01:32:44 +0000 (+0800) Subject: Properly set text conversion style within ERC buffers X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8d13ad2318f1e4b677d569e6232d6dde6bec4819;p=emacs.git Properly set text conversion style within ERC buffers * lisp/erc/erc.el (erc-mode): Register `erc-check-text-conversion' as a local post command hook. (set-text-conversion-style): New function. Detect if point is within the input prompt, then enable or disable text conversion correspondingly. --- diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index f7237c9e334..853ef4fb2d9 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1538,6 +1538,7 @@ Defaults to the server buffer." (setq-local paragraph-start (concat "\\(" (regexp-quote (erc-prompt)) "\\)")) (setq-local completion-ignore-case t) + (add-hook 'post-command-hook #'erc-check-text-conversion nil t) (add-hook 'kill-buffer-hook #'erc-kill-buffer-function nil t) (add-hook 'completion-at-point-functions #'erc-complete-word-at-point nil t)) @@ -8030,6 +8031,22 @@ or `erc-kill-buffer-hook' if any other buffer." (t (run-hooks 'erc-kill-buffer-hook))))) +(declare-function set-text-conversion-style "textconv.c") + +(defun erc-check-text-conversion () + "Check if point is within the ERC prompt and toggle text conversion. +If `text-conversion-style' is not `action' if point is within the +prompt or `nil' otherwise, set it to such a value, so as to +guarantee that the input method functions properly for the +purpose of typing within the ERC prompt." + (when (and (eq major-mode 'erc-mode) + (boundp set-text-conversion-style)) + (if (>= (point) (erc-beg-of-input-line)) + (unless (eq text-conversion-style 'action) + (set-text-conversion-style 'action)) + (unless (not text-conversion-style) + (set-text-conversion-style nil))))) + (defun erc-kill-server () "Sends a QUIT command to the server when the server buffer is killed. This function should be on `erc-kill-server-hook'."