Add the date unit and fix the init-fn order

This commit is contained in:
Sameer Rahmani 2024-04-19 19:32:00 +01:00
parent 7f197504b5
commit 60d26d8331
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
3 changed files with 42 additions and 8 deletions

View File

@ -29,6 +29,7 @@
(defvar line-unit)
(defvar buffer-name-unit)
(defvar time-unit)
(defvar date-unit)
(defvar mode-name-unit)
(defvar projectile-project-unit)
(declare-function projectile-project-name "projectile-project-name" ()))
@ -105,7 +106,7 @@ Emacs knowing."
(defvar noether--timer nil)
(defun noether--set-time ()
"Set the current time to the internal var which is being watched."
(setq noether--time (format-time-string "%m-%d %H:%M")))
(setq noether--time (format-time-string "%H:%M")))
(defun noether--time-format (_ v _ _)
"Just return the current time V."
@ -115,7 +116,7 @@ Emacs knowing."
(noether-defunit time-unit
"just the time for your bar."
:label "T:"
:len 8
:len 5
:init (lambda ()
(setq noether--timer
(run-with-timer 1 1 #'noether--set-time)))
@ -126,6 +127,35 @@ Emacs knowing."
:var 'noether--time
:fn #'noether--time-format)
;; ============================================================================
;; Daet indicator
;; ============================================================================
(defvar noether--date "")
(defvar noether--date-timer nil)
(defun noether--set-date ()
"Set the current date to the internal var which is being watched."
(setq noether--date (format-time-string "%m-%d")))
(defun noether--date-format (_ v _ _)
"Just return the current date V."
v)
(noether-defunit date-unit
"just the date for your bar."
:label "D:"
:len 5
:init (lambda ()
(noether--set-date)
(setq noether--date-timer
(run-with-timer 3600 1 #'noether--set-date)))
:deinit (lambda ()
(when noether--date-timer
(cancel-timer noether--date-timer)))
:var 'noether--date
:fn #'noether--date-format)
;; ============================================================================
;; Mode name
;; ============================================================================

View File

@ -28,6 +28,7 @@
;;; Code:
(require 'seq)
(require 'posframe)
(require 'subr-x)
(defgroup noether nil
"The customization group for the noether-mode."
@ -255,9 +256,6 @@ side BUF and F to it. It's simple trick to make small a closure."
(when (null f)
(error (format "No `fn' in %s" unit)))
(when init-fn
(funcall init-fn))
(when var
;; Setup the watcher and the watcher remover
(add-variable-watcher var updater)
@ -268,6 +266,10 @@ side BUF and F to it. It's simple trick to make small a closure."
(remove-variable-watcher var updater))
(get view-name :watcher-removers))))
(when init-fn
(funcall init-fn))
(put view-name :updaters
(cons updater (get view-name :updaters)))

View File

@ -43,8 +43,7 @@
"A simple and minimalist mode-line like status bar"
:managed? t
:buffer "*modeline*"
;;:binding (kbd "C-c 1")
:timeout 0
:binding (kbd "C-c 1")
:separator "|"
:visible? t
:frame
@ -53,6 +52,7 @@
;; (- (frame-outer-height) 40))
:poshandler #'noether--bottom-right
:border-width 0
;;:timeout 5
:border-color "#bd93f9")
@ -60,7 +60,9 @@
(list
(line-unit :label "")
(buffer-name-unit :label "B: ")
(mode-name-unit :label "M: ")))
(mode-name-unit :label "M: ")
(time-unit)
(date-unit)))
(setq noether-views (list mode-line))