Fix some of the low hanging linting errors

This commit is contained in:
Sameer Rahmani 2023-06-18 18:34:35 +01:00
parent 6182158fc6
commit f8fb71c307
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
2 changed files with 83 additions and 83 deletions

View File

@ -6,7 +6,7 @@
;; URL: https://devheroes.codes/lxsameer/noether ;; URL: https://devheroes.codes/lxsameer/noether
;; Version: 0.1.0 ;; Version: 0.1.0
;; Keywords: frames, modeline ;; 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 ;; 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 ;; it under the terms of the GNU General Public License as published by
@ -28,24 +28,24 @@
(require 'posframe) (require 'posframe)
(defvar noether/views () (defvar noether-views ()
"A list of views that noether should manage. "A list of views that noether should manage.
You should adding your views to this var, so noether can activate them You should adding your views to this var, so noether can activate them
on demand.") 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." "Return the value of the KEY in UNIT or the DEFAULT value if it doesn't exist."
`(or (plist-get ,unit ,key) ,default)) `(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." "Return the value of the KEY in VIEW or the DEFAULT value if it doesn't exist."
`(or (plist-get ,view ,key) ,default)) `(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. "Extract the props pairs from BODY-LIST with an optional accumulator ACC.
It will returen a pair in form of (body . props)." 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))) (rest (cdr body-list)))
(if (and k (keywordp k)) (if (and k (keywordp k))
(noether/-extract-props (noether--extract-props
(cdr rest) (cdr rest)
(cons (cdr rest) (plist-put (cdr acc) k (car rest)))) (cons (cdr rest) (plist-put (cdr acc) k (car rest))))
(cons body-list (cdr acc))))) (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." "Create a placeholder for UNIT based on its :label and :len."
(concat (concat
(noether/-unit-get unit :label "") (noether--unit-get unit :label "")
(make-string (noether/-unit-get unit :len 0) ? ))) (make-string (noether--unit-get unit :len 0) ? )))
(defmacro defview (name docs &rest body) (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 will be used as the view properties and the rest will be the body of
the show function." the show function."
(declare (doc-string 2)) (declare (doc-string 2))
(let* ((parsed-body (noether/-extract-props body)) (let* ((parsed-body (noether--extract-props body))
(show-body (car parsed-body)) (show-body (car parsed-body))
(props (cdr parsed-body)) (props (cdr parsed-body))
(initial-content (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) "")))) (or (plist-get props :separator) ""))))
`(progn `(progn
@ -101,7 +101,7 @@ parameter in form of key/values that will override any original
key/value from the original definition." key/value from the original definition."
(declare (doc-string 2)) (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 ;; For now we don't have any use for the body
(_ (car parsed-body)) (_ (car parsed-body))
(orig-props (cdr 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." "Draw the given VIEW on the screen."
;; View has to be processed at this stage ;; View has to be processed at this stage
(interactive) (interactive)
(let* ((show-fn (noether/-view-get view :show (lambda ()))) (let* ((show-fn (noether--view-get view :show (lambda ())))
(name (noether/-view-get view :name)) (name (noether--view-get view :name))
;; What if the user killed the buffer before? ;; 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 ;; TODO: Check to see whether the buffer is populated. If not, it means
;; that user killed the buffer manually. We need to repopulate it ;; that user killed the buffer manually. We need to repopulate it
;; again ;; again
(when (noether/-view-get view :managed?) (when (noether--view-get view :managed?)
(with-current-buffer buf (with-current-buffer buf
(funcall show-fn) (funcall show-fn)
;;(mapc #'funcall (get name :updaters)) ;;(mapc #'funcall (get name :updaters))
@ -132,22 +132,22 @@ key/value from the original definition."
(posframe-show (posframe-show
buf buf
:min-height (noether/-view-get view :height 1) :min-height (noether--view-get view :height 1)
:min-width (noether/-view-get view :width 10) :min-width (noether--view-get view :width 10)
:position '(0 . 0) ;;(cons (- (frame-outer-width) 10) (- (frame-outer-height) 10)) :position '(0 . 0) ;;(cons (- (frame-outer-width) 10) (- (frame-outer-height) 10))
;;:poshandler #'posframe-poshandler-frame-bottom-right-corner ;;:poshandler #'posframe-poshandler-frame-bottom-right-corner
:border-width (noether/-view-get view :border 0) :border-width (noether--view-get view :border 0)
:border-color (noether/-view-get view :border-color "#eeeefe") :border-color (noether--view-get view :border-color "#eeeefe")
:accewpt-focus (noether/-view-get view :accept-focus) :accewpt-focus (noether--view-get view :accept-focus)
:timeout (noether/-view-get view :timeout 5) :timeout (noether--view-get view :timeout 5)
:refresh (noether/-view-get view :refresh 0.5)))) :refresh (noether--view-get view :refresh 0.5))))
;; We need to keep this function as simple as possible ;; We need to keep this function as simple as possible
;; and avoid any performance pitfalls ;; 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. "Update the buffer BUF at START-POINT with length LEN by calling F.
It will pass WATCH-PARAMS to the unit's `:fn'" It will pass WATCH-PARAMS to the unit's `:fn'"
;; call f get the return value and put it in the dedicated cell ;; 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)))))) (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. "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." 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' ;; `add-watch-params' is a list of 4 elements that `add-variable-watcher'
;; passes to it's handler ;; passes to it's handler
(lambda (&rest add-watch-params) (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." "Setup the given UNIT in respect of VIEW using the POINT-STATE as the boundary."
(let* ((init-fn (noether/-unit-get unit :init)) (let* ((init-fn (noether--unit-get unit :init))
(f (noether/-unit-get unit :fn)) (f (noether--unit-get unit :fn))
(len (noether/-unit-get unit :len)) (len (noether--unit-get unit :len))
(label (noether/-unit-get unit :label "")) (label (noether--unit-get unit :label ""))
(buf (noether/-view-get view :buffer)) (buf (noether--view-get view :buffer))
(sep (noether/-view-get view :separator)) (sep (noether--view-get view :separator))
(var (noether/-unit-get unit :var)) (var (noether--unit-get unit :var))
(name (noether/-unit-get unit :name)) (name (noether--unit-get unit :name))
(view-name (noether/-view-get view :name)) (view-name (noether--view-get view :name))
(start-point (+ point-state (length label))) (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 ;; 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) (when (null name)
(error (format "No :name for unit %s" unit))) (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 ""))))) (+ end-point (length (or sep "")))))
(defun noether/-reset-view-state (view) (defun noether--reset-view-state (view)
"Reset the state stored in VIEW. "Reset the state stored in VIEW.
E.g. the updaters list." 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." "Setup the given VIEW by setting up its units."
(when (not (listp view)) (when (not (listp view))
(error (format "The given value as a view is not a list: %s" 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)) (let ((name (noether--view-get view :name))
(binding (noether/-view-get view :binding))) (binding (noether--view-get view :binding)))
(when (not (null binding)) (when (not (null binding))
(define-key global-noethor-mode-map 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) (erase-buffer)
(goto-char 0) (goto-char 0)
(insert (get name :initial-content)))) (insert (get name :initial-content))))
(seq-reduce (seq-reduce
(lambda (state u) (lambda (state u)
(noether/-setup-unit state view u)) (noether--setup-unit state view u))
(noether/-view-get view :units) (noether--view-get view :units)
0)) 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." "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))) (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." "Tear down the given VIEW to avoid any zombie watcher or timer n stuff."
(let ((name (noether/-view-get view :name))) (let ((name (noether--view-get view :name)))
(mapc #'noether/-teardown-unit (noether/-view-get view :units)) (mapc #'noether--teardown-unit (noether--view-get view :units))
(mapc #'funcall (get name :watcher-removers)) (mapc #'funcall (get name :watcher-removers))
(kill-buffer (kill-buffer
(noether/-view-get view :buffer (format "*%s*" name))) (noether--view-get view :buffer (format "*%s*" name)))
(funcall (noether/-view-get view :deinit (lambda ()))))) (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. "A minor mode that keep tracks of different status blocks.
It reports them back in a status bar like frame." It reports them back in a status bar like frame."
:global t :global t
:lighter " ST42" :lighter " ST42"
:keymap (make-sparse-keymap) :keymap (make-sparse-keymap)
(if global-noethor-mode (if global-noethor-mode
(mapc #'noether/-setup-views noether/views) (mapc #'noether--setup-views noether-views)
(mapc #'noether/-teardown-views noether/views))) (mapc #'noether--teardown-views noether-views)))
(provide 'noether) (provide 'noether)

View File

@ -6,7 +6,7 @@
;; URL: https://devheroes.codes/lxsameer/noether ;; URL: https://devheroes.codes/lxsameer/noether
;; Version: 0.1.0 ;; Version: 0.1.0
;; Keywords: frames, modeline ;; 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 ;; 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 ;; it under the terms of the GNU General Public License as published by
@ -27,23 +27,23 @@
(setq debug-on-error t) (setq debug-on-error t)
(require 'noether) (require 'noether)
(defvar noether/-line 1) (defvar noether--line 1)
(defun noether/-update-line () (defun noether--update-line ()
"Update the `noether/-line' variable after each command." "Update the `noether--line' variable after each command."
;; TODO: calling `line-number-at-pos' is not performant ;; TODO: calling `line-number-at-pos' is not performant
;; replace this with a better alt ;; 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)) (format "%04d" v))
(defvar noether/-time "") (defvar noether--time "")
(defvar noether/-timer nil) (defvar noether--timer nil)
(defun noether/-set-time () (defun noether--set-time ()
(setq noether/-time (format-time-string "%H:%M:%S"))) (setq noether--time (format-time-string "%H:%M:%S")))
(defun noether/-time-format (_ v _ _) (defun noether--time-format (_ v _ _)
"Just return the current time." "Just return the current time."
v) v)
@ -52,25 +52,25 @@
:label "L:" :label "L:"
:len 4 :len 4
:init (lambda () :init (lambda ()
(add-hook 'post-command-hook #'noether/-update-line)) (add-hook 'post-command-hook #'noether--update-line))
:deinit (lambda () :deinit (lambda ()
(remove-hook 'post-command-hook #'noether/-update-line)) (remove-hook 'post-command-hook #'noether--update-line))
:var 'noether/-line :var 'noether--line
:fn #'noether/-line-format) :fn #'noether--line-format)
(defunit time-unit (defunit time-unit
"just the time for your bar." "just the time for your bar."
:label "T:" :label "T:"
:len 8 :len 8
:init (lambda () :init (lambda ()
(setq noether/-timer (setq noether--timer
(run-with-timer 1 1 #'noether/-set-time))) (run-with-timer 1 1 #'noether--set-time)))
:deinit (lambda () :deinit (lambda ()
(when noether/-timer (when noether--timer
(cancel-timer noether/-timer))) (cancel-timer noether--timer)))
:var 'noether/-time :var 'noether--time
:fn #'noether/-time-format) :fn #'noether--time-format)
(defview example-bar (defview example-bar
"Just a test view" "Just a test view"
@ -84,9 +84,9 @@
(time-unit :label "B:"))) (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) (provide 'noether.example)
;;; noether.example.el ends here ;;; noether.example.el ends here