再pyim的github issue中找到了从insert退出到normal的一段代码,稍微改了下,但是没法输入,请问下具体该怎么改才行,我使用";g"从insert退出到normal,现在用";g"能正常从insert到normal模式,但是没法输入英文或者中文
(defun my-pyim-self-insert-command (orig-func key)
(if (and (local-variable-p 'last-event-time)
(floatp last-event-time)
(< (- (float-time) last-event-time) 0.2))
(set (make-local-variable 'temp-evil-escape-mode) t)
(set (make-local-variable 'temp-evil-escape-mode) nil))
(if temp-evil-escape-mode
(let ((fkey (elt evil-escape-key-sequence 0))
(skey (elt evil-escape-key-sequence 1)))
(if (and (char-equal my-last-char fkey) (char-equal key skey))
(progn
(company-abort)
(evil-repeat-stop)
(evil-normal-state)
(message "exit"))
(apply orig-func (list key))))
(progn
(if (numberp key)
(apply orig-func (list key))
(setq unread-command-events (append unread-command-events (list evt))))
(set (make-local-variable 'last-event-time) (float-time))))
(set (make-local-variable 'my-last-char) key)
)
(advice-add 'pyim-input-method :around #'my-pyim-self-insert-command)
用下面这段代码可以直接gg从insert退出到normal模式,但是用";g"就不行,而上面的代码可以用";g"退出到normal,但是没法正常输入英文或者中文。。
;; {{{
;; 当前没有输入内容的时候直接使用 gg 直接返回到normal模式
;; https://github.com/tumashu/pyim/issues/260#issuecomment-570921604
(defun my-pyim-self-insert-command (orig-func)
(interactive "*")
(if (and (local-variable-p 'last-event-time)
(floatp last-event-time)
(< (- (float-time) last-event-time) 0.2))
(set (make-local-variable 'temp-evil-escape-mode) t)
(set (make-local-variable 'temp-evil-escape-mode) nil)
)
(if (and temp-evil-escape-mode
(equal (pyim-entered-get) "g")
(equal last-command-event ?g))
(progn
(company-abort)
(pyim-terminate-translation)
(evil-repeat-stop)
(evil-normal-state)
)
(progn
(call-interactively orig-func)
(set (make-local-variable 'last-event-time) (float-time))
))
)
(advice-add 'pyim-self-insert-command :around #'my-pyim-self-insert-command)
;; (advice-remove 'pyim-self-insert-command #'my-pyim-self-insert-command)
;; }}}
自己又改了下,底下的函数可以使用“;g”来回到normal模式了
;; {{{
;; 当前没有输入内容的时候直接使用evil-escape的按键(;g)的直接返回到normal模式
(defun my-pyim-self-insert-command (orig-func key)
(let ((fkey (elt evil-escape-key-sequence 0))
(skey (elt evil-escape-key-sequence 1))
(last-char (if (and (local-variable-p 'my-last-char) (numberp my-last-char))
my-last-char
nil)))
(set (make-local-variable 'my-last-char) key)
(if (char-equal key fkey)
(progn
(set (make-local-variable 'last-event-time) (float-time))
(funcall orig-func key))
(progn
(if (and (numberp last-char)
(char-equal last-char fkey)
(char-equal key skey)
(and (local-variable-p 'last-event-time)
(floatp last-event-time)
(< (- (float-time) last-event-time) evil-escape-delay)))
(progn
(evil-escape--delete)
(evil-repeat-stop)
(evil-normal-state))
(if (numberp key)
(funcall orig-func key)
(setq unread-command-events (append unread-command-events (list key))))))))
)
(advice-add 'pyim-input-method :around #'my-pyim-self-insert-command)
;; (advice-remove 'pyim-input-method #'my-pyim-self-insert-command)
;; }}}
1 个赞