aboutsummaryrefslogtreecommitdiff
path: root/emacs/notmuch-address.el
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2021-01-10 15:00:46 +0100
committerDavid Bremner <david@tethera.net>2021-01-13 07:10:27 -0400
commit2ca941163da06aed564dab1990fb333fd7457ec2 (patch)
tree00ed761cee896d322e9ba501f12582b34a007316 /emacs/notmuch-address.el
parentadc123e4fd6384fba0165ebddc99d4323f6bee73 (diff)
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more semicolons as headings. That makes it very convenient to navigate code and to show/hide parts of a file. Elips libraries typically have four top-level sections, e.g.: ;;; notmuch.el --- run notmuch within emacs... ;;; Commentary:... ;;; Code:... ;;; notmuch.el ends here In this package many libraries lack a "Commentary:" section, which is not optimal but okay for most libraries, except major entry points. Depending on how one chooses to look at it, the "... ends here" line is not really a heading that begins a section, because it should never have a "section" body (after all it marks eof). If the file is rather short, then I left "Code:" as the only section that contains code. Otherwise I split the file into multiple sibling sections. The "Code:" section continues to contain `require' and `declare-function' forms and other such "front matter". If and only if I have split the code into multiple sections anyway, then I also added an additional section named just "_" before the `provide' form and shortly before the "...end here" line. This section could also be called "Back matter", but I feel it would be distracting to be that explicit about it. (The IMO unnecessary but unfortunately still obligatory "... ends here" line is already distracting enough as far as I am concerned.) Before this commit some libraries already uses section headings, some of them consistently. When a library already had some headings, then this commit often sticks to that style, even at the cost inconsistent styling across all libraries. A very limited number of variable and function definitions have to be moved around because they would otherwise end up in sections they do not belong into. Sections, including but not limited to their heading, can and should be further improved in the future.
Diffstat (limited to 'emacs/notmuch-address.el')
-rw-r--r--emacs/notmuch-address.el28
1 files changed, 19 insertions, 9 deletions
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 71985ed7..bf29c3a0 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -25,9 +25,11 @@
(require 'notmuch-parser)
(require 'notmuch-lib)
(require 'notmuch-company)
-;;
+
(declare-function company-manual-begin "company")
+;;; Cache internals
+
(defvar notmuch-address-last-harvest 0
"Time of last address harvest.")
@@ -47,6 +49,8 @@ If the hash is not present it attempts to load a saved hash."
(or notmuch-address-full-harvest-finished
(notmuch-address--load-address-hash)))
+;;; Options
+
(defcustom notmuch-address-command 'internal
"Determines how address completion candidates are generated.
@@ -133,6 +137,14 @@ matching `notmuch-address-completion-headers-regexp'."
:group 'notmuch-address
:group 'notmuch-hooks)
+(defcustom notmuch-address-use-company t
+ "If available, use company mode for address completion."
+ :type 'boolean
+ :group 'notmuch-send
+ :group 'notmuch-address)
+
+;;; Setup
+
(defun notmuch-address-selection-function (prompt collection initial-input)
"Call (`completing-read'
PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -147,12 +159,6 @@ matching `notmuch-address-completion-headers-regexp'."
(defun notmuch-address-message-insinuate ()
(message "calling notmuch-address-message-insinuate is no longer needed"))
-(defcustom notmuch-address-use-company t
- "If available, use company mode for address completion."
- :type 'boolean
- :group 'notmuch-send
- :group 'notmuch-address)
-
(defun notmuch-address-setup ()
(let* ((setup-company (and notmuch-address-use-company
(require 'company nil t)))
@@ -178,6 +184,8 @@ toggles the setting in this buffer."
(kill-local-variable 'company-idle-delay)
(setq-local company-idle-delay nil))))
+;;; Completion
+
(defun notmuch-address-matching (substring)
"Returns a list of completion candidates matching SUBSTRING.
The candidates are taken from `notmuch-address-completions'."
@@ -250,6 +258,8 @@ requiring external commands."
(ding))))
(t nil)))
+;;; Harvest
+
(defun notmuch-address-harvest-addr (result)
(let ((name-addr (plist-get result :name-addr)))
(puthash name-addr t notmuch-address-completions)))
@@ -406,7 +416,7 @@ appear to be an address savefile. Not overwriting."
(setq notmuch-address-full-harvest-finished t))
(setq notmuch-address-last-harvest 0)))))))
-;;
+;;; Standalone completion
(defun notmuch-address-from-minibuffer (prompt)
(if (not notmuch-address-command)
@@ -425,7 +435,7 @@ appear to be an address savefile. Not overwriting."
(let ((minibuffer-local-map rmap))
(read-string prompt)))))
-;;
+;;; _
(provide 'notmuch-address)