[Top][All Lists]

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

[elpa] externals/which-key c87b0ce 02/51: Add debugging messages for buf

From: Stefan Monnier
Subject: [elpa] externals/which-key c87b0ce 02/51: Add debugging messages for buffer sizing
Date: Tue, 8 Sep 2020 10:26:14 -0400 (EDT)

branch: externals/which-key
commit c87b0ce78213f922a725be1e0ae2dede1cf29516
Author: Justin Burkett <justin@burkett.cc>
Commit: Justin Burkett <justin@burkett.cc>

    Add debugging messages for buffer sizing
 which-key.el | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/which-key.el b/which-key.el
index 08f259d..2aeaeaa 100644
--- a/which-key.el
+++ b/which-key.el
@@ -640,12 +640,13 @@ used.")
 (defvar which-key--automatic-display nil
   "Internal: Non-nil if popup was triggered with automatic
+(defvar which-key--debug-buffer-name nil
+  "If non-nil, use this buffer for debug messages.")
 (defvar which-key--multiple-locations nil)
 (defvar which-key--inhibit-next-operator-popup nil)
 (defvar which-key--prior-show-keymap-args nil)
 (defvar which-key--previous-frame-size nil)
 (defvar which-key--prefix-title-alist nil)
-(defvar which-key--debug nil)
 (defvar which-key--evil-keys-regexp (eval-when-compile
                                       (regexp-opt '("-state"))))
 (defvar which-key--ignore-non-evil-keys-regexp
@@ -701,6 +702,14 @@ update.")
   (when which-key--pages-obj
     (which-key--pages-prefix which-key--pages-obj)))
+(defmacro which-key--debug-message (&rest msg)
+  `(when which-key--debug-buffer-name
+     (let ((buf (get-buffer-create which-key--debug-buffer-name))
+           (fmt-msg (format ,@msg)))
+       (with-current-buffer buf
+         (goto-char (point-max))
+         (insert "\n" fmt-msg "\n")))))
 ;;; Third-party library support
 ;;;; Evil
@@ -1919,7 +1928,7 @@ as well as metadata."
         (push page-width page-widths))
        :pages (nreverse pages)
-       :height avl-lines
+       :height (if (> n-pages 1) avl-lines (min avl-lines n-keys))
        :widths (nreverse page-widths)
        :keys/page (reverse keys/page)
        :page-nums (number-sequence 1 n-pages)
@@ -1981,6 +1990,12 @@ is the width of the live window."
             (or prefix-title
                  (key-description prefix-keys))))
+      (which-key--debug-message "Frame height: %s
+Minibuffer height: %s
+Max dimensions: (%s,%s)
+Available for bindings: (%s,%s)
+Actual lines: %s" (frame-height) (window-text-height (minibuffer-window))
+max-lines max-width avl-lines avl-width (which-key--pages-height result))
 (defun which-key--lighter-status ()
@@ -2495,7 +2510,7 @@ is selected interactively by mode in 
     (&optional prefix-keys from-keymap filter prefix-title)
   "Fill `which-key--buffer' with key descriptions and reformat.
 Finally, show the buffer."
-  (let ((start-time (when which-key--debug (current-time)))
+  (let ((start-time (current-time))
         (formatted-keys (which-key--get-bindings
                          prefix-keys from-keymap filter))
         (prefix-desc (key-description prefix-keys)))
@@ -2510,9 +2525,9 @@ Finally, show the buffer."
                     formatted-keys prefix-keys prefix-title))
-    (when which-key--debug
-      (message "On prefix \"%s\" which-key took %.0f ms." prefix-desc
-               (* 1000 (float-time (time-since start-time)))))))
+    (which-key--debug-message
+     "On prefix \"%s\" which-key took %.0f ms." prefix-desc
+     (* 1000 (float-time (time-since start-time))))))
 (defun which-key--this-command-keys ()
   "Version of `this-single-command-keys' corrected for key-chords and 

reply via email to

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