Skip to content

Commit

Permalink
Refactor meow-esc-mode and add documentation
Browse files Browse the repository at this point in the history
Refactor the "fake" meow-esc-mode with the minor mode macro.
Add commentary as suggested in #510.
  • Loading branch information
eshrh committed Oct 5, 2023
1 parent 0109f0b commit 971cda2
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions meow-esc.el
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,33 @@
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;; In the terminal, ESC can be used as META, because they send the
;; same keycode. To allow both usages simulataneously, you can
;; customize meow-esc-delay, the maximum time between ESC and the
;; keypress that should be treated as a meta combo. If the time is
;; longer than the delay, it's treated as pressing ESC and then the
;; key separately.
;;; Code:

(defvar meow-esc-delay 0.1)
(defvar meow-esc-mode nil)
(defvar meow--escape-key-seq [?\e])

(defun meow-esc-mode (&optional arg)
(cond
((or (null arg) (eq arg 0))
(meow-esc-mode (if meow-esc-mode -1 +1)))
((> arg 0)
(unless meow-esc-mode
(setq meow-esc-mode t)
(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
(define-minor-mode meow-esc-mode

Check failure on line 28 in meow-esc.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

Global minor modes should be autoloaded or, rarely, ‘:require’ their defining file (i.e. ":require ’meow-esc"), to support the customization variable of the same name.

Check failure on line 28 in meow-esc.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

Global minor modes should be autoloaded or, rarely, ‘:require’ their defining file (i.e. ":require ’meow-esc"), to support the customization variable of the same name.

Check failure on line 28 in meow-esc.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

Global minor modes should be autoloaded or, rarely, ‘:require’ their defining file (i.e. ":require ’meow-esc"), to support the customization variable of the same name.
"Mode that ensures ESC works in the terminal"
:init-value nil
:interactive nil
:global t
:keymap nil
(if meow-esc-mode
(progn
(setq meow-esc-mode t)
(add-hook 'after-make-frame-functions #'meow--init-esc-if-tui)
(mapc #'meow--init-esc-if-tui (frame-list)))
(progn
(remove-hook 'after-make-frame-functions #'meow--init-esc-if-tui)
(mapc #'meow--deinit-esc-if-tui (frame-list))
(setq meow-esc-mode nil)))))
(setq meow-esc-mode nil))))

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

(defun meow--init-esc-if-tui (frame)
(with-selected-frame frame
Expand Down

0 comments on commit 971cda2

Please sign in to comment.