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