* message.el (message-newline-and-indent): New function.
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 12 Apr 2006 13:22:28 +0000 (13:22 +0000)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 12 Apr 2006 13:22:28 +0000 (13:22 +0000)
* ecomplete.el: Implement more bits.

lisp/ChangeLog
lisp/message.el

index d86dc8c..e9394d9 100644 (file)
@@ -6,6 +6,8 @@
 
 2006-04-12  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
+       * message.el (message-newline-and-indent): New function.
+
        * ecomplete.el: Implement more bits.
 
        * message.el (message-put-addresses-in-ecomplete): Clean up the
index 0e3e28a..bf0e09d 100644 (file)
@@ -2349,7 +2349,11 @@ Prefixed with two \\[universal-argument]'s, display the PGG manual."
 
   (define-key message-mode-map "\C-a" 'message-beginning-of-line)
   (define-key message-mode-map "\t" 'message-tab)
-  (define-key message-mode-map "\M-;" 'comment-region))
+  (define-key message-mode-map "\M-;" 'comment-region)
+
+  (define-key message-mode-map "\M-n" 'message-next-abbrev)
+  (define-key message-mode-map "\M-p" 'message-prev-abbrev)
+  (define-key message-mode-map "\r" 'message-newline-and-indent))
 
 (easy-menu-define
   message-mode-menu message-mode-map "Message Menu."
@@ -2604,11 +2608,14 @@ M-RET    `message-newline-and-reformat' (break the line and reformat)."
   (add-hook 'after-change-functions 'message-strip-forbidden-properties
            nil 'local)
   ;; Allow mail alias things.
-  (when (eq message-mail-alias-type 'abbrev)
+  (cond
+   ((eq message-mail-alias-type 'abbrev)
     (if (fboundp 'mail-abbrevs-setup)
        (mail-abbrevs-setup)
       (if (fboundp 'mail-aliases-setup)        ; warning avoidance
          (mail-aliases-setup))))
+   ((eq message-mail-alias-type 'ecomplete)
+    (ecomplete-setup)))
   (unless buffer-file-name
     (message-set-auto-save-file-name))
   (unless (buffer-base-buffer)
@@ -7169,7 +7176,41 @@ From headers in the original article."
               "\n" "" 
               (replace-regexp-in-string "^ +\\| *$" "" string)))
        (ecomplete-add-item 'mail (car (mail-header-parse-address string))
-                           string)))))
+                           string))))
+  (ecomplete-save))
+
+(defun message-next-abbrev ()
+  "Display the next possible abbrev for the text before point."
+  (interactive)
+  (message-display-abbrev 'next))
+
+(defun message-prev-abbrev ()
+  "Display the previous possible abbrev for the text before point."
+  (interactive)
+  (message-display-abbrev 'prev))
+
+(defun message-display-abbrev (direction)
+  (when (and (message-point-in-header-p)
+            (save-excursion
+              (save-restriction
+                (message-narrow-to-field)
+                (goto-char (point-min))
+                (looking-at "To\\|Cc"))))
+    (let ((word (buffer-substring (point) (save-excursion
+                                           (backward-word) (point)))))
+      (if (eq direction 'next)
+         (ecomplete-next-match 'mail word)
+       (ecomplete-prev-match 'mail word)))))
+
+(defun message-newline-and-indent ()
+  "If looking at an abbrev, insert that.  Otherwise `newline-and-indent'."
+  (interactive)
+  (let ((current-message (current-message)))
+    (debug current-message)
+    (if (and (not (zerop (length current-message)))
+            (get-text-property 0 'ecomplete current-message))
+       (insert (ecomplete-return-current-match))
+      (newline-and-indent))))
 
 (when (featurep 'xemacs)
   (require 'messagexmas)