emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/keycast 3a8c4db51a 21/31: keycast-log-mode: New mode


From: ELPA Syncer
Subject: [nongnu] elpa/keycast 3a8c4db51a 21/31: keycast-log-mode: New mode
Date: Sun, 9 Jan 2022 05:58:47 -0500 (EST)

branch: elpa/keycast
commit 3a8c4db51ac4ee4be43c96295979eab508548bfb
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    keycast-log-mode: New mode
---
 README.md  |  9 ++++---
 keycast.el | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 90 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 2676e90764..57ade56ede 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,11 @@
 Show current command and its key in the mode line
 =================================================
 
-This package provides Keycast mode.  Once enabled, that mode shows
-the current command and its key or mouse binding in the mode line,
-and updates them whenever another command is invoked.
+This package provides two modes that display the current command
+and its key or mouse binding, and update the displayed information
+once another command is invoked.
+
+`keycast-mode` displays the command and event in the mode-line and
+`keycast-log-mode` displays them in a dedicated frame.
 
 ![screenshot](http://readme.emacsair.me/keycast.png)
diff --git a/keycast.el b/keycast.el
index 7e76e78122..609c14d054 100644
--- a/keycast.el
+++ b/keycast.el
@@ -146,6 +146,38 @@ instead."
                         (const   :tag "Use actual command" t)
                         (symbol  :tag "Substitute command")))))
 
+(defcustom keycast-log-format "%-20K%C\n"
+  "The format spec used by `keycast-log-mode'.
+
+%s `keycast-separator-width' spaces.
+%k The key using the `keycast-key' face and padding.
+%K The key with no styling without any padding.
+%c The command using the `keycast-command' face.
+%C The command with-no styling.
+%r The times the command was repeated."
+  :package-version '(keycast . "2.0.0")
+  :group 'keycast
+  :type 'string)
+
+(defcustom keycast-log-frame-alist
+  '((minibuffer . nil))
+  "Alist of frame parameters used by `keycast-log-mode's frame."
+  :package-version '(keycast . "2.0.0")
+  :group 'keycast
+  :type 'string)
+
+(defcustom keycast-log-newest-first t
+  "Whether `keycast-log-mode' inserts events at beginning of buffer."
+  :package-version '(keycast . "2.0.0")
+  :group 'keycast
+  :type 'boolean)
+
+(defcustom keycast-log-buffer-name "*keycast*"
+  "The name of the buffer used by `keycast-log-mode'."
+  :package-version '(keycast . "2.0.0")
+  :group 'keycast
+  :type 'string)
+
 (defface keycast-key
   '((t (:weight bold
         :height 1.2
@@ -159,7 +191,10 @@ instead."
   "When Keycast mode is enabled, face used for the command in the mode line."
   :group 'keycast)
 
-;;; Core
+;;; Common
+
+(defvar keycast-mode)
+(defvar keycast-log-mode)
 
 (defvar keycast--this-command nil)
 (defvar keycast--this-command-keys nil)
@@ -175,7 +210,10 @@ instead."
   ;; values have been reset to nil.
   (setq keycast--this-command-keys (this-command-keys))
   (setq keycast--this-command this-command)
-  (force-mode-line-update))
+  (when keycast-log-mode
+    (keycast-log-update-buffer))
+  (when keycast-mode
+    (force-mode-line-update)))
 
 (defun keycast--format (format)
   (and (not keycast--reading-passwd)
@@ -204,6 +242,8 @@ instead."
                               (format " x%s" (1+ keycast--command-repetitions))
                             "")))))))))
 
+;;; Mode-Line
+
 (defvar keycast--removed-tail nil)
 
 ;;;###autoload
@@ -232,7 +272,8 @@ instead."
              (setcar cons (cadr cons))
              (setcdr cons (cddr cons)))))
     (setq keycast--removed-tail nil)
-    (remove-hook 'pre-command-hook 'keycast--update)))
+    (unless keycast-log-mode
+      (remove-hook 'pre-command-hook 'keycast--update))))
 
 (defun keycast--tree-member (elt tree)
   (or (member elt tree)
@@ -265,6 +306,46 @@ instead."
 (put 'mode-line-keycast 'risky-local-variable t)
 (make-variable-buffer-local 'mode-line-keycast)
 
+;;; Log-Buffer
+
+;;;###autoload
+(define-minor-mode keycast-log-mode
+  "Log invoked commands and their key bindings in a buffer."
+  :global t
+  (cond
+   (keycast-log-mode
+    (add-hook 'pre-command-hook 'keycast--update t)
+    (keycast-log-update-buffer))
+   ((not keycast-mode)
+    (remove-hook 'pre-command-hook 'keycast--update))))
+
+(defun keycast-log-update-buffer ()
+  (when keycast--this-command
+    (let ((buf (get-buffer keycast-log-buffer-name)))
+      (unless (buffer-live-p buf)
+        (setq buf (get-buffer-create keycast-log-buffer-name))
+        (with-current-buffer buf
+          (setq buffer-read-only t)
+          (setq mode-line-format nil)
+          (let ((default-frame-alist keycast-log-frame-alist))
+            (switch-to-buffer-other-frame (current-buffer)))))
+      (with-current-buffer buf
+        (goto-char (if keycast-log-newest-first (point-min) (point-max)))
+        (let ((inhibit-read-only t))
+          (insert (keycast--format keycast-log-format)))
+        (goto-char (if keycast-log-newest-first (point-min) (point-max)))))))
+
+(defun keycast-log-erase-buffer ()
+  "Erase the contents of `keycast-log-mode's buffer."
+  (interactive)
+  (let ((buf (get-buffer keycast-log-buffer-name)))
+    (when (buffer-live-p buf)
+      (with-current-buffer buf
+        (let ((inhibit-read-only t))
+          (erase-buffer))))))
+
+;;; Common
+
 (defun keycast--read-passwd (fn prompt &optional confirm default)
   (let ((keycast--reading-passwd t))
     (funcall fn prompt confirm default)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]