mu4e-(actions|control|org|update).el: tidy up

Fix flycheck warnings, and use '--' instead of '~' for private
variables/functions.
This commit is contained in:
Dirk-Jan C. Binnema 2021-08-30 22:02:49 +03:00
parent 162f5896ae
commit 3a39eff1df
5 changed files with 56 additions and 49 deletions

View File

@ -43,7 +43,8 @@
Works for headers view and message-view."
(message "Number of lines: %s"
(shell-command-to-string
(concat "wc -l < " (shell-quote-argument (mu4e-message-field msg :path))))))
(concat "wc -l < "
(shell-quote-argument (mu4e-message-field msg :path))))))
;;; Org Helpers
@ -102,22 +103,22 @@ file where you store your org-contacts."
;;; Patches
(defvar mu4e~patch-directory-history nil
(defvar mu4e--patch-directory-history nil
"History of directories we have applied patches to.")
;; This essentially works around the fact that read-directory-name
;; can't have custom history.
(defun mu4e~read-patch-directory (&optional prompt)
(defun mu4e--read-patch-directory (&optional prompt)
"Read a `PROMPT'ed directory name via `completing-read' with history."
(unless prompt
(setq prompt "Target directory:"))
(file-truename
(completing-read prompt 'read-file-name-internal #'file-directory-p
nil nil 'mu4e~patch-directory-history)))
nil nil 'mu4e--patch-directory-history)))
(defun mu4e-action-git-apply-patch (msg)
"Apply `MSG' as a git patch."
(let ((path (mu4e~read-patch-directory "Target directory: ")))
(let ((path (mu4e--read-patch-directory "Target directory: ")))
(let ((default-directory path))
(shell-command
(format "git apply %s"
@ -130,10 +131,10 @@ If the `default-directory' matches the most recent history entry don't
bother asking for the git tree again (useful for bulk actions)."
(let ((cwd (substring-no-properties
(or (car mu4e~patch-directory-history)
(or (car mu4e--patch-directory-history)
"not-a-dir"))))
(unless (and (stringp cwd) (string= default-directory cwd))
(setq cwd (mu4e~read-patch-directory "Target directory: ")))
(setq cwd (mu4e--read-patch-directory "Target directory: ")))
(let ((default-directory cwd))
(shell-command
(format "git am %s %s"
@ -152,7 +153,7 @@ messages can lead to messages with multiple tags headers.")
(defvar mu4e-action-tags-completion-list '()
"List of tags for completion in `mu4e-action-retag-message'.")
(defun mu4e~contains-line-matching (regexp path)
(defun mu4e--contains-line-matching (regexp path)
"Return non-nil if the file at PATH contain a line matching REGEXP.
Otherwise return nil."
(with-temp-buffer
@ -161,7 +162,7 @@ Otherwise return nil."
(goto-char (point-min))
(re-search-forward regexp nil t))))
(defun mu4e~replace-first-line-matching (regexp to-string path)
(defun mu4e--replace-first-line-matching (regexp to-string path)
"Replace first line matching REGEXP in PATH with TO-STRING."
(with-temp-file path
(insert-file-contents path)
@ -220,13 +221,13 @@ would add 'tag' and 'long tag', and remove 'oldtag'."
(setq tagstr (replace-regexp-in-string "[\\&]" "\\\\\\&" tagstr))
(setq tagstr (replace-regexp-in-string "[/]" "\\&" tagstr))
(if (not (mu4e~contains-line-matching (concat header ":.*") path))
(if (not (mu4e--contains-line-matching (concat header ":.*") path))
;; Add tags header just before the content
(mu4e~replace-first-line-matching
(mu4e--replace-first-line-matching
"^$" (concat header ": " tagstr "\n") path)
;; replaces keywords, restricted to the header
(mu4e~replace-first-line-matching
(mu4e--replace-first-line-matching
(concat header ":.*")
(concat header ": " tagstr)
path))

View File

@ -70,7 +70,6 @@
(require 'message)
(require 'mail-parse)
(require 'smtpmail)
(require 'rfc2368)
(require 'mu4e-server)
(require 'mu4e-actions)
@ -337,7 +336,7 @@ buffers; lets remap its faces so it uses the ones for mu4e."
(define-key mu4e-context-minor-mode-map (kbd ";") nil)
(define-key mu4e-context-minor-mode-map (kbd "C-c C-;")
#'mu4e-compose-context-switch)
(set (make-local-variable 'message-signature) mu4e-compose-signature)
;; set this to allow mu4e to work when gnus-agent is unplugged in gnus
(set (make-local-variable 'message-send-mail-real-function) nil)

View File

@ -1,4 +1,4 @@
;;; mu4e-contrib.el -- part of mu4e, the mu mail user agent -*- lexical-binding: t -*-
;;; mu4e-contrib.el -- part of mu4e -*- lexical-binding: t -*-
;; Copyright (C) 2013-2021 Dirk-Jan C. Binnema
@ -48,7 +48,8 @@
(mu4e-mark-execute-all t))
(defun mu4e-headers-mark-all ()
"Mark all messages within current query results and ask user to execute which action."
"Mark all headers for some action,
Ask user what action to execute."
(interactive)
(mu4e-headers-mark-for-each-if
(cons 'something nil)
@ -59,22 +60,25 @@
;;
;; Allow bookmarking a mu4e buffer in regular emacs bookmarks.
(defun mu4e~view-set-bookmark-make-record-fn ()
(defun mu4e--view-set-bookmark-make-record-fn ()
"Make a bookmar record function (view)."
(set (make-local-variable 'bookmark-make-record-function)
'mu4e-view-bookmark-make-record))
(defun mu4e~headers-set-bookmark-make-record-fn ()
(defun mu4e--headers-set-bookmark-make-record-fn ()
"Make a bookmar record function (headers)."
(set (make-local-variable 'bookmark-make-record-function)
'mu4e-view-bookmark-make-record))
;; Probably this can be moved to mu4e-view.el.
(add-hook 'mu4e-view-mode-hook #'mu4e~view-set-bookmark-make-record-fn)
(add-hook 'mu4e-view-mode-hook #'mu4e--view-set-bookmark-make-record-fn)
;; And this can be moved to mu4e-headers.el.
(add-hook 'mu4e-headers-mode-hook #'mu4e~headers-set-bookmark-make-record-fn)
(add-hook 'mu4e-headers-mode-hook #'mu4e--headers-set-bookmark-make-record-fn)
(defun mu4e-view-bookmark-make-record ()
"Make a bookmark entry for a mu4e buffer. Note that this is an
emacs bookmark, not to be confused with `mu4e-bookmarks'."
"Make a bookmark entry for a mu4e buffer.
Note that this is an Emacs bookmark, not to be confused with
`mu4e-bookmarks'."
(let* ((msg (mu4e-message-at-point))
(maildir (plist-get msg :maildir))
(date (format-time-string "%Y%m%d" (plist-get msg :date)))
@ -122,26 +126,26 @@ BOOKMARK is a bookmark name or a bookmark record."
;; '("hMark as ham" . mu4e-register-msg-as-ham) t)
(defvar mu4e-register-as-spam-cmd nil
"Command for invoking spam processor to register message as spam,
for example for bogofilter, use \"/usr/bin/bogofilter -Ns < %s\" ")
"Command for invoking spam processor to register message as spam.
For example for bogofilter, use \"/usr/bin/bogofilter -Ns < %s\"")
(defvar mu4e-register-as-ham-cmd nil
"Command for invoking spam processor to register message as ham.
For example for bogofile, use \"/usr/bin/bogofilter -Sn < %s\"")
(defun mu4e-register-msg-as-spam (msg)
"Mark message as spam."
"Register MSG as spam."
(interactive)
(let* ((path (shell-quote-argument (mu4e-message-field msg :path)))
(command (format mu4e-register-as-spam-cmd path))) ;; re-register msg as spam
(command (format mu4e-register-as-spam-cmd path)))
(shell-command command))
(mu4e-mark-at-point 'delete nil))
(defun mu4e-register-msg-as-ham (msg)
"Mark message as ham."
"Register MSG as ham."
(interactive)
(let* ((path (shell-quote-argument(mu4e-message-field msg :path)))
(command (format mu4e-register-as-ham-cmd path))) ;; re-register msg as ham
(command (format mu4e-register-as-ham-cmd path)))
(shell-command command))
(mu4e-mark-at-point 'something nil))
@ -151,7 +155,7 @@ For example for bogofile, use \"/usr/bin/bogofilter -Sn < %s\"")
;; '("hMark as ham" . mu4e-view-register-msg-as-ham) t)
(defun mu4e-view-register-msg-as-spam (msg)
"Mark message as spam (view mode)."
"Register MSG as spam (view mode)."
(interactive)
(let* ((path (shell-quote-argument (mu4e-message-field msg :path)))
(command (format mu4e-register-as-spam-cmd path)))
@ -159,7 +163,7 @@ For example for bogofile, use \"/usr/bin/bogofilter -Sn < %s\"")
(mu4e-view-mark-for-delete))
(defun mu4e-view-register-msg-as-ham (msg)
"Mark message as ham (view mode)."
"Mark MSG as ham (view mode)."
(interactive)
(let* ((path (shell-quote-argument(mu4e-message-field msg :path)))
(command (format mu4e-register-as-ham-cmd path)))
@ -173,8 +177,8 @@ For example for bogofile, use \"/usr/bin/bogofilter -Sn < %s\"")
;; eshell. Does not depend on gnus.
(defun mu4e~active-composition-buffers ()
"Return all active mu4e composition buffers"
(defun mu4e--active-composition-buffers ()
"Return all active mu4e composition buffers."
(let (buffers)
(save-excursion
(dolist (buffer (buffer-list t))
@ -184,15 +188,17 @@ For example for bogofile, use \"/usr/bin/bogofilter -Sn < %s\"")
(nreverse buffers)))
(defun eshell/mu4e-attach (&rest args)
"Attach files to a mu4e message using eshell. If no mu4e
buffers found, compose a new message and then attach the file."
"Attach files to a mu4e message using eshell with ARGS.
If no mu4e buffers found, compose a new message and then attach
the file."
(let ((destination nil)
(files-str nil)
(bufs nil)
;; Remove directories from the list
(files-to-attach
(delq nil (mapcar
(lambda (f) (if (or (not (file-exists-p f)) (file-directory-p f))
(lambda (f) (if (or (not (file-exists-p f))
(file-directory-p f))
nil
(expand-file-name f)))
(eshell-flatten-list (reverse args))))))
@ -203,7 +209,7 @@ buffers found, compose a new message and then attach the file."
(mapconcat
(lambda (f) (file-name-nondirectory f))
files-to-attach ", "))
(setq bufs (mu4e~active-composition-buffers))
(setq bufs (mu4e--active-composition-buffers))
;; set up destination mail composition buffer
(if (and bufs
(y-or-n-p "Attach files to existing mail composition buffer? "))
@ -224,7 +230,8 @@ buffers found, compose a new message and then attach the file."
(goto-char (point-max)) ; attach at end of buffer
(while files-to-attach
(mml-attach-file (car files-to-attach)
(or (mm-default-file-encoding (car files-to-attach))
(or (mm-default-file-encoding
(car files-to-attach))
"application/octet-stream") nil)
(setq files-to-attach (cdr files-to-attach)))
(message "Attached file(s) %s" files-str))

View File

@ -32,7 +32,7 @@
(defgroup mu4e-org nil
"Settings for the org-mode related functionality in mu4e."
"Settings for the Org mode related functionality in mu4e."
:group 'mu4e
:group 'org)
@ -60,7 +60,7 @@ Example usage:
If non-nil, `org-store-link' in `mu4e-headers-mode' links to the
the current query; otherwise, it links to the message at point.")
(defun mu4e~org-store-link-query ()
(defun mu4e--org-store-link-query ()
"Store a link to a mu4e query."
(setq org-store-link-plist nil) ; reset
(org-store-link-props
@ -70,14 +70,14 @@ the current query; otherwise, it links to the message at point.")
:link (concat "mu4e:query:" (mu4e-last-query))
:description (format "[%s]" (mu4e-last-query))))
(defun mu4e~org-address (cell)
"Get address field FIELD from MSG as a string or nil."
(defun mu4e--org-address (cell)
"Get an address from CELL."
(let ((name (car cell)) (addr (cdr cell)))
(if name
(format "%s <%s>" name addr)
(format "%s" addr))))
(defun mu4e~org-store-link-message ()
(defun mu4e--org-store-link-message ()
"Store a link to a mu4e message."
(setq org-store-link-plist nil)
(let* ((msg (mu4e-message-at-point))
@ -90,13 +90,13 @@ the current query; otherwise, it links to the message at point.")
:type "mu4e"
:date date
:from (when from
(mu4e~org-address from))
(mu4e--org-address from))
:maildir (plist-get msg :maildir)
:message-id msgid
:path (plist-get msg :path)
:subject (plist-get msg :subject)
:to (when to
(mu4e~org-address to))
(mu4e--org-address to))
:link (concat "mu4e:msgid:" msgid)
:description (funcall mu4e-org-link-desc-func msg))))
@ -109,9 +109,9 @@ valid even after moving the message around."
(when (derived-mode-p 'mu4e-view-mode 'mu4e-headers-mode)
(if (and (derived-mode-p 'mu4e-headers-mode)
mu4e-org-link-query-in-headers-mode)
(mu4e~org-store-link-query)
(mu4e--org-store-link-query)
(when (mu4e-message-at-point)
(mu4e~org-store-link-message)))))
(mu4e--org-store-link-message)))))
;
(defun mu4e-org-open (link)
"Open the org LINK.

View File

@ -1,6 +1,6 @@
;;; mu4e-update.el -- part of mu4e, -*- lexical-binding: t -*-
;; Copyright (C) 2011-2020 Dirk-Jan C. Binnema
;; Copyright (C) 2011-2021 Dirk-Jan C. Binnema
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
@ -22,8 +22,8 @@
;;; Commentary:
;; Updating the mu4e message: calling a mail retrieval program
;; and re-running the index.
;; Updating the mu4e message store: calling a mail retrieval program and
;; re-running the index.
;;; Code: