* wl-draft.el (wl-draft-previous-history-element): New function.
authoryoichi <yoichi>
Sun, 14 Sep 2003 10:35:40 +0000 (10:35 +0000)
committeryoichi <yoichi>
Sun, 14 Sep 2003 10:35:40 +0000 (10:35 +0000)
(wl-draft-next-history-element): Ditto.
* wl-e21.el, wl-xmas.el, wl-mule.el (wl-draft-key-setup): Bind
them to M-p and M-n.

wl/ChangeLog
wl/wl-draft.el
wl/wl-e21.el
wl/wl-mule.el
wl/wl-xmas.el

index 9043e57..1088233 100644 (file)
@@ -1,3 +1,10 @@
+2003-09-14  Yoichi NAKAYAMA  <yoichi@geiin.org>
+
+       * wl-draft.el (wl-draft-previous-history-element): New function.
+       (wl-draft-next-history-element): Ditto.
+       * wl-e21.el, wl-xmas.el, wl-mule.el (wl-draft-key-setup): Bind
+       them to M-p and M-n.
+
 2003-09-14  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
 
        * Version number is increased to 2.11.12.
index 752229b..6df2d19 100644 (file)
@@ -2435,6 +2435,80 @@ Automatically applied in draft sending time."
        (set-buffer-modified-p modified))))
   (recenter n))
 
+;; insert element from history
+(defvar wl-draft-current-history-position nil)
+(defvar wl-draft-history-backup-word "")
+
+(defun wl-draft-previous-history-element (n)
+  (interactive "p")
+  (let (bol history)
+    (when (and (not (wl-draft-on-field-p))
+              (< (point)
+                 (save-excursion
+                   (goto-char (point-min))
+                   (search-forward (concat "\n" mail-header-separator "\n") nil 0)
+                   (point)))
+              (save-excursion
+                (beginning-of-line)
+                (while (and (looking-at "^[ \t]")
+                            (not (= (point) (point-min))))
+                  (forward-line -1))
+                (cond
+                 ((looking-at wl-folder-complete-header-regexp)
+                  (and (boundp 'wl-read-folder-hist)
+                       (setq history wl-read-folder-hist)))
+                 ;; ((looking-at wl-address-complete-header-regexp)
+                 ;;  (setq history .....))
+                 (t
+                  nil)))
+              (eolp))
+      (setq bol (save-excursion (beginning-of-line) (point)))
+      (cond ((and (or (eq last-command 'wl-draft-previous-history-element)
+                     (eq last-command 'wl-draft-next-history-element))
+                 wl-draft-current-history-position)
+            (setq end (point))
+            (or (search-backward-regexp ",[ \t]*\\(.*\\)" bol t)
+                (search-backward-regexp "^[ \t]\\(.*\\)" bol t)
+                (search-backward-regexp "^[^ \t]*: \\(.*\\)" bol t))
+            (setq prev (match-string 1))
+            (goto-char (match-beginning 1))
+            (setq beg (point))
+            (if (cond ((< n 0)
+                       (>= (+ n wl-draft-current-history-position) 0))
+                      ((> n 0)
+                       (<= (+ n wl-draft-current-history-position)
+                           (length history))))
+                (progn
+                  (setq wl-draft-current-history-position
+                        (+ n wl-draft-current-history-position))
+                  (setq new
+                        (nth wl-draft-current-history-position
+                             (append (list wl-draft-history-backup-word)
+                                     history)))
+                  (delete-region beg end)
+                  (insert new))
+              (goto-char end)
+              (cond ((< n 0)
+                     (message "End of history; no next item"))
+                    ((> n 0)
+                     (message "Beginning of history; no preceding item")))))
+           ((and (> n 0)
+                 (save-excursion
+                   (or (search-backward-regexp ",[ \t]*\\(.*\\)" bol t)
+                       (search-backward-regexp "^[ \t]\\(.*\\)" bol t)
+                       (search-backward-regexp "^[^ \t]*: \\(.*\\)" bol t)))
+                 (car history))
+            (setq wl-draft-current-history-position 1)
+            (setq wl-draft-history-backup-word (match-string 1))
+            (delete-region (match-beginning 1) (match-end 1))
+            (insert (car history)))
+           (t
+            (setq wl-draft-current-history-position nil)))))))
+
+(defun wl-draft-next-history-element (n)
+  (interactive "p")
+  (wl-draft-previous-history-element (- n)))
+
 ;;;; user-agent support by Sen Nagata
 
 ;; this appears to be necessarily global...
index 3bdd11a..e71b290 100644 (file)
@@ -630,7 +630,9 @@ Special commands:
 ;;  (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
   (define-key wl-draft-mode-map "\C-xk"    'wl-draft-mimic-kill-buffer)
   (define-key wl-draft-mode-map "\C-c\C-d" 'wl-draft-elide-region)
-  (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line))
+  (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line)
+  (define-key wl-draft-mode-map "\M-p" 'wl-draft-previous-history-element)
+  (define-key wl-draft-mode-map "\M-n" 'wl-draft-next-history-element))
 
 (defun wl-draft-overload-functions ()
   (wl-mode-line-buffer-identification)
index 8f3e799..7cc59ca 100644 (file)
@@ -165,7 +165,9 @@ Special commands:
   (define-key wl-draft-mode-map "\C-c\C-a" 'wl-addrmgr)
   (define-key wl-draft-mode-map "\C-xk" 'wl-draft-mimic-kill-buffer)
   (define-key wl-draft-mode-map "\C-c\C-d" 'wl-draft-elide-region)
-  (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line))
+  (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line)
+  (define-key wl-draft-mode-map "\M-p" 'wl-draft-previous-history-element)
+  (define-key wl-draft-mode-map "\M-n" 'wl-draft-next-history-element))
 
 (defun wl-draft-overload-menubar ()
   (let ((keymap (current-local-map)))
index b0bd02c..5b9a447 100644 (file)
@@ -537,7 +537,9 @@ Special commands:
   (define-key wl-draft-mode-map "\C-c\C-a" 'wl-addrmgr)
   (define-key wl-draft-mode-map "\C-xk"    'wl-draft-mimic-kill-buffer)
   (define-key wl-draft-mode-map "\C-c\C-d" 'wl-draft-elide-region)
-  (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line))
+  (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line)
+  (define-key wl-draft-mode-map "\M-p" 'wl-draft-previous-history-element)
+  (define-key wl-draft-mode-map "\M-n" 'wl-draft-next-history-element))
 
 (defun wl-draft-overload-functions ()
   (wl-mode-line-buffer-identification)