-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiao-helpers.el
92 lines (73 loc) · 2.89 KB
/
miao-helpers.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; miao-helpers.el --- Miao variables -*- lexical-binding: t; -*-
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Internal variables and customizable variables.
;;; Code:
(defun miao-define-keys (states &rest keybinds)
"Define KEYBINDS in STATE.
Example usage:
(miao-define-keys
;; state
'normal
;; bind to a command
'(\"a\" . miao-append)
;; bind to a keymap
(cons \"x\" ctl-x-map)
;; bind to a keybinding which holds a keymap
'(\"c\" . \"C-c\")
;; bind to a keybinding which holds a command
'(\"q\" . \"C-x C-q\"))"
(declare (indent 1))
(if (listp states)
(dolist (state states)
(let ((map (alist-get state miao-keymap-alist)))
(pcase-dolist (`(,key . ,def) keybinds)
(define-key map (kbd key) def))))
(let ((map (alist-get states miao-keymap-alist)))
(pcase-dolist (`(,key . ,def) keybinds)
(define-key map (kbd key) def)))))
(defun miao-bypass-list-add (mode)
"Add mode to miao-bypass-mode-list."
(add-to-list 'mode 'miao-bypass-mode-list))
(defun miao-leader-define-keys (&rest keybinds)
"Define KEYBINDS in miao leader mode."
(declare (indent 1))
(let ((map (alist-get 'leader miao-keymap-alist)))
(pcase-dolist (`(,key . ,def) keybinds)
(define-key map (kbd key) def))))
(defun miao-leader-get-major-keymap (major)
(let ((keymap (gethash major miao-leader-major-keymap-hash)))
(if keymap
keymap
(setq keymap (make-keymap))
(suppress-keymap keymap t)
(puthash major keymap miao-leader-major-keymap-hash)
keymap)))
(defun miao-leader-define-major-keys (major &rest keybinds)
"Define KEYBINDS in miao leader mode."
(declare (indent 1))
(let ((map (miao-leader-get-major-keymap major)))
(pcase-dolist (`(,key . ,def) keybinds)
(define-key map (kbd key) def))))
(defun miao-indicator ()
(when (bound-and-true-p miao-global-mode)
(let* ((state (miao--current-state))
(state-name (alist-get state miao-modeline-indicators)))
(if state-name
(propertize
(format " %s " state-name)
'face 'miao-modeline-face)
""))))
(provide 'miao-helpers)