Update mozc stuff

This commit is contained in:
2026-07-21 00:05:23 -07:00
parent 20be5dd80f
commit c7542dc27a
2 changed files with 72 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
;;; mozc-posframe.el --- Allow mozc.el candidates to be shown in a posframe -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(require 'mozc)
(require 'posframe)
;; Show candidates in a posframe
(defconst my/-mozc-cand-posframe-name " *mozc-posframe*")
(defun my/-mozc-cand-posframe-live-p ()
"Return non-nil if the posframe of mozc-posframe is live."
(buffer-live-p (get-buffer my/-mozc-cand-posframe-name)))
(defun my/-mozc-cand-posframe-clean-up ()
"Clean up the current candidate session."
(my/-mozc-cand-posframe-clear))
(defun my/-mozc-cand-posframe-clear ()
"Clear the candidate window."
(when (my/-mozc-cand-posframe-live-p)
(posframe-delete my/-mozc-cand-posframe-name)))
(defun my/-mozc-cand-posframe-update (candidates)
"Update the candidate window using posframes.
CANDIDATES is the list of candidates."
(let ((contents (mozc-cand-overlay-make-contents candidates))
(position (posn-point mozc-preedit-posn-origin))
space-idxs
right-sizes)
(with-current-buffer (get-buffer-create my/-mozc-cand-posframe-name)
(erase-buffer)
(cl-loop for (left right face) in contents
do (let ((start (point)))
(when left
(insert left))
(push (point) space-idxs)
(insert " ")
(if right
(let ((right-start (point)))
(insert right)
(with-restriction right-start (point)
(push (car (buffer-text-pixel-size)) right-sizes)))
(push 0 right-sizes))
(put-text-property start (point) 'face face)
(insert "\n")))
(let ((width (car (buffer-text-pixel-size))))
(message "%s" width)
(cl-loop for pos in space-idxs
for right-width in right-sizes
do (message "%s" (- width right-width))
do (put-text-property
pos (1+ pos)
'display `(space :align-to (,(- width right-width))))))
(posframe-show (current-buffer)
:position position))))
(add-to-list 'mozc-candidate-dispatch-table
'(posframe (clean-up . my/-mozc-cand-posframe-clean-up)
(clear . my/-mozc-cand-posframe-clear)
(update . my/-mozc-cand-posframe-update)))
(provide 'mozc-posframe)
;;; mozc-posframe.el ends here
+12
View File
@@ -627,6 +627,17 @@ directory. Otherwise, run `find-file' on that file."
;; mozc
(require 'mozc nil t)
(setq default-input-method "japanese-mozc")
(with-eval-after-load 'mozc
(require 'mozc-posframe)
(defvar my/-mozc-mode-override-evil-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-k") #'mozc-handle-event)
map)
"Emulation map to override evil keys in `mozc-mode'.")
(add-to-list 'emulation-mode-map-alists
`((mozc-mode . ,my/-mozc-mode-override-evil-map))))
;; mozc status bar stuff
(defun my/-update-waybar-fcitx-state ()
"Update the waybar fcitx5 state."
(call-process "pkill" nil 0 nil "-RTMIN+1" "waybar"))
@@ -700,6 +711,7 @@ With NO-UPDATE-BAR, don't update any status bar's state."
;; (advice-add 'mozc-helper-process-filter :override
;; #'my/-fixed-mozc-helper-process-filter))
;; migemo
(use-package migemo
:defer nil