diff options
author | jao <jao@gnu.org> | 2021-08-20 03:38:47 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2021-08-20 03:38:47 +0100 |
commit | 944e7eceb86b916ed24a85ea40dfc51b5d826e1d (patch) | |
tree | f2553e30bc4bcf7a322ed486966a50507234d67a | |
parent | 296f3a1156dcc3244b1c0df84adc4dcf021df7c0 (diff) | |
download | elibs-944e7eceb86b916ed24a85ea40dfc51b5d826e1d.tar.gz elibs-944e7eceb86b916ed24a85ea40dfc51b5d826e1d.tar.bz2 |
jao-notmuch-move (unused) spin-off
-rw-r--r-- | lib/net/jao-notmuch-move.el | 75 | ||||
-rw-r--r-- | lib/net/jao-notmuch.el | 47 | ||||
-rw-r--r-- | notmuch.org | 5 |
3 files changed, 77 insertions, 50 deletions
diff --git a/lib/net/jao-notmuch-move.el b/lib/net/jao-notmuch-move.el new file mode 100644 index 0000000..eb7ea4c --- /dev/null +++ b/lib/net/jao-notmuch-move.el @@ -0,0 +1,75 @@ +;;; jao-notmuch-move.el --- Move messages around in notmuch -*- lexical-binding: t; -*- + +;; Copyright (C) 2021 jao + +;; Author: jao <mail@jao.io> +;; Keywords: mail + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Moving messages around + +;;; Code: + +(require 'notmuch) + +(defvar jao-notmuch-mailboxes nil) +(defvar jao-notmuch-mailboxes-rx nil) + +(defun jao-notmuch--path-to-mailbox (full-path) + (unless jao-notmuch-mailboxes-rx + (setq jao-notmuch-mailboxes-rx (regexp-opt jao-notmuch-mailboxes))) + (if (string-match jao-notmuch-mailboxes-rx full-path) + (match-string 0 full-path) + (user-error "Message not in any registered mailbox!"))) + +(defun jao-notmuch--msg-props () + (if-let ((p (save-excursion + (beginning-of-line) + (text-property-search-forward :notmuch-message-properties)))) + (prop-match-value p) + (user-error "No message at point"))) + +(defun jao-notmuch--full-path () + (seq-find #'file-exists-p (plist-get (jao-notmuch--msg-props) :filename))) + +(defun jao-notmuch--move (&optional full-path d) + (let* ((full-path (or full-path (jao-notmuch--full-path))) + (ff (jao-notmuch--path-to-mailbox full-path)) + (d (or d (completing-read (format "From %s to: " ff) + (remove ff jao-notmuch-mailboxes) nil t))) + (dest (string-replace ff d full-path)) + (dest (replace-regexp-in-string ",U=.+$" "m:2,S" dest)) + (ftags (split-string ff "/")) + (ttags (split-string d "/"))) + (when (y-or-n-p (format "%s -> %s? " ftags ttags)) + (notmuch-tree-close-message-window) + (notmuch-tree-tag (append (notmuch-tag-change-list ftags t) + (notmuch-tag-change-list ttags))) + (rename-file (jao-notmuch--full-path) dest) + (shell-command-to-string "notmuch new") + (notmuch-refresh-this-buffer)))) + +(defun jao-notmuch-move-message () + "Move message at point to another folder." + (interactive) + (jao-notmuch--move)) + + + + +(provide 'jao-notmuch-move) +;;; jao-notmuch-move.el ends here diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index c7dc1fb..d3c7841 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -24,7 +24,6 @@ ;;; Code: -(require 'eww) (require 'outline) (require 'notmuch) @@ -32,54 +31,10 @@ (require 'notmuch-show) -;; Moving messages around - -(defvar jao-notmuch-mailboxes nil) -(defvar jao-notmuch-mailboxes-rx nil) - -(defun jao-notmuch--path-to-mailbox (full-path) - (unless jao-notmuch-mailboxes-rx - (setq jao-notmuch-mailboxes-rx (regexp-opt jao-notmuch-mailboxes))) - (if (string-match jao-notmuch-mailboxes-rx full-path) - (match-string 0 full-path) - (user-error "Message not in any registered mailbox!"))) - -(defun jao-notmuch--msg-props () - (if-let ((p (save-excursion - (beginning-of-line) - (text-property-search-forward :notmuch-message-properties)))) - (prop-match-value p) - (user-error "No message at point"))) - -(defun jao-notmuch--full-path () - (seq-find #'file-exists-p (plist-get (jao-notmuch--msg-props) :filename))) - -(defun jao-notmuch--move (&optional full-path d) - (let* ((full-path (or full-path (jao-notmuch--full-path))) - (ff (jao-notmuch--path-to-mailbox full-path)) - (d (or d (completing-read (format "From %s to: " ff) - (remove ff jao-notmuch-mailboxes) nil t))) - (dest (string-replace ff d full-path)) - (dest (replace-regexp-in-string ",U=.+$" "m:2,S" dest)) - (ftags (split-string ff "/")) - (ttags (split-string d "/"))) - (when (y-or-n-p (format "%s -> %s? " ftags ttags)) - (notmuch-tree-close-message-window) - (notmuch-tree-tag (append (notmuch-tag-change-list ftags t) - (notmuch-tag-change-list ttags))) - (rename-file (jao-notmuch--full-path) dest) - (shell-command-to-string "notmuch new") - (notmuch-refresh-this-buffer)))) - -(defun jao-notmuch-move-message () - "Move message at point to another folder." - (interactive) - (jao-notmuch--move)) - - ;; Targetting the displayed message from the tree view (defvar-local jao-notmuch--tree-buffer nil) +(declare eww--url-at-point "eww") (defun jao-notmuch-goto-message-buffer (&optional and-click no-record) (interactive "P") diff --git a/notmuch.org b/notmuch.org index 830721a..cb20bc1 100644 --- a/notmuch.org +++ b/notmuch.org @@ -174,9 +174,7 @@ :map message-mode-map (("C-c C-d" . notmuch-draft-postpone)))) - (use-package jao-notmuch - :demand t - :config (setq jao-notmuch-mailboxes (jao-mailbox-folders))) + (use-package jao-notmuch :demand t) #+end_src * hello @@ -330,7 +328,6 @@ ("i" . jao-notmuch-show-images) ("K" . jao-notmuch-tag-jump-and-next) ("k" . jao-notmuch-tree-read-thread) - ("M" . jao-notmuch-move-message) ("n" . jao-notmuch-tree-next) ("O" . notmuch-tree-toggle-order) ("o" . jao-notmuch-tree-widen-search) |