Browse Source

Cache the list of emails

This should make khardel-insert-email quite faster.
tags/v0.2.0
Damien Cassou 1 year ago
parent
commit
f94a8c4120
Signed by: Damien Cassou <damien@cassou.me> GPG Key ID: B68746238E59B548
1 changed files with 16 additions and 2 deletions
  1. +16
    -2
      khardel.el

+ 16
- 2
khardel.el View File

@@ -38,6 +38,9 @@
"Path to the khard executable file."
:type 'file)

(defvar khardel--emails nil
"Cache a list of strings of the form \"Name <email>\".")

(defun khardel--list-contacts ()
"Return a map whose keys are names and values are contacts."
(save-match-data
@@ -50,8 +53,8 @@
do (map-put contacts (match-string 2) (cons (match-string 1) (match-string 2)))
finally return contacts)))))

(defun khardel--list-emails ()
"Return a list of strings of the form \"Name <email>\"."
(defun khardel--fetch-emails ()
"Return a list of strings of the form \"Name <email>\" by asking `khardel-command'."
(save-match-data
(with-temp-buffer
(call-process khardel-command nil t nil "email" "--parsable" "--remove-first-line")
@@ -60,6 +63,17 @@
while (re-search-forward "^\\([^\t\n]*\\)\t\\([^\t\n]*\\)\t.*$" nil t)
collect (format "%s <%s>" (match-string 2) (match-string 1))))))

(defun khardel--list-emails ()
"Return a list of strings of the form \"Name <email>\"."
(if khardel--emails
khardel--emails
(setq khardel--emails (khardel--fetch-emails))))

(defun khardel-flush-caches ()
"Delete cached data to force a refresh."
(interactive)
(setq khardel--emails nil))

(defun khardel-choose-contact ()
"Let the user select a contact from a list of all contacts.
Return the contact."

Loading…
Cancel
Save