Add standard library headers.
[bpt/emacs.git] / lisp / mail / vms-pmail.el
1 ;;; vms-pmail.el --- use Emacs as the editor within VMS mail.
2
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
4
5 ;; Author: Roland B Roberts <roberts@nsrl31.nsrl.rochester.edu>
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 ;;; Code:
24
25 ;;;
26 ;;; Quick hack to use emacs as mail editor. There are a *bunch* of
27 ;;; changes scattered throughout emacs to make this work, namely:
28 ;;; (1) mod to sysdep.c to allow emacs to attach to a process other
29 ;;; than the one that originally spawned it.
30 ;;; (2) mod to kepteditor.com to define the logical emacs_parent_pid
31 ;;; which is what sysdep.c looks for, and define the logical
32 ;;; emacs_command_args which contains the command line
33 ;;; (3) mod to re-parse command line arguments from emacs_command_args
34 ;;; then execute them as though emacs were just starting up.
35 ;;;
36 (defun vms-pmail-save-and-exit ()
37 "Save current buffer and exit emacs.
38 If this emacs cannot be suspended, you will be prompted about modified
39 buffers other than the mail buffer. BEWARE --- suspending emacs without
40 saving your mail buffer causes mail to abort the send (potentially useful
41 since the mail buffer is still here)."
42 (interactive)
43 (basic-save-buffer)
44 (if (vms-system-info "LOGICAL" "DONT_SUSPEND_EMACS")
45 (progn
46 (save-some-buffers)
47 (kill-emacs 1))
48 (kill-buffer (current-buffer))
49 (suspend-emacs)))
50
51 (defun vms-pmail-abort ()
52 "Mark buffer as unmodified and exit emacs.
53 When the editor is exited without saving its buffer, VMS mail does not
54 send a message. If you have other modified buffers you will be
55 prompted for what to do with them."
56 (interactive)
57 (if (not (yes-or-no-p "Really abort mail? "))
58 (ding)
59 (not-modified)
60 (if (vms-system-info "LOGICAL" "DONT_SUSPEND_EMACS")
61 (progn
62 (save-some-buffers)
63 (kill-emacs 1))
64 (kill-buffer (current-buffer))
65 (suspend-emacs))))
66
67 (defun vms-pmail-setup ()
68 "Set up file assuming use by VMS MAIL utility.
69 The buffer is put into text-mode, auto-save is turned off and the
70 following bindings are established.
71
72 \\[vms-pmail-save-and-exit] vms-pmail-save-and-exit
73 \\[vms-pmail-abort] vms-pmail-abort
74
75 All other emacs commands are still available."
76 (interactive)
77 (auto-save-mode -1)
78 (text-mode)
79 (let ((default (vms-system-info "LOGICAL" "SYS$SCRATCH"))
80 (directory (file-name-directory (buffer-file-name)))
81 (filename (file-name-nondirectory (buffer-file-name))))
82 (if (string= directory "SYS$SCRATCH:")
83 (progn
84 (cd default)
85 (setq buffer-file-name (concat default filename))))
86 (use-local-map (copy-keymap (current-local-map)))
87 (local-set-key "\C-c\C-c" 'vms-pmail-save-and-exit)
88 (local-set-key "\C-c\C-g" 'vms-pmail-abort)))
89
90 (defun indicate-mail-reply-text ()
91 "Prepares received mail for re-sending by placing >'s on each line."
92 (interactive)
93 (goto-char (point-min))
94 (while (not (eobp))
95 (insert ">")
96 (beginning-of-line)
97 (forward-line 1))
98 (set-buffer-modified-p nil)
99 (goto-char (point-min)))
100
101 (defun insert-signature ()
102 "Moves to the end of the buffer and inserts a \"signature\" file.
103 First try the file indicated by environment variable MAIL$TRAILER.
104 If that fails, try the file \"~/.signature\".
105 If neither file exists, fails quietly."
106 (interactive)
107 (end-of-buffer)
108 (newline)
109 (if (vms-system-info "LOGICAL" "MAIL$TRAILER")
110 (if (file-attributes (vms-system-info "LOGICAL" "MAIL$TRAILER"))
111 (insert-file-contents (vms-system-info "LOGICAL" "MAIL$TRAILER"))
112 (if (file-attributes "~/.signature")
113 (insert-file-contents "~/.signature")))))
114
115 ;;; vms-pmail.el ends here