|
6 | 6 | ;; Maintainer: Shen, Jen-Chieh <jcs090218@gmail.com> |
7 | 7 | ;; URL: https://github.com/jcs-emacs/jcs-echobar |
8 | 8 | ;; Version: 0.1.0 |
9 | | -;; Package-Requires: ((emacs "26.1") (echo-bar "1.0.0") (indent-control "0.1.0") (show-eol "0.1.0")) |
| 9 | +;; Package-Requires: ((emacs "26.1") (echo-bar "1.0.0") (indent-control "0.1.0") (show-eol "0.1.0") (keycast "1.2.0")) |
10 | 10 | ;; Keywords: faces echo-bar |
11 | 11 |
|
12 | 12 | ;; This file is not part of GNU Emacs. |
|
34 | 34 | (require 'echo-bar) |
35 | 35 | (require 'indent-control) |
36 | 36 | (require 'show-eol) |
| 37 | +(require 'keycast) |
37 | 38 |
|
38 | 39 | (defgroup jcs-echobar nil |
39 | 40 | "An echo-bar for jcs-emacs." |
|
42 | 43 | :link '(url-link :tag "Github" "https://github.com/jcs-emacs/jcs-echobar")) |
43 | 44 |
|
44 | 45 | (defcustom jcs-echobar-render |
45 | | - `((:eval (jcs-echobar--render-spaces-tabs-size)) |
| 46 | + `((:eval (jcs-echobar--render-keycast)) |
| 47 | + (:eval (jcs-echobar--render-spaces-tabs-size)) |
46 | 48 | (:eval (jcs-echobar--render-coding-system)) |
47 | 49 | (:eval (jcs-echobar--render-eol)) |
48 | 50 | (:eval (jcs-echobar--render-time))) |
49 | 51 | "List of item to render in echo-bar." |
50 | 52 | :type 'list |
51 | 53 | :group 'jcs-echobar) |
52 | 54 |
|
53 | | -(defvar jcs-echobar--render nil) |
| 55 | +(defcustom jcs-echobar-keycast-format "%K%C%R " |
| 56 | + "The keycast format spec." |
| 57 | + :type 'string |
| 58 | + :group 'jcs-echobar) |
54 | 59 |
|
55 | 60 | ;; |
56 | 61 | ;; (@* "Externals" ) |
|
68 | 73 |
|
69 | 74 | (defun jcs-echobar--enable () |
70 | 75 | "Enable function `jcs-echobar-mode'." |
| 76 | + (progn ; keycast |
| 77 | + (add-hook 'post-command-hook #'keycast--update t) |
| 78 | + (add-hook 'minibuffer-exit-hook #'keycast--minibuffer-exit t) |
| 79 | + (advice-add 'keycast--update :after #'jcs-echobar--keycast-update)) |
71 | 80 | (add-hook 'window-size-change-functions #'jcs-echobar--window-resize) |
72 | 81 | (jcs-echobar--window-resize) ; call it manually once |
73 | 82 | (setq jcs-echobar--default-function echo-bar-function) |
|
76 | 85 |
|
77 | 86 | (defun jcs-echobar--disable () |
78 | 87 | "Disable function `jcs-echobar-mode'." |
| 88 | + (progn ; keycast |
| 89 | + (remove-hook 'post-command-hook #'keycast--update) |
| 90 | + (remove-hook 'minibuffer-exit-hook #'keycast--minibuffer-exit) |
| 91 | + (advice-remove 'keycast--update #'jcs-echobar--keycast-update)) |
79 | 92 | (remove-hook 'window-size-change-functions #'jcs-echobar--window-resize) |
80 | 93 | (setq echo-bar-function jcs-echobar--default-function) |
81 | 94 | (echo-bar-mode -1)) |
|
116 | 129 | ;; (@* "Core" ) |
117 | 130 | ;; |
118 | 131 |
|
| 132 | +(defvar jcs-echobar--render nil) |
| 133 | + |
119 | 134 | (defun jcs-echobar--window-resize (&rest _) |
120 | 135 | "Window resize hook." |
121 | 136 | (setq jcs-echobar--render nil) ; reset |
|
133 | 148 | "Render the echo-bar." |
134 | 149 | (mapconcat #'format-mode-line jcs-echobar--render "")) |
135 | 150 |
|
| 151 | +(defun jcs-echobar--keycast-update (&rest _) |
| 152 | + "Exection after `keycast-update' function." |
| 153 | + (when (bound-and-true-p jcs-echobar-mode) |
| 154 | + (echo-bar-update))) |
| 155 | + |
136 | 156 | ;; |
137 | 157 | ;; (@* "Plugins" ) |
138 | 158 | ;; |
|
155 | 175 | "Render time." |
156 | 176 | (format-time-string "%b %d, %Y %H:%M:%S")) |
157 | 177 |
|
| 178 | +(defun jcs-echobar--render-keycast () |
| 179 | + "Render `keycast'." |
| 180 | + (when (featurep 'keycast) |
| 181 | + (keycast--format jcs-echobar-keycast-format))) |
| 182 | + |
158 | 183 | (provide 'jcs-echobar) |
159 | 184 | ;;; jcs-echobar.el ends here |
0 commit comments