Converted xemacs *screen* nomenclature to *frame*.
[bpt/emacs.git] / lisp / vms-patch.el
CommitLineData
d501f516
ER
1;;; vms-patch.el --- override parts of files.el for VMS.
2
55badf85 3;; Copyright (C) 1986, 1992 Free Software Foundation, Inc.
eea8d4ef 4
e5167999 5;; Maintainer: FSF
6251ee24 6;; Keywords: vms
e5167999 7
a2535589
JA
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
e5167999 12;; the Free Software Foundation; either version 2, or (at your option)
a2535589
JA
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to
22;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
e5167999 24;;; Code:
a2535589
JA
25
26;;; Functions that need redefinition
27
28;;; VMS file names are upper case, but buffer names are more
29;;; convenient in lower case.
30
31(defun create-file-buffer (filename)
32 "Create a suitably named buffer for visiting FILENAME, and return it.
33FILENAME (sans directory) is used unchanged if that name is free;
34otherwise a string <2> or <3> or ... is appended to get an unused name."
35 (generate-new-buffer (downcase (file-name-nondirectory filename))))
36
37;;; Given a string FN, return a similar name which is a legal VMS filename.
38;;; This is used to avoid invalid auto save file names.
39(defun make-legal-file-name (fn)
40 (setq fn (copy-sequence fn))
41 (let ((dot nil) (indx 0) (len (length fn)) chr)
42 (while (< indx len)
43 (setq chr (aref fn indx))
44 (cond
45 ((eq chr ?.) (if dot (aset fn indx ?_) (setq dot t)))
46 ((not (or (and (>= chr ?a) (<= chr ?z)) (and (>= chr ?A) (<= chr ?Z))
47 (and (>= chr ?0) (<= chr ?9))
48 (eq chr ?$) (eq chr ?_) (and (eq chr ?-) (> indx 0))))
49 (aset fn indx ?_)))
50 (setq indx (1+ indx))))
51 fn)
52
53;;; Auto save filesnames start with _$ and end with $.
54
55(defun make-auto-save-file-name ()
56 "Return file name to use for auto-saves of current buffer.
66657f27
RS
57This function does not consider `auto-save-visited-file-name';
58the caller should check that before calling this function.
59This is a separate function so that your `.emacs' file or the site's
60`site-init.el' can redefine it.
61See also `auto-save-file-name-p'."
a2535589
JA
62 (if buffer-file-name
63 (concat (file-name-directory buffer-file-name)
64 "_$"
65 (file-name-nondirectory buffer-file-name)
66 "$")
67 (expand-file-name (concat "_$_" (make-legal-file-name (buffer-name)) "$"))))
68
69(defun auto-save-file-name-p (filename)
66657f27 70 "Return t if FILENAME can be yielded by `make-auto-save-file-name'.
a2535589 71FILENAME should lack slashes.
66657f27
RS
72This is a separate function so that your `.emacs' file or the site's
73`site-init.el' can redefine it."
a2535589
JA
74 (string-match "^_\\$.*\\$" filename))
75
55badf85
RS
76;;;
77;;; This goes along with kepteditor.com which defines these logicals
78;;; If EMACS_COMMAND_ARGS is defined, it supersedes EMACS_FILE_NAME,
79;;; which is probably set up incorrectly anyway.
80;;; The function command-line-again is a kludge, but it does the job.
81;;;
a2535589
JA
82(defun vms-suspend-resume-hook ()
83 "When resuming suspended Emacs, check for file to be found.
84If the logical name `EMACS_FILE_NAME' is defined, `find-file' that file."
55badf85
RS
85 (let ((file (vms-system-info "LOGICAL" "EMACS_FILE_NAME"))
86 (args (vms-system-info "LOGICAL" "EMACS_COMMAND_ARGS"))
87 (line (vms-system-info "LOGICAL" "EMACS_FILE_LINE")))
88 (if (not args)
89 (if file
90 (progn (find-file file)
91 (if line (goto-line (string-to-int line)))))
92 (cd (file-name-directory file))
93 (vms-command-line-again))))
a2535589
JA
94
95(setq suspend-resume-hook 'vms-suspend-resume-hook)
96
97(defun vms-suspend-hook ()
98 "Don't allow suspending if logical name `DONT_SUSPEND_EMACS' is defined."
99 (if (vms-system-info "LOGICAL" "DONT_SUSPEND_EMACS")
100 (error "Can't suspend this emacs"))
101 nil)
102
103(setq suspend-hook 'vms-suspend-hook)
104
55badf85
RS
105;;;
106;;; A kludge that allows reprocessing of the command line. This is mostly
107;;; to allow a spawned VMS mail process to do something reasonable when
108;;; used in conjunction with the modifications to sysdep.c that allow
109;;; Emacs to attach to a "foster" parent.
110;;;
111(defun vms-command-line-again ()
112 "Reprocess command line arguments. VMS specific.
113Command line arguments are initialized from the logical EMACS_COMMAND_ARGS
114which is defined by kepteditor.com. On VMS this allows attaching to a
115spawned Emacs and doing things like \"emacs -l myfile.el -f doit\""
116 (let* ((args (downcase (vms-system-info "LOGICAL" "EMACS_COMMAND_ARGS")))
117 (command-line-args (list "emacs"))
118 (beg 0)
119 (end 0)
120 (len (length args))
121 this-char)
122 (if args
123 (progn
124;;; replace non-printable stuff with spaces
125 (while (< beg (length args))
126 (if (or (> 33 (setq this-char (aref args beg)))
127 (< 127 this-char))
128 (aset args beg 32))
129 (setq beg (1+ beg)))
130 (setq beg (1- (length args)))
131 (while (= 32 (aref args beg)) (setq beg (1- beg)))
132 (setq args (substring args 0 (1+ beg)))
133 (setq beg 0)
134;;; now start parsing args
135 (while (< beg (length args))
136 (while (and (< beg (length args))
137 (or (> 33 (setq this-char (aref args beg)))
138 (< 127 this-char))
139 (setq beg (1+ beg))))
140 (setq end (1+ beg))
141 (while (and (< end (length args))
142 (< 32 (setq this-char (aref args end)))
143 (> 127 this-char))
144 (setq end (1+ end)))
145 (setq command-line-args (append
146 command-line-args
147 (list (substring args beg end))))
148 (setq beg (1+ end)))
149 (command-line)))))
150
a2535589
JA
151(defun vms-read-directory (dirname switches buffer)
152 (save-excursion
153 (set-buffer buffer)
154 (subprocess-command-to-buffer
155 (concat "DIRECTORY " switches " " dirname)
156 buffer)
157 (goto-char (point-min))
158 ;; Remove all the trailing blanks.
159 (while (search-forward " \n")
160 (forward-char -1)
161 (delete-horizontal-space))
162 (goto-char (point-min))))
163
164(setq dired-listing-switches
165 "/SIZE/DATE/OWNER/WIDTH=(FILENAME=32,SIZE=5)")
86581d96
JB
166
167(setq print-region-function
168 '(lambda (start end command ign1 ign2 ign3 &rest switches)
169 (write-region start end "sys$login:delete-me.txt")
170 (send-command-to-subprocess
171 1
172 (concat command
6f680efb 173 " sys$login:delete-me.txt/name=\"GNUprintbuffer\" "
86581d96
JB
174 (mapconcat 'identity switches " "))
175 nil nil nil)))
d501f516 176
55badf85
RS
177;;;
178;;; Fuctions for using Emacs as a VMS Mail editor
179;;;
180(autoload 'vms-pmail-setup "vms-pmail"
181 "Set up file assuming use by VMS Mail utility.
182The buffer is put into text-mode, auto-save is turned off and the
183following bindings are established.
184
185\\[vms-pmail-save-and-exit] vms-pmail-save-and-exit
186\\[vms-pmail-abort] vms-pmail-abort
187
188All other Emacs commands are still available."
189 t)
190
d501f516 191;;; vms-patch.el ends here