1535 |
(message "Auto save file for draft message exists; consider M-x mail-recover")) |
(message "Auto save file for draft message exists; consider M-x mail-recover")) |
1536 |
initialized)) |
initialized)) |
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 |
|
|
1609 |
(defun mail-recover () |
(defun mail-recover () |
1610 |
"Reread contents of current buffer from its last auto-save file." |
"Recover interrupted mail composition from auto-save files." |
1611 |
(interactive) |
(interactive) |
1612 |
(let ((file-name (make-auto-save-file-name))) |
;; In case they invoke us from some random buffer... |
1613 |
(cond ((save-window-excursion |
(switch-to-buffer "*mail*") |
1614 |
(if (not (eq system-type 'vax-vms)) |
;; If *mail* didn't exist, set its directory, so that auto-saved |
1615 |
(with-output-to-temp-buffer "*Directory*" |
;; drafts will be found. |
1616 |
(buffer-disable-undo standard-output) |
(if (file-exists-p (expand-file-name "~/")) |
1617 |
(let ((default-directory "/")) |
(setq default-directory "~/")) |
1618 |
(call-process |
(or (eq major-mode 'mail-mode) |
1619 |
"ls" nil standard-output nil "-l" file-name)))) |
(mail-mode)) |
1620 |
(yes-or-no-p (format "Recover auto save file %s? " file-name))) |
(let ((file-name buffer-auto-save-file-name)) |
1621 |
(let ((buffer-read-only nil)) |
(cond ((and file-name (file-exists-p file-name)) |
1622 |
(erase-buffer) |
(let ((dispbuf |
1623 |
(insert-file-contents file-name nil))) |
;; This used to invoke `ls' via call-process, but |
1624 |
(t (error "mail-recover cancelled"))))) |
;; 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))))) |
1651 |
|
|
1652 |
;;;###autoload |
;;;###autoload |
1653 |
(defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions) |
(defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions) |