* ecomplete.el: Implement more bits.
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 12 Apr 2006 12:37:14 +0000 (12:37 +0000)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 12 Apr 2006 12:37:14 +0000 (12:37 +0000)
* message.el (message-put-addresses-in-ecomplete): Clean up the
string.

lisp/ChangeLog
lisp/ecomplete.el
lisp/message.el

index aac5ee2..14c4439 100644 (file)
@@ -1,5 +1,10 @@
 2006-04-12  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
+       * ecomplete.el: Implement more bits.
+
+       * message.el (message-put-addresses-in-ecomplete): Clean up the
+       string. 
+
        * ecomplete.el (ecomplete-add-item): Chop off decimals.
 
        * gnus-sum.el (gnus-summary-save-parts): Bind
index f6d5b4f..3c916cb 100644 (file)
@@ -40,6 +40,9 @@
 ;;; Internal variables.
 
 (defvar ecomplete-database nil)
+(defvar ecomplete-current-matches nil)
+(defvar ecomplete-match-length nil)
+(defvar ecomplete-current-line nil)
 
 (defun ecomplete-setup ()
   (when (file-exists-p ecomplete-database-file)
     (insert ")")
     (write-region (point-min) (point-max) ecomplete-database-file nil 'silent)))
 
+(defun ecomplete-show-matches (type match)
+  (let* ((elems (cdr (assq type ecomplete-database)))
+        (match (regexp-quote match))
+        (candidates
+         (sort 
+          (loop for (key count time text) in elems
+                when (string-match match text)
+                collect (list count time text))
+          (lambda (l1 l2)
+            (> (car l1) (car l2))))))
+    (when (> (length candidates) 10)
+      (setcdr (nthcdr 10 candidates) nil))
+    (unless (zerop (length candidates))
+      (with-temp-buffer
+       (dolist (candidate candidates)
+         (insert (caddr candidate) "\n"))
+       (goto-char (point-min))
+       (while (re-search-forward match nil t)
+         (put-text-property (match-beginning 0) (match-end 0)
+                            'face 'isearch))
+       (setq ecomplete-current-matches (buffer-string)
+             ecomplete-current-line 0
+             ecomplete-match-length (count-lines (point-min) (point-max)))
+       (ecomplete-highlight-match-line)))))
+
+(defun ecomplete-up-list ()
+  "Go up the list of matches."
+  (interactive)
+  (when (and ecomplete-current-matches
+            (> ecomplete-current-line 0))
+    (decf ecomplete-current-line)
+    (ecomplete-highlight-match-line)))
+
+(defun ecomplete-down-list ()
+  "Go down the list of matches."
+  (interactive)
+  (when (and ecomplete-current-matches
+            (< ecomplete-current-line ecomplete-match-length))
+    (incf ecomplete-current-line)
+    (ecomplete-highlight-match-line)))
+
+(defun ecomplete-highlight-match-line ()
+  (with-temp-buffer
+    (insert ecomplete-current-matches)
+    (goto-char (point-min))
+    (forward-line ecomplete-current-line)
+    (save-restriction
+      (narrow-to-region (point) (line-end-position))
+      (while (not (eobp))
+       ;; Put the 'region face on any charactes on this line that
+       ;; aren't already highlighted.
+       (unless (get-text-property (point) 'face)
+         (put-text-property (point) (1+ (point)) 'face 'region))
+       (forward-char 1)))
+    (message "%s" (buffer-string))))
+
 (provide 'ecomplete)
 
 ;;; ecomplete.el ends here
index 9c3fb9a..0e3e28a 100644 (file)
@@ -7164,6 +7164,10 @@ From headers in the original article."
   (dolist (header '("to" "cc" "from" "reply-to"))
     (let ((value (message-fetch-field header)))
       (dolist (string (mail-header-parse-addresses value 'raw))
+       (setq string
+             (replace-regexp-in-string
+              "\n" "" 
+              (replace-regexp-in-string "^ +\\| *$" "" string)))
        (ecomplete-add-item 'mail (car (mail-header-parse-address string))
                            string)))))