summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/net/jao-notmuch.el133
-rw-r--r--lib/wm/jao-exwm.el6
-rw-r--r--lib/wm/jao-x11.el28
3 files changed, 150 insertions, 17 deletions
diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el
index f7829e5..a319555 100644
--- a/lib/net/jao-notmuch.el
+++ b/lib/net/jao-notmuch.el
@@ -31,6 +31,139 @@
(require 'notmuch-show)
+;;; searches
+(defvar jao-notmuch--new nil)
+(defvar jao-notmuch--new-rx nil)
+(defvar jao-notmuch--newa nil)
+
+(defun jao-notmuch--tags-q (tags)
+ (format "tag:\"/^(%s)$/\"" (mapconcat (lambda (s) (format "%s" s)) tags "|")))
+
+(defun jao-notmuch--new (&rest tags)
+ (cond ((listp jao-notmuch--new)
+ (jao-notmuch--tags-q (append jao-notmuch--new tags)))
+ (tags (concat jao-notmuch--new " OR " (jao-notmuch--tags-q tags)))
+ (t jao-notmuch--new)))
+
+(defun jao-notmuch--set-new-search (s)
+ (setq jao-notmuch--new s
+ jao-notmuch--new-rx (regexp-quote (jao-notmuch--new))
+ jao-notmuch--newa (concat (jao-notmuch--new) " AND ")))
+
+(defun jao-notmuch--q (d0 &optional k d1 qs st)
+ (let* ((qs (when qs (mapconcat (lambda (q) (format "%s" q)) qs " AND ")))
+ (q (or qs
+ (concat (jao-notmuch--new)
+ (mapconcat (lambda (d) (when d (concat " AND tag:" d)))
+ (list d0 d1))))))
+ (list :name (concat d0 (when (and d1 (not (string= "" d1))) "/") d1)
+ :key k :query q :search-type (or st 'tree)
+ :sort-order 'oldest-first)))
+
+(defun jao-notmuch--q-feed (q)
+ (apply #'jao-notmuch--q (cons "feeds" q)))
+
+;;;###autoload
+(defun jao-notmuch-init-searches (s &optional other)
+ (jao-notmuch--set-new-search s)
+
+ (setq notmuch-hello-sections nil
+ notmuch-saved-searches nil
+ jao-notmuch-widened-searches nil)
+
+ (when other (jao-notmuch-def-searches (car other) (cdr other))))
+
+;;;###autoload
+(defun jao-notmuch-tree-widen-search ()
+ (interactive)
+ (when-let* ((query (notmuch-tree-get-query)))
+ (let ((notmuch-show-process-crypto (notmuch-tree--message-process-crypto)))
+ (notmuch-tree-close-message-window)
+ (notmuch-tree (string-replace jao-notmuch--newa "" query)))))
+
+(defun jao-notmuch--widen (s &optional extra)
+ (let* ((q (plist-get s :query))
+ (qs (string-replace jao-notmuch--newa "" q)))
+ (plist-put (copy-sequence s) :query (concat qs extra))))
+
+;;;###autoload
+(defun jao-notmuch-widen-searches (searches &optional extra)
+ (mapcar (lambda (s) (jao-notmuch--widen s extra)) searches))
+
+(defun jao-notmuch-hello--insert-searches (searches title title-face)
+ (when-let* ((searches (notmuch-hello-query-counts searches)))
+ (let* ((cnt (when title
+ (seq-reduce (lambda (c q)
+ (+ c (or (plist-get q :count) 0)))
+ searches
+ 0)))
+ (title (when title (format "%d %s" cnt title)))
+ (notmuch-column-control 1.0)
+ (title-face (or title-face 'jao-themes-f00)))
+ (when title
+ (widget-insert (propertize title 'face title-face))
+ (newline)
+ (jao-notmuch-hbar 5))
+ (notmuch-hello-insert-buttons searches)
+ (newline))))
+
+(defun jao-notmuch--replace (lst s)
+ (let ((name (plist-get s :name)))
+ (set lst (seq-remove (lambda (s0) (string= name (plist-get s0 :name)))
+ (symbol-value lst)))
+ (add-to-list lst s t)))
+
+;;;###autoload
+(defun jao-notmuch-def-searches (name searches &optional no-save title-face)
+ (declare (indent 1))
+ (unless no-save
+ (dolist (s searches)
+ (jao-notmuch--replace 'jao-notmuch-widened-searches
+ (jao-notmuch--widen s))
+ (jao-notmuch--replace 'notmuch-saved-searches s)))
+ (add-to-list 'notmuch-hello-sections
+ `(jao-notmuch-hello--insert-searches ,searches ,name ,title-face)
+ t))
+
+(defvar jao-notmuch-widened-searches nil)
+
+;;; jump to searches
+(defun jao-notmuch--searches-w/new (searches)
+ (seq-filter (lambda (s)
+ (string-match-p jao-notmuch--new-rx (plist-get s :query)))
+ (notmuch-hello-query-counts searches)))
+
+(defconst jao-notmuch--search-keys '("a" "s" "d" "f" "g" "h" "j" "k" "l"))
+
+(defun jao-notmuch--index-searches (searches)
+ (seq-map-indexed (lambda (q i)
+ (plist-put q :key (or (elt jao-notmuch--search-keys i)
+ (format "%s" i))))
+ searches))
+
+;;;###autoload
+(defun jao-notmuch-jump-search (&optional widen)
+ (interactive "P")
+ (let ((notmuch-saved-searches
+ (if widen jao-notmuch-widened-searches notmuch-saved-searches)))
+ (notmuch-jump-search)))
+
+;;;###autoload
+(defun jao-notmuch-jump ()
+ "Jump to a saved, non-zero count search."
+ (interactive)
+ (if-let* ((searches (jao-notmuch--searches-w/new notmuch-saved-searches)))
+ (if (= 2 (length searches))
+ (let* ((q (seq-remove (lambda (q) (string= "new" (plist-get q :name)))
+ searches))
+ (q (car q))
+ (of (eq 'oldest-first (plist-get q :sort-order)))
+ (query (plist-get q :query)))
+ (notmuch-tree query nil nil nil nil nil nil of t))
+ (let ((notmuch-saved-searches (jao-notmuch--index-searches searches)))
+ (notmuch-jump-search)))
+ (jao-notmuch-jump-search t)))
+
;;; targetting the displayed message from the tree view
(defvar-local jao-notmuch--tree-buffer nil)
diff --git a/lib/wm/jao-exwm.el b/lib/wm/jao-exwm.el
index 7027df4..27ddeb0 100644
--- a/lib/wm/jao-exwm.el
+++ b/lib/wm/jao-exwm.el
@@ -211,17 +211,17 @@
(switch-to-buffer b)
(exwm-input--fake-key ?y)
(exwm-input--fake-key ?y)
- (prog1 (current-kill 1)
+ (prog1 (message "%s" (current-kill 1))
(switch-to-buffer cb)))))
(defun jao-exwm-firefox-search (query)
(interactive "sQuery: ")
(jao-exwm-firefox)
- (sit-for 0.5)
+ (sit-for 0.2)
(exwm-input--fake-key ?s)
(dolist (k (string-to-list query))
(exwm-input--fake-key k))
- (sit-for 0.5)
+ (sit-for 0.2)
(exwm-input--fake-key ?\r))
(provide 'jao-exwm)
diff --git a/lib/wm/jao-x11.el b/lib/wm/jao-x11.el
index 16566d8..788bfe6 100644
--- a/lib/wm/jao-x11.el
+++ b/lib/wm/jao-x11.el
@@ -23,53 +23,53 @@
(jao-shell-def-exec jao-bright-set-up "brightnessctl" "-q" "s" "5%+")
(jao-shell-def-exec jao-bright-set-down "brightnessctl" "-q" "s" "5%-")
-(defun jao-brightness ()
+(defun jao-x11-brightness ()
(string-trim (or (cadr (jao-shell-cmd-lines "brightnessctl")) "(Unknown)")))
;;;###autoload
-(defun jao-bright-show ()
+(defun jao-x11-bright-show ()
(interactive)
- (message "%s" (jao-brightness)))
+ (message "%s" (jao-x11-brightness)))
;;;###autoload
-(defun jao-bright-up ()
+(defun jao-x11-bright-up ()
(interactive)
(jao-shell-exec "brightnessctl -q s 5%%+" t)
- (jao-bright-show))
+ (jao-x11-bright-show))
;;;###autoload
-(defun jao-bright-down ()
+(defun jao-x11-bright-down ()
(interactive)
(jao-shell-exec "brightnessctl -q s 5%%-" t)
- (jao-bright-show))
+ (jao-x11-bright-show))
;;; Keyboard
;;;###autoload
-(defun jao-kb-layout ()
+(defun jao-x11-kb-layout ()
(string-trim
(shell-command-to-string
"setxkbmap -query | grep 'layout:' | awk '{print $2}'")))
;;;###autoload
-(defun jao-kb-set (lyt &optional intl)
+(defun jao-x11-kb-set (lyt &optional intl)
(interactive "sLayout: ")
(let ((intl (if intl " -variant intl" "")))
(shell-command-to-string (format "setxkbmap %s%s" lyt intl))))
;;;###autoload
-(defun jao-kb-toggled-p ()
+(defun jao-x11-kb-toggled-p ()
(not (string-empty-p
(shell-command-to-string "setxkbmap -query|grep variant"))))
;;;###autoload
-(defun jao-kb-toggle ()
+(defun jao-x11-kb-toggle ()
(interactive)
- (jao-kb-set (jao-kb-layout) (not (jao-kb-toggled-p))))
+ (jao-x11-kb-set (jao-x11-kb-layout) (not (jao-x11-kb-toggled-p))))
;;;###autoload
-(defun jao-kb-disable-laptop ()
+(defun jao-x11-kb-disable-laptop ()
(interactive)
(jao-shell-exec "xinput float 13"))
-(provide 'jao-x11-kbd)
+(provide 'jao-x11)
;;; jao-x11.el ends here