aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2018-01-16 14:53:11 +0100
committerLars Ingebrigtsen2018-01-17 11:55:58 +0100
commit064395251f99eb85161ca7c8e36665e2bd0453f5 (patch)
tree7f0b7357daea5789896720dac874000a4af76a41
parent7efb366b20715682efe72dd35fb05a6338a0ddc1 (diff)
downloademacs-064395251f99eb85161ca7c8e36665e2bd0453f5.tar.gz
emacs-064395251f99eb85161ca7c8e36665e2bd0453f5.zip
Add documentation to ecomplete.el
* lisp/ecomplete.el: Add doc strings and document the format.
-rw-r--r--lisp/ecomplete.el36
1 files changed, 36 insertions, 0 deletions
diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el
index 87052e34e8b..43ab8e691e6 100644
--- a/lisp/ecomplete.el
+++ b/lisp/ecomplete.el
@@ -22,6 +22,35 @@
22 22
23;;; Commentary: 23;;; Commentary:
24 24
25;; ecomplete stores matches in a file that looks like this:
26;;
27;; ((mail
28;; ("larsi@gnus.org" 38154 1516109510 "Lars Ingebrigtsen <larsi@gnus.org>")
29;; ("kfogel@red-bean.com" 10 1516065455 "Karl Fogel <kfogel@red-bean.com>")
30;; ...
31;; ))
32;;
33;; That is, it's an alist map where the key is the "type" of match (so
34;; that you can have one list of things for `mail' and one for, say,
35;; `twitter'). In each of these sections you then have a list where
36;; each item is on the form
37;;
38;; (KEY TIMES-USED LAST-TIME-USED STRING)
39;;
40;; If you call `ecomplete-display-matches', it will then display all
41;; items that match STRING. KEY is unique and is used to identify the
42;; item, and is used for updates. For instance, if given the above
43;; data, you call
44;;
45;; (ecomplete-add-item "larsi@gnus.org" 'mail "Lars Magne Ingebrigtsen <larsi@gnus.org>")
46;;
47;; the "larsi@gnus.org" entry will then be updated with that new STRING.
48
49;; The interface functions are `ecomplete-add-item' and
50;; `ecomplete-display-matches', while `ecomplete-setup' should be
51;; called to read the .ecompleterc file, and `ecomplete-save' are
52;; called to save the file.
53
25;;; Code: 54;;; Code:
26 55
27(eval-when-compile 56(eval-when-compile
@@ -47,6 +76,7 @@
47 76
48;;;###autoload 77;;;###autoload
49(defun ecomplete-setup () 78(defun ecomplete-setup ()
79 "Read the .ecompleterc file."
50 (when (file-exists-p ecomplete-database-file) 80 (when (file-exists-p ecomplete-database-file)
51 (with-temp-buffer 81 (with-temp-buffer
52 (let ((coding-system-for-read ecomplete-database-file-coding-system)) 82 (let ((coding-system-for-read ecomplete-database-file-coding-system))
@@ -54,6 +84,7 @@
54 (setq ecomplete-database (read (current-buffer))))))) 84 (setq ecomplete-database (read (current-buffer)))))))
55 85
56(defun ecomplete-add-item (type key text) 86(defun ecomplete-add-item (type key text)
87 "Add item TEXT of TYPE to the database, using KEY as the identifier."
57 (let ((elems (assq type ecomplete-database)) 88 (let ((elems (assq type ecomplete-database))
58 (now (string-to-number (format-time-string "%s"))) 89 (now (string-to-number (format-time-string "%s")))
59 entry) 90 entry)
@@ -64,9 +95,11 @@
64 (nconc elems (list (list key 1 now text)))))) 95 (nconc elems (list (list key 1 now text))))))
65 96
66(defun ecomplete-get-item (type key) 97(defun ecomplete-get-item (type key)
98 "Return the text for the item identified by KEY of the required TYPE."
67 (assoc key (cdr (assq type ecomplete-database)))) 99 (assoc key (cdr (assq type ecomplete-database))))
68 100
69(defun ecomplete-save () 101(defun ecomplete-save ()
102 "Write the .ecompleterc file."
70 (with-temp-buffer 103 (with-temp-buffer
71 (let ((coding-system-for-write ecomplete-database-file-coding-system)) 104 (let ((coding-system-for-write ecomplete-database-file-coding-system))
72 (insert "(") 105 (insert "(")
@@ -105,6 +138,9 @@
105 (buffer-string))))) 138 (buffer-string)))))
106 139
107(defun ecomplete-display-matches (type word &optional choose) 140(defun ecomplete-display-matches (type word &optional choose)
141 "Display the top-rated elements TYPE that match WORD.
142If CHOOSE, allow the user to choose interactively between the
143matches."
108 (let* ((matches (ecomplete-get-matches type word)) 144 (let* ((matches (ecomplete-get-matches type word))
109 (line 0) 145 (line 0)
110 (max-lines (when matches (- (length (split-string matches "\n")) 2))) 146 (max-lines (when matches (- (length (split-string matches "\n")) 2)))