Fix some of the low hanging linting errors
This commit is contained in:
parent
6182158fc6
commit
f8fb71c307
120
noether.el
120
noether.el
|
@ -6,7 +6,7 @@
|
|||
;; URL: https://devheroes.codes/lxsameer/noether
|
||||
;; Version: 0.1.0
|
||||
;; Keywords: frames, modeline
|
||||
;; Package-Requires: (posframe seq)
|
||||
;; Package-Requires: (posframe (emacs "26.1"))
|
||||
;;
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
|
@ -28,24 +28,24 @@
|
|||
(require 'posframe)
|
||||
|
||||
|
||||
(defvar noether/views ()
|
||||
(defvar noether-views ()
|
||||
"A list of views that noether should manage.
|
||||
|
||||
You should adding your views to this var, so noether can activate them
|
||||
on demand.")
|
||||
|
||||
|
||||
(defmacro noether/-unit-get (unit key &optional default)
|
||||
(defmacro noether--unit-get (unit key &optional default)
|
||||
"Return the value of the KEY in UNIT or the DEFAULT value if it doesn't exist."
|
||||
`(or (plist-get ,unit ,key) ,default))
|
||||
|
||||
|
||||
(defmacro noether/-view-get (view key &optional default)
|
||||
(defmacro noether--view-get (view key &optional default)
|
||||
"Return the value of the KEY in VIEW or the DEFAULT value if it doesn't exist."
|
||||
`(or (plist-get ,view ,key) ,default))
|
||||
|
||||
|
||||
(defun noether/-extract-props (body-list &optional acc)
|
||||
(defun noether--extract-props (body-list &optional acc)
|
||||
"Extract the props pairs from BODY-LIST with an optional accumulator ACC.
|
||||
|
||||
It will returen a pair in form of (body . props)."
|
||||
|
@ -53,17 +53,17 @@ It will returen a pair in form of (body . props)."
|
|||
(rest (cdr body-list)))
|
||||
|
||||
(if (and k (keywordp k))
|
||||
(noether/-extract-props
|
||||
(noether--extract-props
|
||||
(cdr rest)
|
||||
(cons (cdr rest) (plist-put (cdr acc) k (car rest))))
|
||||
(cons body-list (cdr acc)))))
|
||||
|
||||
|
||||
(defun noether/-create-placeholder (unit)
|
||||
(defun noether--create-placeholder (unit)
|
||||
"Create a placeholder for UNIT based on its :label and :len."
|
||||
(concat
|
||||
(noether/-unit-get unit :label "")
|
||||
(make-string (noether/-unit-get unit :len 0) ? )))
|
||||
(noether--unit-get unit :label "")
|
||||
(make-string (noether--unit-get unit :len 0) ? )))
|
||||
|
||||
|
||||
(defmacro defview (name docs &rest body)
|
||||
|
@ -72,11 +72,11 @@ BODY will be parsed in a way that any starting pair of keyword and value
|
|||
will be used as the view properties and the rest will be the body of
|
||||
the show function."
|
||||
(declare (doc-string 2))
|
||||
(let* ((parsed-body (noether/-extract-props body))
|
||||
(let* ((parsed-body (noether--extract-props body))
|
||||
(show-body (car parsed-body))
|
||||
(props (cdr parsed-body))
|
||||
(initial-content
|
||||
(mapconcat #'noether/-create-placeholder (eval (plist-get props :units))
|
||||
(mapconcat #'noether--create-placeholder (eval (plist-get props :units))
|
||||
(or (plist-get props :separator) ""))))
|
||||
|
||||
`(progn
|
||||
|
@ -101,7 +101,7 @@ 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))
|
||||
(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)))
|
||||
|
@ -113,18 +113,18 @@ key/value from the original definition."
|
|||
|
||||
|
||||
|
||||
(defun noether/show (view)
|
||||
(defun noether-show (view)
|
||||
"Draw the given VIEW on the screen."
|
||||
;; View has to be processed at this stage
|
||||
(interactive)
|
||||
(let* ((show-fn (noether/-view-get view :show (lambda ())))
|
||||
(name (noether/-view-get view :name))
|
||||
(let* ((show-fn (noether--view-get view :show (lambda ())))
|
||||
(name (noether--view-get view :name))
|
||||
;; What if the user killed the buffer before?
|
||||
(buf (get-buffer-create (noether/-view-get view :buffer (format "*%s*" name)))))
|
||||
(buf (get-buffer-create (noether--view-get view :buffer (format "*%s*" name)))))
|
||||
;; TODO: Check to see whether the buffer is populated. If not, it means
|
||||
;; that user killed the buffer manually. We need to repopulate it
|
||||
;; again
|
||||
(when (noether/-view-get view :managed?)
|
||||
(when (noether--view-get view :managed?)
|
||||
(with-current-buffer buf
|
||||
(funcall show-fn)
|
||||
;;(mapc #'funcall (get name :updaters))
|
||||
|
@ -132,22 +132,22 @@ key/value from the original definition."
|
|||
|
||||
(posframe-show
|
||||
buf
|
||||
:min-height (noether/-view-get view :height 1)
|
||||
:min-width (noether/-view-get view :width 10)
|
||||
:min-height (noether--view-get view :height 1)
|
||||
:min-width (noether--view-get view :width 10)
|
||||
|
||||
:position '(0 . 0) ;;(cons (- (frame-outer-width) 10) (- (frame-outer-height) 10))
|
||||
|
||||
;;:poshandler #'posframe-poshandler-frame-bottom-right-corner
|
||||
:border-width (noether/-view-get view :border 0)
|
||||
:border-color (noether/-view-get view :border-color "#eeeefe")
|
||||
:accewpt-focus (noether/-view-get view :accept-focus)
|
||||
:timeout (noether/-view-get view :timeout 5)
|
||||
:refresh (noether/-view-get view :refresh 0.5))))
|
||||
:border-width (noether--view-get view :border 0)
|
||||
:border-color (noether--view-get view :border-color "#eeeefe")
|
||||
:accewpt-focus (noether--view-get view :accept-focus)
|
||||
:timeout (noether--view-get view :timeout 5)
|
||||
:refresh (noether--view-get view :refresh 0.5))))
|
||||
|
||||
|
||||
;; We need to keep this function as simple as possible
|
||||
;; and avoid any performance pitfalls
|
||||
(defun noether/update-unit (buf f start-point len watch-params)
|
||||
(defun noether-update-unit (buf f start-point len watch-params)
|
||||
"Update the buffer BUF at START-POINT with length LEN by calling F.
|
||||
It will pass WATCH-PARAMS to the unit's `:fn'"
|
||||
;; call f get the return value and put it in the dedicated cell
|
||||
|
@ -159,32 +159,32 @@ It will pass WATCH-PARAMS to the unit's `:fn'"
|
|||
(insert (truncate-string-to-width res len))))))
|
||||
|
||||
|
||||
(defun noether/-make-updater (buf f start-point len)
|
||||
(defun noether--make-updater (buf f start-point len)
|
||||
"Create an updater for the given buffer BUF using the function F.
|
||||
It will call `noether/update-unit' and path START-POINT and LEN along
|
||||
It will call `noether-update-unit' and path START-POINT and LEN along
|
||||
side BUF and F to it. It's simple trick to make small a closure."
|
||||
|
||||
;; `add-watch-params' is a list of 4 elements that `add-variable-watcher'
|
||||
;; passes to it's handler
|
||||
(lambda (&rest add-watch-params)
|
||||
(noether/update-unit buf f start-point len add-watch-params)))
|
||||
(noether-update-unit buf f start-point len add-watch-params)))
|
||||
|
||||
|
||||
(defun noether/-setup-unit (point-state view unit)
|
||||
(defun noether--setup-unit (point-state view unit)
|
||||
"Setup the given UNIT in respect of VIEW using the POINT-STATE as the boundary."
|
||||
(let* ((init-fn (noether/-unit-get unit :init))
|
||||
(f (noether/-unit-get unit :fn))
|
||||
(len (noether/-unit-get unit :len))
|
||||
(label (noether/-unit-get unit :label ""))
|
||||
(buf (noether/-view-get view :buffer))
|
||||
(sep (noether/-view-get view :separator))
|
||||
(var (noether/-unit-get unit :var))
|
||||
(name (noether/-unit-get unit :name))
|
||||
(view-name (noether/-view-get view :name))
|
||||
(let* ((init-fn (noether--unit-get unit :init))
|
||||
(f (noether--unit-get unit :fn))
|
||||
(len (noether--unit-get unit :len))
|
||||
(label (noether--unit-get unit :label ""))
|
||||
(buf (noether--view-get view :buffer))
|
||||
(sep (noether--view-get view :separator))
|
||||
(var (noether--unit-get unit :var))
|
||||
(name (noether--unit-get unit :name))
|
||||
(view-name (noether--view-get view :name))
|
||||
(start-point (+ point-state (length label)))
|
||||
(end-point (+ start-point (noether/-unit-get unit :len 0)))
|
||||
(end-point (+ start-point (noether--unit-get unit :len 0)))
|
||||
;; Just a small trick to make the resulting closure smaller
|
||||
(updater (noether/-make-updater buf f start-point len)))
|
||||
(updater (noether--make-updater buf f start-point len)))
|
||||
|
||||
(when (null name)
|
||||
(error (format "No :name for unit %s" unit)))
|
||||
|
@ -212,62 +212,62 @@ side BUF and F to it. It's simple trick to make small a closure."
|
|||
(+ end-point (length (or sep "")))))
|
||||
|
||||
|
||||
(defun noether/-reset-view-state (view)
|
||||
(defun noether--reset-view-state (view)
|
||||
"Reset the state stored in VIEW.
|
||||
E.g. the updaters list."
|
||||
(put (noether/-view-get view :name) :updaters nil))
|
||||
(put (noether--view-get view :name) :updaters nil))
|
||||
|
||||
|
||||
(defun noether/-setup-views (view)
|
||||
(defun noether--setup-views (view)
|
||||
"Setup the given VIEW by setting up its units."
|
||||
(when (not (listp view))
|
||||
(error (format "The given value as a view is not a list: %s" view)))
|
||||
|
||||
(noether/-reset-view-state view)
|
||||
(noether--reset-view-state view)
|
||||
|
||||
(let ((name (noether/-view-get view :name))
|
||||
(binding (noether/-view-get view :binding)))
|
||||
(let ((name (noether--view-get view :name))
|
||||
(binding (noether--view-get view :binding)))
|
||||
|
||||
(when (not (null binding))
|
||||
(define-key global-noethor-mode-map binding
|
||||
(lambda () (interactive) (noether/show view))))
|
||||
(lambda () (interactive) (noether-show view))))
|
||||
|
||||
(with-current-buffer (get-buffer-create (noether/-view-get view :buffer (format "*%s*" name)))
|
||||
(with-current-buffer (get-buffer-create (noether--view-get view :buffer (format "*%s*" name)))
|
||||
(erase-buffer)
|
||||
(goto-char 0)
|
||||
(insert (get name :initial-content))))
|
||||
|
||||
(seq-reduce
|
||||
(lambda (state u)
|
||||
(noether/-setup-unit state view u))
|
||||
(noether/-view-get view :units)
|
||||
(noether--setup-unit state view u))
|
||||
(noether--view-get view :units)
|
||||
0))
|
||||
|
||||
(defun noether/-teardown-unit (unit)
|
||||
(defun noether--teardown-unit (unit)
|
||||
"Tear down the given UNIT by calling the `:deinit' function and removing possible watches."
|
||||
(let ((deinit (noether/-unit-get unit :deinit (lambda ()))))
|
||||
(let ((deinit (noether--unit-get unit :deinit (lambda ()))))
|
||||
(funcall deinit)))
|
||||
|
||||
|
||||
(defun noether/-teardown-views (view)
|
||||
(defun noether--teardown-views (view)
|
||||
"Tear down the given VIEW to avoid any zombie watcher or timer n stuff."
|
||||
(let ((name (noether/-view-get view :name)))
|
||||
(mapc #'noether/-teardown-unit (noether/-view-get view :units))
|
||||
(let ((name (noether--view-get view :name)))
|
||||
(mapc #'noether--teardown-unit (noether--view-get view :units))
|
||||
(mapc #'funcall (get name :watcher-removers))
|
||||
(kill-buffer
|
||||
(noether/-view-get view :buffer (format "*%s*" name)))
|
||||
(funcall (noether/-view-get view :deinit (lambda ())))))
|
||||
(noether--view-get view :buffer (format "*%s*" name)))
|
||||
(funcall (noether--view-get view :deinit (lambda ())))))
|
||||
|
||||
|
||||
(define-minor-mode global-noethor-mode
|
||||
(define-minor-mode noethor-global-mode
|
||||
"A minor mode that keep tracks of different status blocks.
|
||||
It reports them back in a status bar like frame."
|
||||
:global t
|
||||
:lighter " ST42"
|
||||
:keymap (make-sparse-keymap)
|
||||
(if global-noethor-mode
|
||||
(mapc #'noether/-setup-views noether/views)
|
||||
(mapc #'noether/-teardown-views noether/views)))
|
||||
(mapc #'noether--setup-views noether-views)
|
||||
(mapc #'noether--teardown-views noether-views)))
|
||||
|
||||
|
||||
(provide 'noether)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
;; URL: https://devheroes.codes/lxsameer/noether
|
||||
;; Version: 0.1.0
|
||||
;; Keywords: frames, modeline
|
||||
;; Package-Requires: (posframe seq)
|
||||
;; Package-Requires: (posframe (emacs "26.1"))
|
||||
;;
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
|
@ -27,23 +27,23 @@
|
|||
(setq debug-on-error t)
|
||||
(require 'noether)
|
||||
|
||||
(defvar noether/-line 1)
|
||||
(defvar noether--line 1)
|
||||
|
||||
(defun noether/-update-line ()
|
||||
"Update the `noether/-line' variable after each command."
|
||||
(defun noether--update-line ()
|
||||
"Update the `noether--line' variable after each command."
|
||||
;; TODO: calling `line-number-at-pos' is not performant
|
||||
;; replace this with a better alt
|
||||
(setq noether/-line (line-number-at-pos)))
|
||||
(setq noether--line (line-number-at-pos)))
|
||||
|
||||
(defun noether/-line-format (_ v _ _)
|
||||
(defun noether--line-format (_ v _ _)
|
||||
(format "%04d" v))
|
||||
|
||||
(defvar noether/-time "")
|
||||
(defvar noether/-timer nil)
|
||||
(defun noether/-set-time ()
|
||||
(setq noether/-time (format-time-string "%H:%M:%S")))
|
||||
(defvar noether--time "")
|
||||
(defvar noether--timer nil)
|
||||
(defun noether--set-time ()
|
||||
(setq noether--time (format-time-string "%H:%M:%S")))
|
||||
|
||||
(defun noether/-time-format (_ v _ _)
|
||||
(defun noether--time-format (_ v _ _)
|
||||
"Just return the current time."
|
||||
v)
|
||||
|
||||
|
@ -52,25 +52,25 @@
|
|||
:label "L:"
|
||||
:len 4
|
||||
:init (lambda ()
|
||||
(add-hook 'post-command-hook #'noether/-update-line))
|
||||
(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)
|
||||
(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)))
|
||||
(setq noether--timer
|
||||
(run-with-timer 1 1 #'noether--set-time)))
|
||||
:deinit (lambda ()
|
||||
(when noether/-timer
|
||||
(cancel-timer noether/-timer)))
|
||||
(when noether--timer
|
||||
(cancel-timer noether--timer)))
|
||||
|
||||
:var 'noether/-time
|
||||
:fn #'noether/-time-format)
|
||||
:var 'noether--time
|
||||
:fn #'noether--time-format)
|
||||
|
||||
(defview example-bar
|
||||
"Just a test view"
|
||||
|
@ -84,9 +84,9 @@
|
|||
(time-unit :label "B:")))
|
||||
|
||||
|
||||
(setq noether/views (list example-bar))
|
||||
(setq noether-views (list example-bar))
|
||||
|
||||
(global-noethor-mode t)
|
||||
(noethor-global-mode t)
|
||||
|
||||
(provide 'noether.example)
|
||||
;;; noether.example.el ends here
|
||||
|
|
Loading…
Reference in New Issue