From 7d0ff465220bec224c1f0c1163e6b4a88e1fb4c6 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 19 Aug 2022 13:39:13 -0500 Subject: bleh --- lisp/+modeline.el | 41 +++++++++++++++++++++-------------------- lisp/+notmuch.el | 35 +++++++++++++++++++++++++++++++++++ lisp/+tab-bar.el | 15 ++++++++++++++- 3 files changed, 70 insertions(+), 21 deletions(-) (limited to 'lisp') diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 11d6a4c..c6e8463 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el @@ -89,14 +89,15 @@ and appended with `truncate-string-ellipsis'." (defun +modeline-buffer-name (&optional spacer) ; gonsie "Display the buffer name." - (let ((bufname (string-trim (string-replace "%" "" (buffer-name))))) + (let ((bufname (string-trim (string-replace "%" "%%%%" (buffer-name))))) (+modeline-spacer nil spacer (if (and +modeline-buffer-position (fboundp +modeline-buffer-position)) (funcall +modeline-buffer-position) (propertize (cond ((ignore-errors - (and (> +modeline-buffer-name-max-length 0) - (< +modeline-buffer-name-max-length 1))) + (and + (> +modeline-buffer-name-max-length 0) + (< +modeline-buffer-name-max-length 1))) (truncate-string-to-width bufname (* (window-total-width) +modeline-buffer-name-max-length) @@ -149,14 +150,14 @@ in the cdr will be applied to the major-mode in the mode line." (propertize ;; (+string-truncate (format-mode-line mode-name) 16) (format-mode-line mode-name) 'face (when (actually-selected-window-p) - ;; XXX: This is probably really inefficient. I need to - ;; simply detect which mode it's in when I change major - ;; modes (`change-major-mode-hook') and change the face - ;; there, probably. - ;; (catch :done (dolist (cel +modeline-major-mode-faces) - ;; (when (derived-mode-p (car cel)) - ;; (throw :done (cdr cel)))) - ;; (alist-get t +modeline-major-mode-faces)) + ;; XXX: This is probably really inefficient. I need to + ;; simply detect which mode it's in when I change major + ;; modes (`change-major-mode-hook') and change the face + ;; there, probably. + ;; (catch :done (dolist (cel +modeline-major-mode-faces) + ;; (when (derived-mode-p (car cel)) + ;; (throw :done (cdr cel)))) + ;; (alist-get t +modeline-major-mode-faces)) '+modeline-major-mode-face) 'keymap (let ((map (make-sparse-keymap))) (bindings--define-key map [mode-line down-mouse-1] @@ -302,13 +303,13 @@ The order of elements matters: whichever one matches first is applied." (when file-percentage-mode (+modeline-spacer nil spacer (let ((perc (format-mode-line '(-2 "%p")))) - (pcase perc - ("To" "/\\") - ("Bo" "\\/") - ("Al" "[]") - (_ (let ((vec (vector "/|" "//" "||" "\\\\" "\\|" "\\|")) - (perc (string-to-number perc))) - (aref vec (floor (/ perc 17)))))))))) + (pcase perc + ("To" "/\\") + ("Bo" "\\/") + ("Al" "[]") + (_ (let ((vec (vector "/|" "//" "||" "\\\\" "\\|" "\\|")) + (perc (string-to-number perc))) + (aref vec (floor (/ perc 17)))))))))) (defun +modeline-file-percentage-icon (&optional spacer) "Display the position in the current file as an icon." @@ -379,8 +380,8 @@ to a function in the current buffer, call that function instead." "Display the version control branch of the current buffer in the modeline." ;; from https://www.gonsie.com/blorg/modeline.html, from Doom (when-let ((backend (vc-backend buffer-file-name))) - (+modeline-spacer nil spacer - (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) + (+modeline-spacer nil spacer + (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) (defun +modeline-track (&optional spacer) "Display `tracking-mode' information." diff --git a/lisp/+notmuch.el b/lisp/+notmuch.el index 890edbe..9e79c5a 100644 --- a/lisp/+notmuch.el +++ b/lisp/+notmuch.el @@ -58,5 +58,40 @@ for search." nil) 'notmuch-address-history))) +(defcustom +notmuch-spam-tags '("+spam" "+Spam") + "A list of tag changes to apply when marking a thread as spam." + :type '(repeat string)) + +(defun +notmuch-tree-mark-spam-then-next (&optional ham beg end) + "Mark the current message as spam and move to the next." + (interactive "P") + (+notmuch-tree-mark-spam ham) + (notmuch-tree-next-matching-message)) + +(defun +notmuch-tree-mark-spam (&optional ham) + "Mark the current message as spam. +That is, apply the tag changes in `+notmuch-spam-tags' to it. If +an optional prefix HAM argument is given, the message will be +marked as not-spam (\"ham\"), i.e., the tag changes in +`+notmuch-spam-tags' will be reversed." + (interactive "P") + (when +notmuch-spam-tags + (notmuch-tree-tag + (notmuch-tag-change-list +notmuch-spam-tags ham)))) + +(defun +notmuch-search-mark-spam (&optional ham beg end) + "Mark the current thread or region as spam. +This adds the tags in `+notmuch-spam-tags' to the message. With +an optional HAM prefix argument, mark the messages as +not-spam (\"ham\"). + +This function advances the next thread when finished." + (interactive (cons current-prefix-arg (notmuch-interactive-region))) + (when +notmuch-spam-tags + (notmuch-search-tag + (notmuch-tag-change-list +notmuch-spam-tags ham) beg end)) + (when (eq beg end) + (notmuch-search-next-thread))) + (provide '+notmuch) ;;; +notmuch.el ends here diff --git a/lisp/+tab-bar.el b/lisp/+tab-bar.el index 7ff991c..6c9debd 100644 --- a/lisp/+tab-bar.el +++ b/lisp/+tab-bar.el @@ -32,6 +32,19 @@ "Hide the `tracking-mode' information when clocked in." :type 'boolean) +(defun format-mode-line-unescaping (construct) + "Return a mode-line construct as a string, but unescape `%'s." + (format-mode-line + (cond ((listp construct) + (cl-loop for item in construct + collect (cond ((stringp item) + (string-replace "%" "%%" item)) + ((and (listp item) (eq :propertize (car item))) + (format-mode-line-unescaping item)) + (t item)))) + ((stringp construct) (string-replace "%" "%%" construct)) + (t construct)))) + (defun +tab-bar-tracking-mode () "Display `tracking-mode-line-buffers' in the tab-bar." ;; TODO: write something to convert a mode-line construct to a tab-bar @@ -45,7 +58,7 @@ as item = (nth i tracking-mode-line-buffers) collect (append (list (intern (format "tracking-mode-line-%s" i)) 'menu-item - (string-trim (format-mode-line item))) + (string-trim (format-mode-line-unescaping item))) (if-let ((keymap (plist-get item 'keymap))) (list (alist-get 'down-mouse-1 (cdadr keymap))) (list #'ignore)) -- cgit 1.4.1-21-gabe81