(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."
(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)
"\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)