Skip to content

Commit

Permalink
fix post-cmd-hook, keep message between command
Browse files Browse the repository at this point in the history
  • Loading branch information
QiangF committed Mar 9, 2024
1 parent 7e95dfe commit 59dfd9d
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions mini-modeline.el
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,27 @@ Set this to the minimal value that doesn't cause truncation."
(setq mini-modeline--face-cookie
(face-remap-add-relative 'default mini-modeline--face-attr)))

(defvar my-log-flag nil)
(defvar message-log-flag nil)

(defun my-log-flag-toggle ()
(defun message-log (force &rest args)
"Log message into message buffer with ARGS as same parameters in `message'."
(when (or message-log-flag force)
(save-excursion
(with-current-buffer "*Messages*"
(let ((inhibit-read-only t)
(log-text (apply #'format args)))
(goto-char (point-max))
(insert log-text)
(insert "\n")
(notify "message:" log-text))))))

(defun message-log-flag-toggle ()
(interactive)
(setq my-log-flag (not my-log-flag)))
(setq message-log-flag (not message-log-flag)))

(defun mini-modeline--log (force &rest args)
"Log message into message buffer with ARGS as same parameters in `message'."
(when (or my-log-flag force)
(when (or message-log-flag force)
(save-excursion
(with-current-buffer "*Messages*"
(let ((inhibit-read-only t)
Expand Down Expand Up @@ -201,7 +213,7 @@ Return value is (STRING . LINES)."

(defvar mini-modeline--unprocessed-message '())

(defun mini-modeline--display (&optional force)
(defun mini-modeline--display (&optional force keep-msg)
"Update mini-modeline."
(save-match-data
(condition-case err
Expand All @@ -219,13 +231,14 @@ Return value is (STRING . LINES)."
(setq mini-modeline-content (mini-modeline--multi-lr-render
(or mini-modeline-content-left (format-mode-line mini-modeline--l-format))
(format-mode-line mini-modeline--r-format)))

(setq mini-modeline--unprocessed-message '())
(unless keep-msg
(setq mini-modeline--unprocessed-message '()))
(setq mini-modeline--last-update-time (current-time))
(run-at-time 0.1 nil 'mini-modeline--set-minibuffer
mini-modeline-content
mini-modeline-window
mini-modeline-buffer)))))))
(setq mini-modeline--timer
(run-at-time 0.1 nil 'mini-modeline--set-minibuffer
mini-modeline-content
mini-modeline-window
mini-modeline-buffer))))))))
((error debug)
(mini-modeline--log t "mini-modeline: %s\n" err)))))

Expand Down Expand Up @@ -260,7 +273,7 @@ Return value is (STRING . LINES)."
(add-to-list 'mini-modeline--unprocessed-message mini-modeline--message t)
(mini-modeline--log nil "Reroute message %s minibuffer active: %s input pending: %s"
msg (active-minibuffer-window) (input-pending-p))
(mini-modeline--display 'force))
(mini-modeline--display 'force t))
msg))

(defmacro mini-modeline--wrap (func &rest body)
Expand All @@ -276,13 +289,15 @@ BODY will be supplied with orig-func and args."
"Pre command hook of mini-modeline."
;; Don't echo keystrokes when in middle of command
(setq echo-keystrokes 0)
(mini-modeline--display)
(setq mini-modeline--idle nil))

(defsubst mini-modeline--post-cmd ()
"Post command hook of mini-modeline."
(mini-modeline--display)
;; (message-log t "post-cmd %s %s" (string-join mini-modeline--unprocessed-message "\n") (current-buffer))
(setq mini-modeline--idle t)
(mini-modeline--display)
;; (unless (active-minibuffer-window)
;; (mini-modeline--display))
(setq echo-keystrokes mini-modeline--echo-keystrokes))

(defvar mini-modeline--orig-resize-mini-windows resize-mini-windows)
Expand All @@ -294,7 +309,8 @@ BODY will be supplied with orig-func and args."

(defsubst mini-modeline--exit-minibuffer ()
"`minibuffer-exit-hook' of mini-modeline."
(setq resize-mini-windows mini-modeline--orig-resize-mini-windows))
(setq resize-mini-windows mini-modeline--orig-resize-mini-windows)
(mini-modeline--display))

(declare-function anzu--cons-mode-line "ext:anzu")
(declare-function anzu--reset-mode-line "ext:anzu")
Expand Down Expand Up @@ -342,7 +358,7 @@ BODY will be supplied with orig-func and args."
(setq resize-mini-windows mini-modeline--orig-resize-mini-windows)
(redisplay)

;; (defvar mini-modeline--timer nil)
(defvar mini-modeline--timer nil)
;; (setq mini-modeline--timer (run-with-idle-timer 0.1 t #'mini-modeline--display))

(setq message-original (symbol-function 'message))
Expand Down

0 comments on commit 59dfd9d

Please sign in to comment.