Skip to content

Commit

Permalink
fix meow-esc in emacsclient -t
Browse files Browse the repository at this point in the history
fixes #514. If a emacs server is started from graphical, meow-esc-mode
is never called. Therefore, meow-init-esc does not get added to the
make frame hook, and it never gets enabled for emacsclient -t.

This commit always enables meow-esc-mode, and checks whether we are
graphical inside the init and deinit functions instead of in the
global init/deinit functions.
  • Loading branch information
eshrh committed Oct 5, 2023
1 parent b47d1fa commit 0109f0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
6 changes: 2 additions & 4 deletions meow-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ there's no chance for meow to call an init function."

(meow--enable-shims)
;; meow-esc-mode fix ESC in TUI
(unless window-system
(meow-esc-mode 1))
(meow-esc-mode 1)
;; raise Meow keymap priority
(add-to-ordered-list 'emulation-mode-map-alists
`((meow-motion-mode . ,meow-motion-state-keymap)))
Expand Down Expand Up @@ -213,8 +212,7 @@ there's no chance for meow to call an init function."
(when meow-use-cursor-position-hack
(setq redisplay-highlight-region-function meow--backup-redisplay-highlight-region-function)
(setq redisplay-unhighlight-region-function meow--backup-redisplay-unhighlight-region-function))
(unless window-system
(meow-esc-mode -1))
(meow-esc-mode -1)
(advice-remove 'enable-theme 'meow--enable-theme-advice))

(provide 'meow-core)
Expand Down
38 changes: 20 additions & 18 deletions meow-esc.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,35 @@
((> arg 0)
(unless meow-esc-mode
(setq meow-esc-mode t)
(add-hook 'after-make-frame-functions #'meow-init-esc)
(mapc #'meow-init-esc (frame-list))))
(add-hook 'after-make-frame-functions #'meow--init-esc-if-tui)
(mapc #'meow--init-esc-if-tui (frame-list))))
((< arg 0)
(when meow-esc-mode
(remove-hook 'after-make-frame-functions #'meow-init-esc)
(mapc #'meow-deinit-esc (frame-list))
(remove-hook 'after-make-frame-functions #'meow--init-esc-if-tui)
(mapc #'meow--deinit-esc-if-tui (frame-list))
(setq meow-esc-mode nil)))))

(defvar meow--escape-key-seq [?\e])

(defun meow-init-esc (frame)
(defun meow--init-esc-if-tui (frame)
(with-selected-frame frame
(let ((term (frame-terminal frame)))
(when (not (terminal-parameter term 'meow-esc-map))
(let ((meow-esc-map (lookup-key input-decode-map [?\e])))
(set-terminal-parameter term 'meow-esc-map meow-esc-map)
(define-key input-decode-map meow--escape-key-seq
`(menu-item "" ,meow-esc-map :filter ,#'meow-esc)))))))
(unless window-system
(let ((term (frame-terminal frame)))
(when (not (terminal-parameter term 'meow-esc-map))
(let ((meow-esc-map (lookup-key input-decode-map [?\e])))
(set-terminal-parameter term 'meow-esc-map meow-esc-map)
(define-key input-decode-map meow--escape-key-seq
`(menu-item "" ,meow-esc-map :filter ,#'meow-esc))))))))

(defun meow-deinit-esc (frame)
(defun meow--deinit-esc-if-tui (frame)
(with-selected-frame frame
(let ((term (frame-terminal frame)))
(when (terminal-live-p term)
(let ((meow-esc-map (terminal-parameter term 'meow-esc-map)))
(when meow-esc-map
(define-key input-decode-map meow--escape-key-seq meow-esc-map)
(set-terminal-parameter term 'meow-esc-map nil)))))))
(unless window-system
(let ((term (frame-terminal frame)))
(when (terminal-live-p term)
(let ((meow-esc-map (terminal-parameter term 'meow-esc-map)))
(when meow-esc-map
(define-key input-decode-map meow--escape-key-seq meow-esc-map)
(set-terminal-parameter term 'meow-esc-map nil))))))))

(defun meow-esc (map)
(if (and (let ((keys (this-single-command-keys)))
Expand Down

0 comments on commit 0109f0b

Please sign in to comment.