emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ebdb 9e7a96f: Add experimental ebdb-completion-at-point


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 9e7a96f: Add experimental ebdb-completion-at-point-function
Date: Fri, 23 Mar 2018 00:48:22 -0400 (EDT)

branch: externals/ebdb
commit 9e7a96fdf8b5fb8ec14d173f3bb0383d461f5780
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Add experimental ebdb-completion-at-point-function
    
    * ebdb-complete.el (ebdb-completion-at-point-function): New function
      that could be used as a completion-at-point function. Not sure this
      is a good idea, though.
---
 ebdb-complete.el | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/ebdb-complete.el b/ebdb-complete.el
index a892ddd..66c9a9b 100644
--- a/ebdb-complete.el
+++ b/ebdb-complete.el
@@ -56,6 +56,42 @@
 (require 'message)
 (require 'sendmail)
 
+;; Experimental completion-at-point function.  I'm not sure this is a
+;; good idea yet -- with a large enough EBDB database, nearly any
+;; string is completable, meaning the other completion-at-point
+;; functions will rarely get a chance.
+(defun ebdb-completion-at-point-function ()
+  "Try to find an EBDB completion for the text at point.
+For use in `completion-at-point-functions'."
+  ;; Might consider restricting this to text-mode buffers -- would you
+  ;; ever want to complete contact names in prog-mode?
+  (let* ((start (point))
+        (chunk (buffer-substring
+                (save-excursion
+                  ;; First try going back two words.
+                  (forward-word -2)
+                  (setq start (point)))
+                (point)))
+        (completions (all-completions (downcase chunk) ebdb-hashtable)))
+    (unless completions
+      ;; If that didn't work, try just one word.
+      (setq chunk (buffer-substring
+                  (save-excursion
+                    (forward-word -1)
+                    (setq start (point)))
+                  (point))
+           completions (all-completions (downcase chunk) ebdb-hashtable)))
+    (when completions
+      (list start (point)
+           (mapcar
+            (lambda (str)
+              ;; Gross.
+              (if (string-match-p "@" str)
+                  str
+                (capitalize str)))
+            completions)
+           '(:exclusive no)))))
+
 (defvar ebdb-complete-info (make-hash-table)
   "A hashtable, record buffer, buffer-window and window-point")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]