nftable-migration
1;;; consult-mu-contacts-embark.el --- Emabrk Actions for consult-mu-contacts -*- lexical-binding: t -*-
2
3;; Copyright (C) 2021-2023
4
5;; Author: Armin Darvish
6;; Maintainer: Armin Darvish
7;; Created: 2023
8;; Version: 1.0
9;; Package-Requires: ((emacs "28.0") (consult "2.0"))
10;; Homepage: https://github.com/armindarvish/consult-mu
11;; Keywords: convenience, matching, tools, email
12;; Homepage: https://github.com/armindarvish/consult-mu
13
14;; SPDX-License-Identifier: GPL-3.0-or-later
15
16;; This file is free software: you can redistribute it and/or modify
17;; it under the terms of the GNU General Public License as published
18;; by the Free Software Foundation, either version 3 of the License,
19;; or (at your option) any later version.
20;;
21;; This file is distributed in the hope that it will be useful,
22;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24;; GNU General Public License for more details.
25;;
26;; You should have received a copy of the GNU General Public License
27;; along with this file. If not, see <https://www.gnu.org/licenses/>.
28
29
30;;; Commentary:
31
32;; This package provides an alternative interactive serach interface for
33;; mu and mu4e (see URL `https://djcbsoftware.nl/code/mu/mu4e.html').
34;; It uses a consult-based minibuffer completion for searching and
35;; selecting, and marking emails, as well as additional utilities for
36;; composing emails and more.
37
38;; This package requires mu4e version "1.10.8" or later.
39
40
41;;; Code:
42
43;;; Requirements
44
45(require 'embark)
46(require 'consult-mu)
47(require 'consult-mu-embark)
48
49(defun consult-mu-contacts-embark-insert-email (cand)
50 "Embark function for inserting CAND's email."
51 (let* ((contact (get-text-property 0 :contact cand))
52 (email (plist-get contact :email)))
53 (insert (concat email "; "))))
54
55(defun consult-mu-contacts-embark-kill-email (cand)
56 "Embark function for copying CAND's email."
57 (let* ((contact (get-text-property 0 :contact cand))
58 (email (plist-get contact :email)))
59 (kill-new email)))
60
61(defun consult-mu-contacts-embark-get-alternative (cand)
62 "Embark function for copying CAND's email."
63 (let* ((contact (get-text-property 0 :contact cand))
64 (name (string-trim (plist-get contact :name)))
65 (email (plist-get contact :email))
66 (user (string-trim (replace-regexp-in-string "@.*" "" email))))
67 (consult-mu-contacts (cond
68 ((not (string-empty-p name))
69 name)
70 ((not (string-empty-p user))
71 user)
72 ((t ""))))))
73
74(defun consult-mu-contacts-embark-compose (cand)
75 "Embark function for composing an email to CAND."
76 (let* ((contact (get-text-property 0 :contact cand)))
77 (consult-mu-contacts--compose-to contact)))
78
79(defun consult-mu-contacts-embark-search-messages (cand)
80 "Embark function for searching messages from CAND using `consult-mu'."
81 (let* ((contact (get-text-property 0 :contact cand))
82 (email (plist-get contact :email)))
83 (consult-mu (concat "from:" email))))
84
85(defun consult-mu-contacts-embark-default-action (cand)
86 "Run `consult-mu-contacts-action' on CAND."
87 (let* ((contact (get-text-property 0 :contact cand))
88 (query (get-text-property 0 :query cand))
89 (newcand (cons cand `(:contact ,contact :query ,query))))
90 (funcall #'consult-mu-contacts--insert-email-action newcand)))
91
92;;; Define Embark Keymaps
93(defvar-keymap consult-mu-embark-contacts-actions-map
94 :doc "Keymap for consult-mu-embark-contacts"
95 :parent consult-mu-embark-general-actions-map
96 "c" #'consult-mu-contacts-embark-compose
97 "s" #'consult-mu-contacts-embark-search-messages
98 "i" #'consult-mu-contacts-embark-insert-email
99 "w" #'consult-mu-contacts-embark-kill-email
100 "a" #'consult-mu-contacts-embark-get-alternative)
101
102
103(add-to-list 'embark-keymap-alist '(consult-mu-contacts . consult-mu-embark-contacts-actions-map))
104
105;; change the default action on `consult-mu-contacts category.
106(add-to-list 'embark-default-action-overrides '(consult-mu-contacts . consult-mu-contacts-embark-default-action))
107
108;;; Provide `consult-mu-contacts-embark' module
109
110(provide 'consult-mu-contacts-embark)
111
112;;; consult-mu-contacts-embark.el ends here