Compare commits

..

No commits in common. "022ac50b1e3d347cbe56ad8d46331ca0c55bcd94" and "1a24b9d5f616d747ca5af968398efd8710156463" have entirely different histories.

View File

@ -4,7 +4,7 @@
;; Author: mir <mirmarq428@gmail.com> ;; Author: mir <mirmarq428@gmail.com>
;; Keywords:frames,convenience,help ;; Keywords:frames,convenience,help
;; Package-Requires: ((posframe) (alert) (dash)) ;; Package-Requires: ((posframe) (alert))
;; This file is NOT part of GNU Emacs. ;; This file is NOT part of GNU Emacs.
@ -31,7 +31,6 @@
(require 'posframe) (require 'posframe)
(require 'alert) (require 'alert)
(require 'dash)
(if (not (fboundp #'string-pixel-width)) (if (not (fboundp #'string-pixel-width))
(progn (progn
(require 'shr) ;for `shr-string-pixel-width' (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* ( (let* (
;; need to not overlap the gtk scrollbar ;; need to not overlap the gtk scrollbar
(scrollbar-width (or (if (eq x-toolkit-scroll-bars 'gtk) (scrollbar-width (or (if (eq x-toolkit-scroll-bars 'gtk)
30) ; educated guess... 30) ; wild guess...
0)) 0))
;; (stackdepth (or stackdepth 0)) (stackdepth (or stackdepth 0))
(stackdepth 0) ; we do not care actually
(parent-width (frame-pixel-width)) (parent-width (frame-pixel-width))
(child-width (* notibox-width (string-pixel-width " "))) (child-width (* notibox-width (string-pixel-width " ")))
(parent-height (frame-pixel-height)) (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) ;; (notibox--get-position 3)
(defun notibox--prepare-buffer (title body &optional buffer) (defun notibox--prepare-buffer (title body &optional buffer)
"Return the notibox buffer containing TITLE and BODY, properly formatted" "Populate the `*notibox*' buffer (or BUFFER if specified) with TITLE and BODY properly formatted."
(let ((buf (get-buffer-create (format " *notibox-- %s: %s *" title body)))) (let ((buf (get-buffer-create (or buffer "*notibox*"))))
(with-current-buffer buf (with-current-buffer buf
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(erase-buffer) (erase-buffer)
@ -96,8 +94,7 @@ If STACKDEPTH is non-nil and nonzero, return a position that far down."
title title
(propertize (make-string notibox-width ?─) (propertize (make-string notibox-width ?─)
'face `((:foreground ,notibox-border-color))) 'face `((:foreground ,notibox-border-color)))
body)))) body))))))
buf))
;; (notibox--prepare-buffer "test" "this better work gadahgit" (or nil "*notibox-2*")) ;; (notibox--prepare-buffer "test" "this better work gadahgit" (or nil "*notibox-2*"))
;; (get-buffer-create "*notibox-2*") ;; (get-buffer-create "*notibox-2*")
;; wait, we need to be actually basing the things on the buffers huh ;; 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) (defvar notibox-current-posframes nil)
(cl-defun notibox--show (&key timeout &key depth &key buf) (cl-defun notibox--show (&key timeout &key depth &key buf)
"Show the notibox currently prepared, with optional TIMEOUT, at DEPTH, in 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*")))) (let ((buffer (get-buffer-create (or buf "*notibox*"))))
(posframe-show buffer (posframe-show buffer
:position (notibox--get-position depth) :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 :min-height notibox-height
:border-width 2 :border-width 2
:border-color notibox-border-color :border-color notibox-border-color
;; :timeout timeout :timeout timeout)))
))
))
(run-with-timer timeout nil #'notibox-delete this-notibox)
(mir/push-notibox this-notibox)
;; (add-to-list 'notibox-current-posframes
;; this-notibox)
)
nil) nil)
(defun notibox-alert (info) (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)) (title (plist-get info :title))
(timeout (plist-get info :persistent)) (timeout (plist-get info :persistent))
(depth (plist-get info :depth))) (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) (notibox--show :timeout (unless timeout alert-fade-time)
;; :depth (or depth (- (length notibox-current-posframes) 1)) :depth (or depth (- (length notibox-current-posframes) 1)))))
:buf (notibox--prepare-buffer title message))))
(defun notibox--resolve-frame (object) (defun notibox--resolve-frame (object)
"Return the /frame reference/ signified by OBJECT, whatever it may be." "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) (defun notibox--hide (frame)
"Stop showing FRAME." "Stop showing FRAME."
(if (frame-live-p 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) (defun notibox-delete (frame)
"Delete the notibox FRAME. "Delete the notibox FRAME.
@ -188,17 +177,14 @@ If the source is not obvious, use `current-buffer'."
(2 (progn (2 (progn
(setq source (car splooted)) (setq source (car splooted))
(setq contents (cadr 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) ;; (message "[debug] message: %s" msg)
(cons source contents))) (cons source contents)))
;; (split-string "evil-forward-character: End of line" ": ") ;; (split-string "evil-forward-character: End of line" ": ")
;; (length '("evil-forward-character" "end of line")) ;; (length '("evil-forward-character" "end of line"))
;; (split-string "this is a valid message" ": ") ;; (split-string "this is a valid message" ": ")
;; (message "evil-forward-char: End of line") ;; (notibox--parse-message "evil-forward-char: End of line")
;; (message "%s" 'this\:\ is\ a\ \"badly\:\ formed\ message\") ;; (notibox--parse-message "this is a badly formed message")
(defun buflast (buffer) (defun buflast (buffer)
"Return the last line of BUFFER as a string, without linebreaks." "Return the last line of BUFFER as a string, without linebreaks."
(with-current-buffer buffer (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))))) (buffer-substring-no-properties (point-at-bol) (point-max)))))
;; (buflast (get-buffer "*Messages*")) ;; (buflast (get-buffer "*Messages*"))
(defvar last-message nil
"Previous value of `current-message', stored for notibox.")
(defun notibox--tail-echoarea () (defun notibox--tail-echoarea ()
"Show `current-message' in the notibox. If that does not exist, probably hide it." "Show `current-message' in the notibox. If that does not exist, probably hide it."
(if (current-message) (if (current-message)
(unless (string= last-message (current-message))
(let* ((notibox-border-color "#0faa0f") ; hacky, can we set it elsewhere? (let* ((notibox-border-color "#0faa0f") ; hacky, can we set it elsewhere?
(parsed-msg (parsed-msg
(notibox--parse-message (notibox--parse-message
@ -223,11 +206,9 @@ If the source is not obvious, use `current-buffer'."
(contents (cdr parsed-msg))) (contents (cdr parsed-msg)))
(notibox-alert `( :title ,title (notibox-alert `( :title ,title
:message ,contents :message ,contents
))) :depth 0)))
(setq last-message (current-message))) (if notibox-current-posframes
;; (if notibox-current-posframes (notibox-delete (car notibox-current-posframes))))
;; (notibox-delete (car notibox-current-posframes)))
)
) )
(defun notibox/setup-timer () (defun notibox/setup-timer ()
@ -239,34 +220,23 @@ If the source is not obvious, use `current-buffer'."
(defun notibox-test-alert () (defun notibox-test-alert ()
"Show a sample notibox to prove we can." "Show a sample notibox to prove we can."
(interactive) (interactive)
(notibox-alert `(:title ,(random 8096) :message "test of notibox"))) (notibox-alert '(:title "five" :message "six")))
;; (notibox-test-alert) ;; (notibox-alert '(:title "一" :message "二" :timeout 5 :depth 0))
;; (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))
;; begin frame moving experiments. thought we already did this... ;; 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) (defun mir/move-frame (frame pos)
"Move FRAME to POS, a cons of (top . left)." "Move FRAME to POS, a cons of (top . left)."
(if (frame-live-p frame)
(modify-frame-parameters frame (modify-frame-parameters frame
`( `(
(top . ,(car pos)) (top . ,(car pos))
(left . ,(cdr pos)) (left . ,(cdr pos))
)))) )))
;; (frame-parameters test-frame)
;; (mir/move-frame test-frame '(300 . 1200))
(defvar mir/framove-update-interval 0.05 (defvar mir/framove-update-interval 0.05
"How many seconds to wait before updating incremental frame positions.") "How many seconds to wait before updating incremental frame positions.")
@ -311,35 +281,8 @@ intermediate positions are calculated via `mir/framove-update-interval'."
) )
nil nil
) )
;; (mir/framove-gradual test-frame '(500 . 1400) 1)
(defun mir/notibox-down-one (frame) ;; (mir/move-frame test-frame '(500 . 500))
"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)
)
(provide 'notibox) (provide 'notibox)
;;; notibox.el ends here ;;; notibox.el ends here