aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2002-01-03 16:52:26 +0000
committerEli Zaretskii2002-01-03 16:52:26 +0000
commit6cd4cfc5ad2cb8832dda3841e66464258a8d1370 (patch)
tree6e6d085b51924210182a7b00be8c65e59c3c84f8
parent1f7d2e140f4293a933fd96355aa17c08581fc4de (diff)
downloademacs-6cd4cfc5ad2cb8832dda3841e66464258a8d1370.tar.gz
emacs-6cd4cfc5ad2cb8832dda3841e66464258a8d1370.zip
(mail-recover-1): New function.
(mail-recover): Switch to the *mail* buffer right away. Use buffer-auto-save-file-name instead of calling make-auto-save-file-name. Call dired-noselect instead of invoking `ls' directly. Bind coding-system-for-read to emacs-mule-unix before reading the auto-save file. If the buffer's auto-save file does not exist, call mail-recover-1 to allow recovery from past auto-saved drafts.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/mail/sendmail.el125
2 files changed, 122 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bea449baeca..1e96641cbfb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12002-01-03 Eli Zaretskii <eliz@is.elta.co.il>
2
3 * mail/sendmail.el (mail-recover-1): New function.
4 (mail-recover): Switch to the *mail* buffer right away. Use
5 buffer-auto-save-file-name instead of calling
6 make-auto-save-file-name. Call dired-noselect instead of invoking
7 `ls' directly. Bind coding-system-for-read to emacs-mule-unix
8 before reading the auto-save file. If the buffer's auto-save file
9 does not exist, call mail-recover-1 to allow recovery from past
10 auto-saved drafts.
11
12002-01-03 Pavel Jan,Bm(Bk <Pavel@Janik.cz> 122002-01-03 Pavel Jan,Bm(Bk <Pavel@Janik.cz>
2 13
3 * time.el (display-time-load-average-threshold): Fix defcustom 14 * time.el (display-time-load-average-threshold): Fix defcustom
diff --git a/lisp/mail/sendmail.el b/lisp/mail/sendmail.el
index 0927966e651..2d3073f3b44 100644
--- a/lisp/mail/sendmail.el
+++ b/lisp/mail/sendmail.el
@@ -1535,22 +1535,119 @@ The seventh argument ACTIONS is a list of actions to take
1535 (message "Auto save file for draft message exists; consider M-x mail-recover")) 1535 (message "Auto save file for draft message exists; consider M-x mail-recover"))
1536 initialized)) 1536 initialized))
1537 1537
1538(defun mail-recover-1 ()
1539 "Pop up a list of auto-saved draft messages and allow to recover them."
1540 (interactive)
1541 (let ((file-name (make-auto-save-file-name))
1542 (ls-lisp-support-shell-wildcards t)
1543 non-random-len wildcard)
1544 ;; Remove the random part from the auto-save-file-name, and
1545 ;; create a wildcard which matches possible candidates.
1546 ;; Note: this knows that make-auto-save-file-name appends
1547 ;; "#<RANDOM-STUFF>#" to the buffer name, where RANDOM-STUFF
1548 ;; is the result of (make-temp-name "").
1549 (setq non-random-len
1550 (- (length file-name) (length (make-temp-name "")) 1))
1551 (setq wildcard (concat (substring file-name 0 non-random-len) "*"))
1552 (if (null (file-expand-wildcards wildcard))
1553 (message "There are no auto-saved drafts to recover")
1554 ;; Bind dired-trivial-filenames to t because all auto-save file
1555 ;; names are normally ``trivial'', so Dired will set point after
1556 ;; all the files, at buffer bottom. We want it on the first
1557 ;; file instead.
1558 (let ((dired-trivial-filenames t))
1559 (dired-other-window wildcard (concat dired-listing-switches "t")))
1560 (rename-buffer "*Auto-saved Drafts*" t)
1561 (save-excursion
1562 (goto-char (point-min))
1563 (or (looking-at " Move to the draft file you want to recover,")
1564 (let ((inhibit-read-only t))
1565 ;; Each line starts with a space so that Font Lock mode
1566 ;; won't highlight the first character.
1567 (insert "\
1568 Move to the draft file you want to recover, then type C-c C-c
1569 to recover text of message whose composition was interrupted.
1570 To browse text of a draft, type v on the draft file's line.
1571
1572 You can also delete some of these files;
1573 type d on a line to mark that file for deletion.
1574
1575 List of possible auto-save files for recovery:
1576
1577"))))
1578 (use-local-map
1579 (let ((map (make-sparse-keymap)))
1580 (set-keymap-parent map (current-local-map))
1581 map))
1582 (define-key (current-local-map) "v"
1583 (lambda ()
1584 (interactive)
1585 (let ((coding-system-for-read 'emacs-mule-unix))
1586 (dired-view-file))))
1587 (define-key (current-local-map) "\C-c\C-c"
1588 (lambda ()
1589 (interactive)
1590 (let ((fname (dired-get-filename))
1591 ;; Auto-saved files are written in the internal
1592 ;; representation, so they should be read accordingly.
1593 (coding-system-for-read 'emacs-mule-unix))
1594 (switch-to-buffer-other-window "*mail*")
1595 (let ((buffer-read-only nil))
1596 (erase-buffer)
1597 (insert-file-contents fname nil)
1598 ;; insert-file-contents will set buffer-file-coding-system
1599 ;; to emacs-mule, which is probably not what they want to
1600 ;; use for sending the message. But we don't know what
1601 ;; was its value before the buffer was killed or Emacs
1602 ;; crashed. We therefore reset buffer-file-coding-system
1603 ;; to the default value, so that either the default does
1604 ;; TRT, or the user will get prompted for the right
1605 ;; encoding when they send the message.
1606 (setq buffer-file-coding-system
1607 default-buffer-file-coding-system))))))))
1608
1538(defun mail-recover () 1609(defun mail-recover ()
1539 "Reread contents of current buffer from its last auto-save file." 1610 "Recover interrupted mail composition from auto-save files."
1540 (interactive) 1611 (interactive)
1541 (let ((file-name (make-auto-save-file-name))) 1612 ;; In case they invoke us from some random buffer...
1542 (cond ((save-window-excursion 1613 (switch-to-buffer "*mail*")
1543 (if (not (eq system-type 'vax-vms)) 1614 ;; If *mail* didn't exist, set its directory, so that auto-saved
1544 (with-output-to-temp-buffer "*Directory*" 1615 ;; drafts will be found.
1545 (buffer-disable-undo standard-output) 1616 (if (file-exists-p (expand-file-name "~/"))
1546 (let ((default-directory "/")) 1617 (setq default-directory "~/"))
1547 (call-process 1618 (or (eq major-mode 'mail-mode)
1548 "ls" nil standard-output nil "-l" file-name)))) 1619 (mail-mode))
1549 (yes-or-no-p (format "Recover auto save file %s? " file-name))) 1620 (let ((file-name buffer-auto-save-file-name))
1550 (let ((buffer-read-only nil)) 1621 (cond ((and file-name (file-exists-p file-name))
1551 (erase-buffer) 1622 (let ((dispbuf
1552 (insert-file-contents file-name nil))) 1623 ;; This used to invoke `ls' via call-process, but
1553 (t (error "mail-recover cancelled"))))) 1624 ;; dired-noselect is more portable to systems where
1625 ;; `ls' is not a standard program (it will use
1626 ;; ls-lisp instead).
1627 (dired-noselect file-name
1628 (concat dired-listing-switches "t"))))
1629 (save-excursion
1630 (set-buffer dispbuf)
1631 (let ((buffer-read-only nil))
1632 (goto-char (point-min))
1633 (forward-line)
1634 (kill-line 2)
1635 (dired-move-to-filename)
1636 (setq dispbuf (rename-buffer "*Directory*" t))))
1637 (display-buffer dispbuf t)
1638 (if (not (yes-or-no-p
1639 (format "Recover mail draft from auto save file %s? "
1640 file-name)))
1641 (error "mail-recover cancelled")
1642 (let ((buffer-read-only nil)
1643 (buffer-coding buffer-file-coding-system)
1644 ;; Auto-save files are written in internal
1645 ;; representation of non-ASCII characters.
1646 (coding-system-for-read 'emacs-mule-unix))
1647 (erase-buffer)
1648 (insert-file-contents file-name nil)
1649 (setq buffer-file-coding-system buffer-coding)))))
1650 (t (mail-recover-1)))))
1554 1651
1555;;;###autoload 1652;;;###autoload
1556(defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions) 1653(defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions)