]> git.eshelyaron.com Git - emacs.git/commitdiff
Properly set text conversion style within ERC buffers
authorPo Lu <luangruo@yahoo.com>
Mon, 11 Sep 2023 01:32:44 +0000 (09:32 +0800)
committerPo Lu <luangruo@yahoo.com>
Mon, 11 Sep 2023 01:33:42 +0000 (09:33 +0800)
* 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.

lisp/erc/erc.el

index f7237c9e3343dff993c80094591abba58c58eab4..853ef4fb2d95320438c632df17d20b34c98556d3 100644 (file)
@@ -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'."