Skip to content

Commit

Permalink
refac(setup): define mode line as variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Walheimat committed Jan 6, 2024
1 parent e4cd600 commit 7ff63a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 9 additions & 5 deletions test/whale-line-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,18 @@
(bydi ((:mock require :return t)
(:sometimes whale-line--build-segments)
add-hook
run-hooks)
run-hooks
(:watch mode-line-format)
(:watch whale-line--default-mode-line))
(whale-line-mode--setup)

(bydi-was-called-with run-hooks (list 'whale-line-setup-hook))
(bydi-was-called-nth-with add-hook (list 'pre-redisplay-functions #'whale-line--set-selected-window) 0)
(bydi-was-called-nth-with add-hook (list 'window-configuration-change-hook #'whale-line--calculate-space) 1)
(bydi-was-called-nth-with add-hook (list 'buffer-list-update-hook #'whale-line--queue-refresh) 2)

(eq 'format whale-line--default-mode-line)
(bydi-was-set-to mode-line-format whale-line-mode-line)
(bydi-was-set-to whale-line--default-mode-line 'format)

(bydi-toggle-sometimes)

Expand All @@ -929,15 +932,16 @@
(let ((mode-line-format 'whale)
(whale-line--default-mode-line 'other))

(bydi (run-hooks remove-hook)
(bydi (run-hooks
remove-hook
(:watch mode-line-format))
(whale-line-mode--teardown)

(bydi-was-called-with run-hooks (list 'whale-line-teardown-hook))
(bydi-was-called-nth-with remove-hook (list 'pre-redisplay-functions #'whale-line--set-selected-window) 0)
(bydi-was-called-nth-with remove-hook (list 'window-configuration-change-hook #'whale-line--calculate-space) 1)
(bydi-was-called-nth-with remove-hook (list 'buffer-list-update-hook #'whale-line--queue-refresh) 2)

(should (eq 'other mode-line-format)))))
(bydi-was-set-to mode-line-format 'other))))

(ert-deftest whale-line-mode ()
(bydi (whale-line-mode--setup whale-line-mode--teardown)
Expand Down
6 changes: 4 additions & 2 deletions whale-line.el
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ logging."

;;; -- Variables

(defvar whale-line-mode-line '("%e" (:eval (whale-line--format))))
(defvar whale-line--default-mode-line nil)

(defvar whale-line--segments nil)
(defvar whale-line--props nil)

(defvar whale-line--current-window nil)
(defvar whale-line--default-mode-line nil)

(defvar whale-line--padded-cache (make-hash-table))
(defvar whale-line--space-cache (make-hash-table))
Expand Down Expand Up @@ -1023,7 +1025,7 @@ If SOFT is t, uses `intern-soft'."
(add-hook 'buffer-list-update-hook #'whale-line--queue-refresh)

;; Set the new mode-line-format
(setq-default mode-line-format '("%e" (:eval (whale-line--format)))))
(setq-default mode-line-format whale-line-mode-line))

(defun whale-line-mode--teardown ()
"Tear down `whale-line-mode'."
Expand Down

0 comments on commit 7ff63a5

Please sign in to comment.