1 ;;; pmailedit.el --- "PMAIL edit mode" Edit the current message
3 ;; Copyright (C) 1985, 1994, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
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
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
33 (defcustom pmail-edit-mode-hook nil
34 "List of functions to call when editing an PMAIL message."
39 (defvar pmail-old-text)
41 (defvar pmail-edit-map nil)
44 ;; Make a keymap that inherits text-mode-map.
45 (setq pmail-edit-map (make-sparse-keymap))
46 (set-keymap-parent pmail-edit-map text-mode-map)
47 (define-key pmail-edit-map "\C-c\C-c" 'pmail-cease-edit)
48 (define-key pmail-edit-map "\C-c\C-]" 'pmail-abort-edit))
50 ;; Pmail Edit mode is suitable only for specially formatted data.
51 (put 'pmail-edit-mode 'mode-class 'special)
53 (declare-function pmail-summary-disable "" ())
54 (declare-function pmail-summary-enable "pmailsum" ())
56 (defun pmail-edit-mode ()
57 "Major mode for editing the contents of an PMAIL message.
58 The editing commands are the same as in Text mode, together with two commands
59 to return to regular PMAIL:
60 * \\[pmail-abort-edit] cancels the changes
61 you have made and returns to PMAIL
62 * \\[pmail-cease-edit] makes them permanent.
63 This functions runs the normal hook `pmail-edit-mode-hook'.
65 (delay-mode-hooks (text-mode))
66 (use-local-map pmail-edit-map)
67 (setq major-mode 'pmail-edit-mode)
68 (setq mode-name "PMAIL Edit")
69 (if (boundp 'mode-line-modified)
70 (setq mode-line-modified (default-value 'mode-line-modified))
71 (setq mode-line-format (default-value 'mode-line-format)))
72 (if (pmail-summary-exists)
74 (set-buffer pmail-summary-buffer)
75 (pmail-summary-disable)))
76 (run-mode-hooks 'pmail-edit-mode-hook))
78 (defvar pmail-old-pruned nil)
79 (put 'pmail-old-pruned 'permanent-local t)
81 (defvar pmail-edit-saved-coding-system nil)
82 (put 'pmail-edit-saved-coding-system 'permanent-local t)
85 (defun pmail-edit-current-message ()
86 "Edit the contents of this message."
88 (if (= pmail-total-messages 0)
89 (error "No messages in this file"))
90 (make-local-variable 'pmail-old-pruned)
91 (setq pmail-old-pruned (eq pmail-header-style 'normal))
92 (make-local-variable 'pmail-edit-saved-coding-system)
93 (setq pmail-edit-saved-coding-system save-buffer-coding-system)
94 (pmail-header-show-headers)
96 ;; As the local value of save-buffer-coding-system is deleted by
97 ;; pmail-edit-mode, we restore the original value.
98 (make-local-variable 'save-buffer-coding-system)
99 (setq save-buffer-coding-system pmail-edit-saved-coding-system)
100 (make-local-variable 'pmail-old-text)
101 (setq pmail-old-text (buffer-substring (point-min) (point-max)))
102 (setq buffer-read-only nil)
103 (force-mode-line-update)
104 (if (and (eq (key-binding "\C-c\C-c") 'pmail-cease-edit)
105 (eq (key-binding "\C-c\C-]") 'pmail-abort-edit))
106 (message "Editing: Type C-c C-c to return to Pmail, C-c C-] to abort")
107 (message "%s" (substitute-command-keys
108 "Editing: Type \\[pmail-cease-edit] to return to Pmail, \\[pmail-abort-edit] to abort"))))
110 (defun pmail-cease-edit ()
111 "Finish editing message; switch back to Pmail proper."
113 (if (pmail-summary-exists)
115 (set-buffer pmail-summary-buffer)
116 (pmail-summary-enable)))
117 ;; Make sure buffer ends with a newline.
119 (goto-char (point-max))
120 (if (/= (preceding-char) ?\n)
122 ;; Adjust the marker that points to the end of this message.
123 (set-marker (aref pmail-message-vector (1+ pmail-current-message))
125 (let ((old pmail-old-text))
126 (force-mode-line-update)
127 (kill-all-local-variables)
129 (if (boundp 'tool-bar-map)
130 (set (make-local-variable 'tool-bar-map) pmail-tool-bar-map))
132 ;; As the local value of save-buffer-coding-system is changed by
133 ;; pmail-variables, we restore the original value.
134 (setq save-buffer-coding-system pmail-edit-saved-coding-system)
135 (if (and (= (length old) (- (point-max) (point-min)))
136 (string= old (buffer-substring (point-min) (point-max))))
139 (pmail-set-attribute "edited" t)
140 (if (boundp 'pmail-summary-vector)
142 (aset pmail-summary-vector (1- pmail-current-message) nil)
144 (pmail-widen-to-current-msgbeg
147 (if (looking-at "Summary-line: ")
148 (let ((buffer-read-only nil))
149 (delete-region (point)
150 (progn (forward-line 1)
154 (pmail-toggle-header (if pmail-old-pruned 1 0))))
155 (run-hooks 'pmail-mode-hook)
156 (setq buffer-read-only t))
158 (defun pmail-abort-edit ()
159 "Abort edit of current message; restore original contents."
161 (delete-region (point-min) (point-max))
162 (insert pmail-old-text)
164 (pmail-highlight-headers))
169 ;; change-log-default-name: "ChangeLog.pmail"
172 ;; arch-tag: 9524f335-12cc-4e95-9e9b-3208dc30550b
173 ;;; pmailedit.el ends here