Mercurial > emacs
annotate lisp/mail/rmailedit.el @ 755:e43123226372
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Fri, 10 Jul 1992 01:16:40 +0000 |
parents | 7cbd4fcd8b0f |
children | 4f28bd14272c |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
368
diff
changeset
|
1 ;;; rmailedit.el --- "RMAIL edit mode" Edit the current message. |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
368
diff
changeset
|
2 |
36 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 1, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | |
21 | |
22 (require 'rmail) | |
23 | |
24 (defvar rmail-edit-map nil) | |
25 (if rmail-edit-map | |
26 nil | |
368 | 27 (setq rmail-edit-map (nconc (make-sparse-keymap) (cdr text-mode-map))) |
36 | 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 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
368
diff
changeset
|
107 ;;; rmailedit.el ends here |