<commit_before>(in-package :lem)

(export '(describe-key
          describe-bindings
          execute-command
          apropos-command))

(define-key *global-keymap* "C-x ?" 'describe-key)
(define-command describe-key () ()
  (message "describe-key: ")
  (redraw-display)
  (let* ((key (read-key-sequence))
         (cmd (find-keybind key)))
    (message "describe-key: ~a ~a"
             (kbd-to-string key)
             (command-name cmd))))

(defun describe-bindings-internal (s name keymap &optional first-p)
  (unless first-p
    (princ #\page s)
    (terpri s))
  (let ((column-width 16))
    (princ name s)
    (terpri s)
    (format s "~va~a~%" column-width "key" "binding")
    (format s "~va~a~%" column-width "---" "-------")
    (keymap-flatten-map keymap
                        (lambda (kbd command)
                          (format s "~va~a~%"
                                  column-width
                                  (kbd-to-string kbd)
                                  (symbol-name command))))
    (terpri s)))

(define-command describe-bindings () ()
  (let ((buffer (current-buffer)))
    (with-pop-up-typeout-window (s (make-buffer "*bindings*") :focus t :erase t)
      (describe-bindings-internal s
                                  "Major Mode Bindings"
                                  (mode-keymap (buffer-major-mode buffer))
                                  t)
      (describe-bindings-internal s
                                  "Global Bindings"
                                  *global-keymap*)
      (dolist (mode (buffer-minor-modes buffer))
        (describe-bindings-internal s
                                    (mode-name mode)
                                    (mode-keymap mode))))))

(define-key *global-keymap* "M-x" 'execute-command)
(define-command execute-command (arg) ("P")
  (let* ((name (prompt-for-line
                (if arg
                    (format nil "~D M-x " arg)
                    "M-x ")
                ""
                (lambda (str)
                  (if (find #\- str)
                      (completion-hypheen str (all-command-names))
                      (completion str (all-command-names))))<commit_msg>describe-bindings not show 'undeined-key' and downcase function name.<commit_after>(in-package :lem)

(export '(describe-key
          describe-bindings
          execute-command
          apropos-command))

(define-key *global-keymap* "C-x ?" 'describe-key)
(define-command describe-key () ()
  (message "describe-key: ")
  (redraw-display)
  (let* ((key (read-key-sequence))
         (cmd (find-keybind key)))
    (message "describe-key: ~a ~a"
             (kbd-to-string key)
             (command-name cmd))))

(defun describe-bindings-internal (s name keymap &optional first-p)
  (unless first-p
    (princ #\page s)
    (terpri s))
  (let ((column-width 16))
    (princ name s)
    (terpri s)
    (format s "~va~a~%" column-width "key" "binding")
    (format s "~va~a~%" column-width "---" "-------")
    (keymap-flatten-map keymap
                        (lambda (kbd command)
                          (unless (equal "UNDEFINED-KEY" (symbol-name command))
                            (format s "~va~(~a~)~%"
                                    column-width
                                    (kbd-to-string kbd)
                                    (symbol-name command)))))
    (terpri s)))

(define-command describe-bindings () ()
  (let ((buffer (current-buffer)))
    (with-pop-up-typeout-window (s (make-buffer "*bindings*") :focus t :erase t)
      (describe-bindings-internal s
                                  "Major Mode Bindings"
                                  (mode-keymap (buffer-major-mode buffer))
                                  t)
      (describe-bindings-internal s
                                  "Global Bindings"
                                  *global-keymap*)
      (dolist (mode (buffer-minor-modes buffer))
        (describe-bindings-internal s
                                    (mode-name mode)
                                    (mode-keymap mode))))))

(define-key *global-keymap* "M-x" 'execute-command)
(define-command execute-command (arg) ("P")
  (let* ((name (prompt-for-line
                (if arg
                    (format nil "~D M-x " arg)
                    "M-x ")
                ""
                (lambda (str)
                  (if (find #\- str)
                      (completion-hypheen str (all-command-names))
                      (completion str (all-command-names))))
{'fraction_non_alphanumeric': 0.138257993384785, 'fraction_numerical': 0.0008820286659316428, 'mean_word_length': 1.3674321503131524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5599346', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1293, 'n_words': 299}