summaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
Diffstat (limited to 'emacs')
-rwxr-xr-xemacs/site-lisp/single-header.el94
1 files changed, 50 insertions, 44 deletions
diff --git a/emacs/site-lisp/single-header.el b/emacs/site-lisp/single-header.el
index 8e55e40..851d4d5 100755
--- a/emacs/site-lisp/single-header.el
+++ b/emacs/site-lisp/single-header.el
@@ -40,6 +40,7 @@
:type 'natnum
:group 'single-header)
(defvar single-header--active-notifs nil)
+(defvar single-header--timer nil)
(defmacro single-header--time-lock (force frame name &rest body)
""
@@ -96,7 +97,7 @@ arg, dismiss all the notifications."
(let ((notifs (ednc-notifications)))
(when notifs
(ednc-dismiss-notification (car notifs))))))
- (single-header-update))
+ (single-header-update t))
(defun single-header--make-header-info-string ()
"Generates the mode line string that contains all the info to the right."
@@ -161,27 +162,64 @@ arg, dismiss all the notifications."
(set-frame-parameter frame 'single-header-buf buf)
(set-frame-parameter frame 'single-header-win win))))
+(defun single-header-update (&optional force)
+ ""
+ (mapc (lambda (f) (single-header-update-frame f force))
+ (visible-frame-list)))
+
+(defun single-header-format (frame win buf)
+ "Evaluated in the header buffer when empty to fill the buffer."
+ (let* ((win-width (window-max-chars-per-line win 'single-header-face))
+ (info (single-header--make-header-info-string))
+ (info-width (string-width info))
+ (notifs (s-truncate (- win-width info-width 2)
+ (single-header--make-notif-string)))
+ (notifs-width (string-width notifs))
+ (filled (min win-width (+ info-width notifs-width)))
+ (padding-width (- win-width filled))
+ (padding (make-string padding-width ? )))
+ (setq notifs (single-header--with-face notifs 'single-header-face))
+ (setq padding (single-header--with-face padding 'single-header-face))
+ (setq info (single-header--with-face info 'single-header-face))
+ (concat notifs padding info)))
+
+(defun single-header-update-frame (frame &optional force)
+ ""
+ (with-selected-frame frame
+ (let ((buf (frame-parameter frame 'single-header-buf))
+ (win (frame-parameter frame 'single-header-win)))
+ (when (and buf win)
+ (with-current-buffer buf
+ (single-header--time-lock
+ force frame "header-lock"
+ (let ((str (single-header-format frame win buf)))
+ (erase-buffer)
+ (insert str))))))))
+
(defun single-header-make ()
"Create the header and show it."
(let ((registered
(or (equal 'single-header--register-notif-change
- ednc-notification-presentation-functions )
+ ednc-notification-presentation-functions)
(and (listp ednc-notification-presentation-functions)
(-contains? ednc-notification-presentation-functions
'single-header--register-notif-change)))))
(unless registered
- (if (listp ednc-notification-presentation-functions)
- (push 'single-header--register-notif-change
- ednc-notification-presentation-functions)
- (list 'single-header--register-notif-change
- ednc-notification-presentation-functions))))
+ (if (listp ednc-notification-presentation-functions)
+ (push 'single-header--register-notif-change
+ ednc-notification-presentation-functions)
+ (list 'single-header--register-notif-change
+ ednc-notification-presentation-functions))))
(mapc (lambda (f)
(when (frame-live-p f)
(single-header--init-frame f)))
(frame-list))
;; TODO frame creation hook
(add-hook 'after-make-frame-functions #'single-header--init-frame)
- (add-hook 'post-command-hook #'single-header-update))
+ (when single-header--timer
+ (cancel-timer single-header--timer))
+ (setq single-header--timer
+ (run-with-timer 0 single-header-update-increment 'single-header-update)))
(defun single-header-delete ()
"Remove an existing header buffer."
@@ -189,56 +227,24 @@ arg, dismiss all the notifications."
(-contains? ednc-notification-presentation-functions
'single-header--register-notif-change)))
(reg-equal (or (equal 'single-header--register-notif-change
- ednc-notification-presentation-functions))))
+ ednc-notification-presentation-functions))))
(when reg-list
(delete 'single-header--register-notif-change
ednc-notification-presentation-functions))
(when reg-equal
(setq ednc-notification-presentation-functions
'ednc--update-log-buffer)))
- (remove-hook 'post-command-hook 'single-header-update)
+ (cancel-timer single-header--timer)
+ (setq single-header--timer nil)
(remove-hook 'after-make-frame-functions 'single-header--init-frame)
- ;; TODO frame creation hook
(mapc (lambda (f)
(delete-window (frame-parameter f 'single-header-win))
(kill-buffer (frame-parameter f 'single-header-buf))
(set-frame-parameter f 'single-header-buf nil)
(set-frame-parameter f 'single-header-win nil))
- (frame-list)))
+ (frame-list)))
-(defun single-header-update (&optional force)
- ""
- (mapc (lambda (f) (single-header-update-frame f force))
- (visible-frame-list)))
-(defun single-header-format (frame win buf)
- "Evaluated in the header buffer when empty to fill the buffer."
- (let* ((win-width (window-max-chars-per-line win 'single-header-face))
- (info (single-header--make-header-info-string))
- (info-width (string-width info))
- (notifs (s-truncate (- win-width info-width 2)
- (single-header--make-notif-string)))
- (notifs-width (string-width notifs))
- (filled (min win-width (+ info-width notifs-width)))
- (padding-width (- win-width filled))
- (padding (make-string padding-width ? )))
- (setq notifs (single-header--with-face notifs 'single-header-face))
- (setq padding (single-header--with-face padding 'single-header-face))
- (setq info (single-header--with-face info 'single-header-face))
- (concat notifs padding info)))
-
-(defun single-header-update-frame (frame &optional force)
- ""
- (with-selected-frame frame
- (let ((buf (frame-parameter frame 'single-header-buf))
- (win (frame-parameter frame 'single-header-win)))
- (when (and buf win)
- (with-current-buffer buf
- (single-header--time-lock
- force frame "header-lock"
- (let ((str (single-header-format frame win buf)))
- (erase-buffer)
- (insert str))))))))
(define-minor-mode single-header-mode
"Global minor mode to enable a single info line at the top of each frame."