Add the defunit macro as a helper to define units
This commit is contained in:
parent
114a9599ac
commit
74d49748d4
19
noether.el
19
noether.el
|
@ -27,6 +27,7 @@
|
|||
(require 'seq)
|
||||
(require 'posframe)
|
||||
|
||||
|
||||
(defvar noether/views ()
|
||||
"A list of views that noether should manage.
|
||||
|
||||
|
@ -93,6 +94,24 @@ the show function."
|
|||
|
||||
|
||||
|
||||
(defmacro defunit (name docs &rest props)
|
||||
"Define a unit with the given NAME, DOCS and a set of PROPS.
|
||||
It will define a function with the given NAME that accepts any
|
||||
parameter in form of key/values that will override any original
|
||||
key/value from the original definition."
|
||||
|
||||
(declare (doc-string 2))
|
||||
(let* ((parsed-body (noether/-extract-props props))
|
||||
;; For now we don't have any use for the body
|
||||
(_ (car parsed-body))
|
||||
(orig-props (cdr parsed-body)))
|
||||
|
||||
`(defun ,name (&rest f-props)
|
||||
,docs
|
||||
(append '(:name ,(intern (format ":%s" name)))
|
||||
f-props (list ,@orig-props)))))
|
||||
|
||||
|
||||
|
||||
(defun noether/show (view)
|
||||
"Draw the given VIEW on the screen."
|
||||
|
|
|
@ -48,6 +48,31 @@
|
|||
"Just return the current time."
|
||||
v)
|
||||
|
||||
(defunit line-unit
|
||||
"Show the line number."
|
||||
:label "L: "
|
||||
:len 4
|
||||
:init (lambda ()
|
||||
(add-hook 'post-command-hook #'noether/-update-line))
|
||||
:deinit (lambda ()
|
||||
(remove-hook 'post-command-hook #'noether/-update-line))
|
||||
:var 'noether/-line
|
||||
:fn #'noether/-line-format)
|
||||
|
||||
(defunit time-unit
|
||||
"just the time for your bar."
|
||||
:label "T: "
|
||||
:len 8
|
||||
:init (lambda ()
|
||||
(setq noether/-timer
|
||||
(run-with-timer 1 1 #'noether/-set-time)))
|
||||
:deinit (lambda ()
|
||||
(when noether/-timer
|
||||
(cancel-timer noether/-timer)))
|
||||
|
||||
:var 'noether/-time
|
||||
:fn #'noether/-time-format)
|
||||
|
||||
(defview example-bar
|
||||
"Just a test view"
|
||||
:managed? t
|
||||
|
@ -56,30 +81,8 @@
|
|||
:separator "|"
|
||||
:units
|
||||
(list
|
||||
(list
|
||||
:label "L: "
|
||||
:name :line
|
||||
:len 4
|
||||
:init (lambda ()
|
||||
(add-hook 'post-command-hook #'noether/-update-line))
|
||||
:deinit (lambda ()
|
||||
(remove-hook 'post-command-hook #'noether/-update-line))
|
||||
:var 'noether/-line
|
||||
:fn #'noether/-line-format)
|
||||
(list
|
||||
:label "T: "
|
||||
:name :time
|
||||
:len 8
|
||||
:init (lambda ()
|
||||
(setq noether/-timer
|
||||
(run-with-timer 1 1 #'noether/-set-time)))
|
||||
:deinit (lambda ()
|
||||
(when noether/-timer
|
||||
(cancel-timer noether/-timer)))
|
||||
|
||||
:var 'noether/-time
|
||||
:fn #'noether/-time-format)
|
||||
))
|
||||
(line-unit)
|
||||
(time-unit :label "<B>")))
|
||||
|
||||
|
||||
(setq noether/views (list example-bar))
|
||||
|
|
Loading…
Reference in New Issue