Compare commits
No commits in common. "022ac50b1e3d347cbe56ad8d46331ca0c55bcd94" and "1a24b9d5f616d747ca5af968398efd8710156463" have entirely different histories.
022ac50b1e
...
1a24b9d5f6
111
notibox.el
111
notibox.el
@ -4,7 +4,7 @@
|
||||
|
||||
;; Author: mir <mirmarq428@gmail.com>
|
||||
;; Keywords:frames,convenience,help
|
||||
;; Package-Requires: ((posframe) (alert) (dash))
|
||||
;; Package-Requires: ((posframe) (alert))
|
||||
|
||||
;; This file is NOT part of GNU Emacs.
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
|
||||
(require 'posframe)
|
||||
(require 'alert)
|
||||
(require 'dash)
|
||||
(if (not (fboundp #'string-pixel-width))
|
||||
(progn
|
||||
(require 'shr) ;for `shr-string-pixel-width'
|
||||
@ -59,10 +58,9 @@ If STACKDEPTH is non-nil and nonzero, return a position that far down."
|
||||
(let* (
|
||||
;; need to not overlap the gtk scrollbar
|
||||
(scrollbar-width (or (if (eq x-toolkit-scroll-bars 'gtk)
|
||||
30) ; educated guess...
|
||||
30) ; wild guess...
|
||||
0))
|
||||
;; (stackdepth (or stackdepth 0))
|
||||
(stackdepth 0) ; we do not care actually
|
||||
(stackdepth (or stackdepth 0))
|
||||
(parent-width (frame-pixel-width))
|
||||
(child-width (* notibox-width (string-pixel-width " ")))
|
||||
(parent-height (frame-pixel-height))
|
||||
@ -87,8 +85,8 @@ If STACKDEPTH is non-nil and nonzero, return a position that far down."
|
||||
;; (notibox--get-position 3)
|
||||
|
||||
(defun notibox--prepare-buffer (title body &optional buffer)
|
||||
"Return the notibox buffer containing TITLE and BODY, properly formatted"
|
||||
(let ((buf (get-buffer-create (format " *notibox-- %s: %s *" title body))))
|
||||
"Populate the `*notibox*' buffer (or BUFFER if specified) with TITLE and BODY properly formatted."
|
||||
(let ((buf (get-buffer-create (or buffer "*notibox*"))))
|
||||
(with-current-buffer buf
|
||||
(let ((inhibit-read-only t))
|
||||
(erase-buffer)
|
||||
@ -96,8 +94,7 @@ If STACKDEPTH is non-nil and nonzero, return a position that far down."
|
||||
title
|
||||
(propertize (make-string notibox-width ?─)
|
||||
'face `((:foreground ,notibox-border-color)))
|
||||
body))))
|
||||
buf))
|
||||
body))))))
|
||||
;; (notibox--prepare-buffer "test" "this better work gadahgit" (or nil "*notibox-2*"))
|
||||
;; (get-buffer-create "*notibox-2*")
|
||||
;; wait, we need to be actually basing the things on the buffers huh
|
||||
@ -105,7 +102,7 @@ If STACKDEPTH is non-nil and nonzero, return a position that far down."
|
||||
(defvar notibox-current-posframes nil)
|
||||
(cl-defun notibox--show (&key timeout &key depth &key buf)
|
||||
"Show the notibox currently prepared, with optional TIMEOUT, at DEPTH, in BUF."
|
||||
(let ((this-notibox
|
||||
(add-to-list 'notibox-current-posframes
|
||||
(let ((buffer (get-buffer-create (or buf "*notibox*"))))
|
||||
(posframe-show buffer
|
||||
:position (notibox--get-position depth)
|
||||
@ -117,14 +114,7 @@ If STACKDEPTH is non-nil and nonzero, return a position that far down."
|
||||
:min-height notibox-height
|
||||
:border-width 2
|
||||
:border-color notibox-border-color
|
||||
;; :timeout timeout
|
||||
))
|
||||
))
|
||||
(run-with-timer timeout nil #'notibox-delete this-notibox)
|
||||
(mir/push-notibox this-notibox)
|
||||
;; (add-to-list 'notibox-current-posframes
|
||||
;; this-notibox)
|
||||
)
|
||||
:timeout timeout)))
|
||||
nil)
|
||||
|
||||
(defun notibox-alert (info)
|
||||
@ -133,10 +123,9 @@ If STACKDEPTH is non-nil and nonzero, return a position that far down."
|
||||
(title (plist-get info :title))
|
||||
(timeout (plist-get info :persistent))
|
||||
(depth (plist-get info :depth)))
|
||||
;; gotta make it move the others down...
|
||||
(notibox--prepare-buffer title message)
|
||||
(notibox--show :timeout (unless timeout alert-fade-time)
|
||||
;; :depth (or depth (- (length notibox-current-posframes) 1))
|
||||
:buf (notibox--prepare-buffer title message))))
|
||||
:depth (or depth (- (length notibox-current-posframes) 1)))))
|
||||
|
||||
(defun notibox--resolve-frame (object)
|
||||
"Return the /frame reference/ signified by OBJECT, whatever it may be."
|
||||
@ -154,7 +143,7 @@ If STACKDEPTH is non-nil and nonzero, return a position that far down."
|
||||
(defun notibox--hide (frame)
|
||||
"Stop showing FRAME."
|
||||
(if (frame-live-p frame)
|
||||
(posframe-delete (window-buffer (frame-selected-window frame)))))
|
||||
(posframe-hide (window-buffer (frame-selected-window frame)))))
|
||||
|
||||
(defun notibox-delete (frame)
|
||||
"Delete the notibox FRAME.
|
||||
@ -188,17 +177,14 @@ If the source is not obvious, use `current-buffer'."
|
||||
(2 (progn
|
||||
(setq source (car splooted))
|
||||
(setq contents (cadr splooted))))
|
||||
(3 (progn
|
||||
(setq source (car splooted))
|
||||
(setq contents (format "%s: %s" (cadr splooted) (caddr splooted)))))
|
||||
)
|
||||
;; (message "[debug] message: %s" msg)
|
||||
(cons source contents)))
|
||||
;; (split-string "evil-forward-character: End of line" ": ")
|
||||
;; (length '("evil-forward-character" "end of line"))
|
||||
;; (split-string "this is a valid message" ": ")
|
||||
;; (message "evil-forward-char: End of line")
|
||||
;; (message "%s" 'this\:\ is\ a\ \"badly\:\ formed\ message\")
|
||||
;; (notibox--parse-message "evil-forward-char: End of line")
|
||||
;; (notibox--parse-message "this is a badly formed message")
|
||||
(defun buflast (buffer)
|
||||
"Return the last line of BUFFER as a string, without linebreaks."
|
||||
(with-current-buffer buffer
|
||||
@ -207,12 +193,9 @@ If the source is not obvious, use `current-buffer'."
|
||||
(buffer-substring-no-properties (point-at-bol) (point-max)))))
|
||||
;; (buflast (get-buffer "*Messages*"))
|
||||
|
||||
(defvar last-message nil
|
||||
"Previous value of `current-message', stored for notibox.")
|
||||
(defun notibox--tail-echoarea ()
|
||||
"Show `current-message' in the notibox. If that does not exist, probably hide it."
|
||||
(if (current-message)
|
||||
(unless (string= last-message (current-message))
|
||||
(let* ((notibox-border-color "#0faa0f") ; hacky, can we set it elsewhere?
|
||||
(parsed-msg
|
||||
(notibox--parse-message
|
||||
@ -223,11 +206,9 @@ If the source is not obvious, use `current-buffer'."
|
||||
(contents (cdr parsed-msg)))
|
||||
(notibox-alert `( :title ,title
|
||||
:message ,contents
|
||||
)))
|
||||
(setq last-message (current-message)))
|
||||
;; (if notibox-current-posframes
|
||||
;; (notibox-delete (car notibox-current-posframes)))
|
||||
)
|
||||
:depth 0)))
|
||||
(if notibox-current-posframes
|
||||
(notibox-delete (car notibox-current-posframes))))
|
||||
)
|
||||
|
||||
(defun notibox/setup-timer ()
|
||||
@ -239,34 +220,23 @@ If the source is not obvious, use `current-buffer'."
|
||||
(defun notibox-test-alert ()
|
||||
"Show a sample notibox to prove we can."
|
||||
(interactive)
|
||||
(notibox-alert `(:title ,(random 8096) :message "test of notibox")))
|
||||
;; (notibox-test-alert)
|
||||
;; (notibox-alert '(:title "一" :message "二" :timeout 5))
|
||||
;; (notibox-alert '(:title "三" :message "四" :timeout 5))
|
||||
;; wanna watch the variable. how do we do that
|
||||
(add-variable-watcher 'notibox-current-posframes
|
||||
(lambda (symbol newval operation where)
|
||||
"Display the variable in *watched* buffer."
|
||||
(with-current-buffer (get-buffer-create "*watched*")
|
||||
(goto-char (point-max))
|
||||
(insert
|
||||
(format "\n%s:\n was: %s\n now: %s"
|
||||
symbol
|
||||
(eval symbol)
|
||||
newval)))
|
||||
))
|
||||
(--map (remove-variable-watcher 'notibox-current-posframes it)
|
||||
(get-variable-watchers 'notibox-current-posframes))
|
||||
(notibox-alert '(:title "five" :message "six")))
|
||||
;; (notibox-alert '(:title "一" :message "二" :timeout 5 :depth 0))
|
||||
|
||||
;; begin frame moving experiments. thought we already did this...
|
||||
(setq test-frame (posframe-show "*Messages*"
|
||||
:position '(800 . 50)
|
||||
:width 30
|
||||
:height 16))
|
||||
(defun mir/move-frame (frame pos)
|
||||
"Move FRAME to POS, a cons of (top . left)."
|
||||
(if (frame-live-p frame)
|
||||
(modify-frame-parameters frame
|
||||
`(
|
||||
(top . ,(car pos))
|
||||
(left . ,(cdr pos))
|
||||
))))
|
||||
)))
|
||||
;; (frame-parameters test-frame)
|
||||
;; (mir/move-frame test-frame '(300 . 1200))
|
||||
(defvar mir/framove-update-interval 0.05
|
||||
"How many seconds to wait before updating incremental frame positions.")
|
||||
|
||||
@ -311,35 +281,8 @@ intermediate positions are calculated via `mir/framove-update-interval'."
|
||||
)
|
||||
nil
|
||||
)
|
||||
|
||||
(defun mir/notibox-down-one (frame)
|
||||
"Move FRAME down by `notibox-padding'."
|
||||
(if (frame-live-p frame)
|
||||
(let* ((parms (frame-parameters frame))
|
||||
(old-y (alist-get 'top parms))
|
||||
(old-x (alist-get 'left parms)))
|
||||
(mir/framove-gradual frame (cons
|
||||
(+ old-y ;; (- (* notibox-height
|
||||
;; (window-text-height))
|
||||
;; notibox-padding)
|
||||
(/
|
||||
(+ (* (window-text-height) notibox-height)
|
||||
notibox-padding)
|
||||
2))
|
||||
old-x
|
||||
) 0.125))))
|
||||
;; (notibox-test-alert)
|
||||
(defun notibox-test-message ()
|
||||
"Send a message and see if it gets picked up by notibox."
|
||||
(message "test message %s: %s is a number" (random 40) (random 500)))
|
||||
;; (notibox-test-message)
|
||||
|
||||
(defun mir/push-notibox (frame)
|
||||
"Push FRAME onto `notibox-current-posframes' and display it at the top of the stack."
|
||||
(--map (mir/notibox-down-one it) ; move each by the interval - need more infra first
|
||||
(reverse notibox-current-posframes))
|
||||
(push frame notibox-current-posframes)
|
||||
)
|
||||
;; (mir/framove-gradual test-frame '(500 . 1400) 1)
|
||||
;; (mir/move-frame test-frame '(500 . 500))
|
||||
|
||||
(provide 'notibox)
|
||||
;;; notibox.el ends here
|
||||
|
Loading…
Reference in New Issue
Block a user