From: Po Lu Date: Sat, 15 Jan 2022 10:18:34 +0000 (+0800) Subject: Prevent pre-edit overlay text from being displayed after a command X-Git-Tag: emacs-29.0.90~3033 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7a679953e22ada9df02b181b872b9e56bbfd0f07;p=emacs.git Prevent pre-edit overlay text from being displayed after a command This works around buggy input methods causing the overlay to be displayed alongside newly inserted text for a brief period. * lisp/term/x-win.el (x-clear-preedit-text): New function. (x-preedit-text): Add said function to pre-command-hook. It will remove itself when triggered. --- diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index e52e488edab..cd63c9208ba 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el @@ -1527,16 +1527,32 @@ This uses `icon-map-list' to map icon file names to stock icon names." (defvar x-preedit-overlay nil "The overlay currently used to display preedit text from a compose sequence.") +;; With some input methods, text gets inserted before Emacs is told to +;; remove any preedit text that was displayed, which causes both the +;; preedit overlay and the text to be visible for a brief period of +;; time. This pre-command-hook clears the overlay before any command +;; and should be set whenever a preedit overlay is visible. +(defun x-clear-preedit-text () + "Clear the pre-edit overlay and remove itself from pre-command-hook. +This function should be installed in `pre-command-hook' whenever +preedit text is displayed." + (when x-preedit-overlay + (delete-overlay x-preedit-overlay) + (setq x-preedit-overlay nil)) + (remove-hook 'pre-command-hook #'x-clear-preedit-text)) + (defun x-preedit-text (event) "Display preedit text from a compose sequence in EVENT. EVENT is a preedit-text event." (interactive "e") (when x-preedit-overlay (delete-overlay x-preedit-overlay) - (setq x-preedit-overlay nil)) + (setq x-preedit-overlay nil) + (remove-hook 'pre-command-hook #'x-clear-preedit-text)) (when (nth 1 event) (let ((string (propertize (nth 1 event) 'face '(:underline t)))) (setq x-preedit-overlay (make-overlay (point) (point))) + (add-hook 'pre-command-hook #'x-clear-preedit-text) (overlay-put x-preedit-overlay 'window (selected-window)) (overlay-put x-preedit-overlay 'before-string (if x-display-cursor-at-start-of-preedit-string