summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-12 19:23:39 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-12 19:23:39 +0800
commitbde550449375a9f5f6dbc652cce2e017de9df835 (patch)
tree053cca043bc8d4403692965c38150b81303132a9
parent99a236afe70c746c75c22bc3883f57f0dc5f2ab9 (diff)
Use the package "keycast"
Now I can conveniently display my key-bindings in the mode line.
-rw-r--r--keycast-conf.el59
-rw-r--r--modeline.el14
2 files changed, 73 insertions, 0 deletions
diff --git a/keycast-conf.el b/keycast-conf.el
new file mode 100644
index 0000000..b71f9c9
--- /dev/null
+++ b/keycast-conf.el
@@ -0,0 +1,59 @@
+;;; keycast-conf.el --- Configuration of keycast mode -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 李俊緯
+
+;; Author: 李俊緯 <mmemmew@gmail.com>
+;; Keywords: emulations, help, tools
+
+;; 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 this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Configuring the mode to my liking.
+
+;;; Code:
+
+;;; The original minor mode tries to insert an element to the
+;;; `mode-line-format'. But my mode line format consists of one
+;;; custom element only, so it is not going to work that way. Rather,
+;;; I shall define my own minor mode to just skip this part.
+
+(autoload 'use-package "basic")
+
+(use-package "keycast" 'keycast)
+
+(require 'keycast)
+
+(setq keycast-separator-width 0)
+
+(setq keycast-substitute-alist
+ (list (list #'self-insert-command (string #x2e) "Typing...")))
+
+(define-minor-mode durand-keycast-mode
+ "Show current command and its key binding in the mode line."
+ :global t
+ :group 'keycast
+ :lighter "K"
+ (cond
+ (durand-keycast-mode
+ (add-hook 'pre-command-hook #'keycast--update t))
+ (keycast-log-mode)
+ ((remove-hook 'pre-command-hook #'keycast--update))))
+
+(defvar durand-view-map)
+
+(define-key durand-view-map (vector ?k) #'durand-keycast-mode)
+
+(provide 'keycast-conf)
+;;; keycast-conf.el ends here
diff --git a/modeline.el b/modeline.el
index 683bf3d..b244463 100644
--- a/modeline.el
+++ b/modeline.el
@@ -91,6 +91,8 @@
(modeline-spc)
(modeline-format-buffer-size)
(modeline-spc)
+ (modeline-format-keycast)
+ (modeline-spc)
(modeline-format-minor-modes)))
;;;###autoload
@@ -366,6 +368,18 @@ mouse-2: Show help for minor mode
mouse-3: Toggle minor modes"
mode-line-minor-mode-keymap))
+(defun modeline-format-keycast ()
+ "Format the keycast information."
+ (declare (side-effect-free t))
+ (modeline-propertize
+ (format-mode-line mode-line-keycast)
+ nil
+ "Minor mode
+mouse-1: Display minor mode menu
+mouse-2: Show help for minor mode
+mouse-3: Toggle minor modes"
+ mode-line-minor-mode-keymap))
+
;;; NOTE: The minor mode menu does not work with my custom mode line.
;;;###autoload