choosing.
* message.el (message-display-abbrev): Use new implementation.
2006-04-12 Lars Magne Ingebrigtsen <larsi@gnus.org>
+ * ecomplete.el (ecomplete-highlight-match-line): Reimplement
+ choosing.
+
* message.el (message-newline-and-indent): Remove debugging.
+ (message-display-abbrev): Use new implementation.
2006-04-12 Reiner Steib <Reiner.Steib@gmx.de>
(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 -1
- ecomplete-match-length (count-lines (point-min) (point-max)))))))
-
-(defun ecomplete-prev-match (type match)
- "Go up the list of matches."
- (interactive)
- (unless (equal match ecomplete-current-match)
- (ecomplete-get-matches type match))
- (when (and ecomplete-current-matches
- (> ecomplete-current-line 0))
- (decf ecomplete-current-line)
- (ecomplete-highlight-match-line)))
-
-(defun ecomplete-next-match (type match)
- "Go down the list of matches."
- (interactive)
- (unless (equal match ecomplete-current-match)
- (ecomplete-get-matches type match))
- (when (and ecomplete-current-matches
- (< ecomplete-current-line ecomplete-match-length))
- (incf ecomplete-current-line)
- (ecomplete-highlight-match-line)))
-
-(defun ecomplete-highlight-match-line ()
+ (buffer-string)))))
+
+(defun ecomplete-display-matches (type word)
+ (let* ((matches (ecomplete-get-matches type word))
+ (line 0)
+ (max-lines (length (split-string matches "\n")))
+ command)
+ (while (not (memq (setq command (read-char)) '(? ?\r)))
+ (cond
+ ((eq command ?n)
+ (setq line (min (1+ line) max-lines)))
+ ((eq command ?p)
+ (setq line (max (1- line) 0))))
+ (ecomplete-highlight-match-line matches line))
+ (when (eq command ?\r)
+ (nth line (split-string ecomplete-current-matches "\n")))))
+
+(defun ecomplete-highlight-match-line (matches line)
(with-temp-buffer
- (insert ecomplete-current-matches)
+ (insert matches)
(goto-char (point-min))
- (forward-line ecomplete-current-line)
+ (forward-line line)
(save-restriction
(narrow-to-region (point) (line-end-position))
(while (not (eobp))
(forward-char 1)))
(message "%s" (buffer-string))))
-(defun ecomplete-return-current-match ()
- (nth ecomplete-current-line (split-string ecomplete-current-matches "\n")))
-
(provide 'ecomplete)
;;; ecomplete.el ends here
(define-key message-mode-map "\t" 'message-tab)
(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))
+ (define-key message-mode-map "\M-n" 'message-display-abbrev))
(easy-menu-define
message-mode-menu message-mode-map "Message Menu."
string))))
(ecomplete-save))
-(defun message-next-abbrev ()
+(defun message-display-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)))
- (if (and (not (zerop (length current-message)))
- (get-text-property 0 'ecomplete current-message))
- (insert (ecomplete-return-current-match))
- (newline-and-indent))))
+ (let* ((end (point))
+ (start (save-excursion
+ (re-search-backward "\n\t " nil t)
+ (1- (point))))
+ (word (buffer-substring start end))
+ (match (ecomplete-display-matches 'mail word)))
+ (when match
+ (delete-region start end)
+ (insert match)))))
(when (featurep 'xemacs)
(require 'messagexmas)