|
|
1.1 root 1: ;; "RMAIL edit mode" Edit the current message.
2: ;; Copyright (C) 1985 Free Software Foundation, Inc.
3:
4: ;; This file is part of GNU Emacs.
5:
6: ;; GNU Emacs is distributed in the hope that it will be useful,
7: ;; but WITHOUT ANY WARRANTY. No author or distributor
8: ;; accepts responsibility to anyone for the consequences of using it
9: ;; or for whether it serves any particular purpose or works at all,
10: ;; unless he says so in writing. Refer to the GNU Emacs General Public
11: ;; License for full details.
12:
13: ;; Everyone is granted permission to copy, modify and redistribute
14: ;; GNU Emacs, but only under the conditions described in the
15: ;; GNU Emacs General Public License. A copy of this license is
16: ;; supposed to have been given to you along with GNU Emacs so you
17: ;; can know your rights and responsibilities. It should be in a
18: ;; file named COPYING. Among other things, the copyright notice
19: ;; and this notice must be preserved on all copies.
20:
21:
22: (require 'rmail)
23:
24: (defvar rmail-edit-map nil)
25: (if rmail-edit-map
26: nil
27: (setq rmail-edit-map (copy-keymap text-mode-map))
28: (define-key rmail-edit-map "\C-c\C-c" 'rmail-cease-edit)
29: (define-key rmail-edit-map "\C-c\C-]" 'rmail-abort-edit))
30:
31: ;; Rmail Edit mode is suitable only for specially formatted data.
32: (put 'rmail-edit-mode 'mode-class 'special)
33:
34: (defun rmail-edit-mode ()
35: "Major mode for editing the contents of an RMAIL message.
36: The editing commands are the same as in Text mode, together with two commands
37: to return to regular RMAIL:
38: * rmail-abort-edit cancels the changes
39: you have made and returns to RMAIL
40: * rmail-cease-edit makes them permanent.
41: \\{rmail-edit-map}"
42: (use-local-map rmail-edit-map)
43: (setq major-mode 'rmail-edit-mode)
44: (setq mode-name "RMAIL Edit")
45: (if (boundp 'mode-line-modified)
46: (setq mode-line-modified (default-value 'mode-line-modified))
47: (setq mode-line-format (default-value 'mode-line-format)))
48: (run-hooks 'text-mode-hook 'rmail-edit-mode-hook))
49:
50: (defun rmail-edit-current-message ()
51: "Edit the contents of this message."
52: (interactive)
53: (rmail-edit-mode)
54: (make-local-variable 'rmail-old-text)
55: (setq rmail-old-text (buffer-substring (point-min) (point-max)))
56: (setq buffer-read-only nil)
57: (set-buffer-modified-p (buffer-modified-p))
58: ;; Make mode line update.
59: (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
60: (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
61: (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort")
62: (message (substitute-command-keys
63: "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
64:
65: (defun rmail-cease-edit ()
66: "Finish editing message; switch back to Rmail proper."
67: (interactive)
68: ;; Make sure buffer ends with a newline.
69: (save-excursion
70: (goto-char (point-max))
71: (if (/= (preceding-char) ?\n)
72: (insert "\n"))
73: ;; Adjust the marker that points to the end of this message.
74: (set-marker (aref rmail-message-vector (1+ rmail-current-message))
75: (point)))
76: (let ((old rmail-old-text))
77: ;; Update the mode line.
78: (set-buffer-modified-p (buffer-modified-p))
79: (rmail-mode-1)
80: (if (and (= (length old) (- (point-max) (point-min)))
81: (string= old (buffer-substring (point-min) (point-max))))
82: ()
83: (setq old nil)
84: (rmail-set-attribute "edited" t)
85: (if (boundp 'rmail-summary-vector)
86: (progn
87: (aset rmail-summary-vector (1- rmail-current-message) nil)
88: (save-excursion
89: (rmail-widen-to-current-msgbeg
90: (function (lambda ()
91: (forward-line 2)
92: (if (looking-at "Summary-line: ")
93: (let ((buffer-read-only nil))
94: (delete-region (point)
95: (progn (forward-line 1)
96: (point))))))))
97: (rmail-show-message))))))
98: (setq buffer-read-only t))
99:
100: (defun rmail-abort-edit ()
101: "Abort edit of current message; restore original contents."
102: (interactive)
103: (delete-region (point-min) (point-max))
104: (insert rmail-old-text)
105: (rmail-cease-edit))
106:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.