Skip to content

Commit

Permalink
biome-grid: add highlight current hour / day (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
SqrtMinusOne committed Mar 10, 2024
1 parent db0784e commit 6a19f63
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions biome-grid.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
:type 'boolean
:group 'biome)

(defcustom biome-grid-highlight-current t
"Highlight current hour or day.
This requires time formatted as iso8601."
:type 'boolean
:group 'boolean)

(defface biome-grid-highlight-current-face
'((t :inherit highlight))
"Highlight current hour or day."
:group 'biome)

(defun biome-grid--format-units (format)
"Add derived units to FORMAT.
Expand Down Expand Up @@ -646,6 +658,31 @@ transient switches)."
keymap)
"Keymap for `biome-grid-mode'.")

(defun biome-grid--maybe-highlight-current ()
"Highlight current hour or day (if hour is not found)."
(when biome-grid-highlight-current
(save-excursion
(goto-char (point-min))
(let ((needle-datetime
(substring
(format-time-string biome-grid-datetime-format (current-time))
;; Remove seconds
0 -3))
(needle-date
(format-time-string biome-grid-date-format (current-time)))
start end)
(if (search-forward needle-datetime nil t)
(setq start (line-beginning-position)
end (line-end-position))
(goto-char (point-min))
(when (search-forward needle-date nil t)
(setq start (line-beginning-position)
end (line-end-position))))
(when (and start end)
(let ((ov (make-overlay start end)))
(overlay-put ov 'priority -49)
(overlay-put ov 'face 'biome-grid-highlight-current-face)))))))

(define-derived-mode biome-grid-mode tabulated-list-mode "Biome Grid"
"Major mode for displaying biome results.
Expand All @@ -668,6 +705,7 @@ displaying more columns than the window width, so there's
(tabulated-list-print t)
(tabulated-list-init-header)
(toggle-truncate-lines 1)
(biome-grid--maybe-highlight-current)
(run-mode-hooks 'biome-grid-mode-hook))
(switch-to-buffer buf)))

Expand Down

0 comments on commit 6a19f63

Please sign in to comment.