Mercurial > emacs
annotate lisp/mail/rmailedit.el @ 814:38b2499cb3e9
*** empty log message ***
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Fri, 17 Jul 1992 20:24:00 +0000 |
parents | 4f28bd14272c |
children | 213978acbc1e |
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 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
3 ;; Maintainer: FSF |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
4 ;; Last-Modified: 31 Jul 1991 |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
5 ;; Keywords: mail |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
6 |
36 | 7 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
25 ;;; Code: |
36 | 26 |
27 (require 'rmail) | |
28 | |
29 (defvar rmail-edit-map nil) | |
30 (if rmail-edit-map | |
31 nil | |
368 | 32 (setq rmail-edit-map (nconc (make-sparse-keymap) (cdr text-mode-map))) |
36 | 33 (define-key rmail-edit-map "\C-c\C-c" 'rmail-cease-edit) |
34 (define-key rmail-edit-map "\C-c\C-]" 'rmail-abort-edit)) | |
35 | |
36 ;; Rmail Edit mode is suitable only for specially formatted data. | |
37 (put 'rmail-edit-mode 'mode-class 'special) | |
38 | |
39 (defun rmail-edit-mode () | |
40 "Major mode for editing the contents of an RMAIL message. | |
41 The editing commands are the same as in Text mode, together with two commands | |
42 to return to regular RMAIL: | |
43 * rmail-abort-edit cancels the changes | |
44 you have made and returns to RMAIL | |
45 * rmail-cease-edit makes them permanent. | |
46 \\{rmail-edit-map}" | |
47 (use-local-map rmail-edit-map) | |
48 (setq major-mode 'rmail-edit-mode) | |
49 (setq mode-name "RMAIL Edit") | |
50 (if (boundp 'mode-line-modified) | |
51 (setq mode-line-modified (default-value 'mode-line-modified)) | |
52 (setq mode-line-format (default-value 'mode-line-format))) | |
53 (run-hooks 'text-mode-hook 'rmail-edit-mode-hook)) | |
54 | |
55 (defun rmail-edit-current-message () | |
56 "Edit the contents of this message." | |
57 (interactive) | |
58 (rmail-edit-mode) | |
59 (make-local-variable 'rmail-old-text) | |
60 (setq rmail-old-text (buffer-substring (point-min) (point-max))) | |
61 (setq buffer-read-only nil) | |
62 (set-buffer-modified-p (buffer-modified-p)) | |
63 ;; Make mode line update. | |
64 (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit) | |
65 (eq (key-binding "\C-c\C-]") 'rmail-abort-edit)) | |
66 (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort") | |
67 (message (substitute-command-keys | |
68 "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort")))) | |
69 | |
70 (defun rmail-cease-edit () | |
71 "Finish editing message; switch back to Rmail proper." | |
72 (interactive) | |
73 ;; Make sure buffer ends with a newline. | |
74 (save-excursion | |
75 (goto-char (point-max)) | |
76 (if (/= (preceding-char) ?\n) | |
77 (insert "\n")) | |
78 ;; Adjust the marker that points to the end of this message. | |
79 (set-marker (aref rmail-message-vector (1+ rmail-current-message)) | |
80 (point))) | |
81 (let ((old rmail-old-text)) | |
82 ;; Update the mode line. | |
83 (set-buffer-modified-p (buffer-modified-p)) | |
84 (rmail-mode-1) | |
85 (if (and (= (length old) (- (point-max) (point-min))) | |
86 (string= old (buffer-substring (point-min) (point-max)))) | |
87 () | |
88 (setq old nil) | |
89 (rmail-set-attribute "edited" t) | |
90 (if (boundp 'rmail-summary-vector) | |
91 (progn | |
92 (aset rmail-summary-vector (1- rmail-current-message) nil) | |
93 (save-excursion | |
94 (rmail-widen-to-current-msgbeg | |
95 (function (lambda () | |
96 (forward-line 2) | |
97 (if (looking-at "Summary-line: ") | |
98 (let ((buffer-read-only nil)) | |
99 (delete-region (point) | |
100 (progn (forward-line 1) | |
101 (point)))))))) | |
102 (rmail-show-message)))))) | |
103 (setq buffer-read-only t)) | |
104 | |
105 (defun rmail-abort-edit () | |
106 "Abort edit of current message; restore original contents." | |
107 (interactive) | |
108 (delete-region (point-min) (point-max)) | |
109 (insert rmail-old-text) | |
110 (rmail-cease-edit)) | |
111 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
368
diff
changeset
|
112 ;;; rmailedit.el ends here |