Commit | Line | Data |
---|---|---|
73e72da4 | 1 | ;; -*- no-byte-compile: t -*- |
16952f18 DN |
2 | ;; Not byte compiled because it uses functions that are not part of |
3 | ;; emacs, so it would generate unnecessary warnings. | |
55535639 | 4 | ;;; vms-patch.el --- override parts of files.el for VMS |
d501f516 | 5 | |
c90f2757 | 6 | ;; Copyright (C) 1986, 1992, 2001, 2002, 2003, 2004, |
409cc4a3 | 7 | ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
eea8d4ef | 8 | |
e5167999 | 9 | ;; Maintainer: FSF |
6251ee24 | 10 | ;; Keywords: vms |
e5167999 | 11 | |
a2535589 JA |
12 | ;; This file is part of GNU Emacs. |
13 | ||
eb3fa2cf | 14 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
a2535589 | 15 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
16 | ;; the Free Software Foundation, either version 3 of the License, or |
17 | ;; (at your option) any later version. | |
a2535589 JA |
18 | |
19 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | ;; GNU General Public License for more details. | |
23 | ||
24 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 25 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
a2535589 | 26 | |
55535639 PJ |
27 | ;;; Commentary: |
28 | ||
e5167999 | 29 | ;;; Code: |
a2535589 | 30 | |
3cd79f62 | 31 | (defvar print-region-function) |
97546017 | 32 | |
a98daaef RS |
33 | (setq auto-mode-alist (cons '(("\\.com\\'" . dcl-mode)) auto-mode-alist)) |
34 | ||
a2535589 JA |
35 | ;;; Functions that need redefinition |
36 | ||
37 | ;;; VMS file names are upper case, but buffer names are more | |
38 | ;;; convenient in lower case. | |
39 | ||
40 | (defun create-file-buffer (filename) | |
41 | "Create a suitably named buffer for visiting FILENAME, and return it. | |
42 | FILENAME (sans directory) is used unchanged if that name is free; | |
43 | otherwise a string <2> or <3> or ... is appended to get an unused name." | |
44 | (generate-new-buffer (downcase (file-name-nondirectory filename)))) | |
45 | ||
e6e78fb5 | 46 | ;;; Given a string FN, return a similar name which is a valid VMS filename. |
a2535589 | 47 | ;;; This is used to avoid invalid auto save file names. |
e6e78fb5 | 48 | (defun make-valid-file-name (fn) |
a2535589 JA |
49 | (setq fn (copy-sequence fn)) |
50 | (let ((dot nil) (indx 0) (len (length fn)) chr) | |
51 | (while (< indx len) | |
52 | (setq chr (aref fn indx)) | |
53 | (cond | |
54 | ((eq chr ?.) (if dot (aset fn indx ?_) (setq dot t))) | |
55 | ((not (or (and (>= chr ?a) (<= chr ?z)) (and (>= chr ?A) (<= chr ?Z)) | |
56 | (and (>= chr ?0) (<= chr ?9)) | |
57 | (eq chr ?$) (eq chr ?_) (and (eq chr ?-) (> indx 0)))) | |
58 | (aset fn indx ?_))) | |
59 | (setq indx (1+ indx)))) | |
60 | fn) | |
61 | ||
e6e78fb5 JB |
62 | (define-obsolete-function-alias 'make-legal-file-name 'make-valid-file-name "23.1") |
63 | ||
a2535589 JA |
64 | ;;; Auto save filesnames start with _$ and end with $. |
65 | ||
66 | (defun make-auto-save-file-name () | |
67 | "Return file name to use for auto-saves of current buffer. | |
66657f27 RS |
68 | This function does not consider `auto-save-visited-file-name'; |
69 | the caller should check that before calling this function. | |
70 | This is a separate function so that your `.emacs' file or the site's | |
71 | `site-init.el' can redefine it. | |
72 | See also `auto-save-file-name-p'." | |
a2535589 JA |
73 | (if buffer-file-name |
74 | (concat (file-name-directory buffer-file-name) | |
75 | "_$" | |
76 | (file-name-nondirectory buffer-file-name) | |
77 | "$") | |
e6e78fb5 | 78 | (expand-file-name (concat "_$_" (make-valid-file-name (buffer-name)) "$")))) |
a2535589 JA |
79 | |
80 | (defun auto-save-file-name-p (filename) | |
66657f27 | 81 | "Return t if FILENAME can be yielded by `make-auto-save-file-name'. |
a2535589 | 82 | FILENAME should lack slashes. |
66657f27 RS |
83 | This is a separate function so that your `.emacs' file or the site's |
84 | `site-init.el' can redefine it." | |
a2535589 JA |
85 | (string-match "^_\\$.*\\$" filename)) |
86 | ||
55badf85 RS |
87 | ;;; |
88 | ;;; This goes along with kepteditor.com which defines these logicals | |
89 | ;;; If EMACS_COMMAND_ARGS is defined, it supersedes EMACS_FILE_NAME, | |
90 | ;;; which is probably set up incorrectly anyway. | |
91 | ;;; The function command-line-again is a kludge, but it does the job. | |
92 | ;;; | |
a2535589 JA |
93 | (defun vms-suspend-resume-hook () |
94 | "When resuming suspended Emacs, check for file to be found. | |
95 | If the logical name `EMACS_FILE_NAME' is defined, `find-file' that file." | |
55badf85 RS |
96 | (let ((file (vms-system-info "LOGICAL" "EMACS_FILE_NAME")) |
97 | (args (vms-system-info "LOGICAL" "EMACS_COMMAND_ARGS")) | |
98 | (line (vms-system-info "LOGICAL" "EMACS_FILE_LINE"))) | |
99 | (if (not args) | |
100 | (if file | |
101 | (progn (find-file file) | |
027a4b6b | 102 | (if line (goto-line (string-to-number line))))) |
55badf85 RS |
103 | (cd (file-name-directory file)) |
104 | (vms-command-line-again)))) | |
a2535589 JA |
105 | |
106 | (setq suspend-resume-hook 'vms-suspend-resume-hook) | |
107 | ||
108 | (defun vms-suspend-hook () | |
109 | "Don't allow suspending if logical name `DONT_SUSPEND_EMACS' is defined." | |
110 | (if (vms-system-info "LOGICAL" "DONT_SUSPEND_EMACS") | |
111 | (error "Can't suspend this emacs")) | |
112 | nil) | |
113 | ||
114 | (setq suspend-hook 'vms-suspend-hook) | |
115 | ||
55badf85 RS |
116 | ;;; |
117 | ;;; A kludge that allows reprocessing of the command line. This is mostly | |
118 | ;;; to allow a spawned VMS mail process to do something reasonable when | |
119 | ;;; used in conjunction with the modifications to sysdep.c that allow | |
120 | ;;; Emacs to attach to a "foster" parent. | |
121 | ;;; | |
122 | (defun vms-command-line-again () | |
123 | "Reprocess command line arguments. VMS specific. | |
124 | Command line arguments are initialized from the logical EMACS_COMMAND_ARGS | |
125 | which is defined by kepteditor.com. On VMS this allows attaching to a | |
126 | spawned Emacs and doing things like \"emacs -l myfile.el -f doit\"" | |
127 | (let* ((args (downcase (vms-system-info "LOGICAL" "EMACS_COMMAND_ARGS"))) | |
128 | (command-line-args (list "emacs")) | |
129 | (beg 0) | |
130 | (end 0) | |
131 | (len (length args)) | |
132 | this-char) | |
133 | (if args | |
134 | (progn | |
135 | ;;; replace non-printable stuff with spaces | |
136 | (while (< beg (length args)) | |
137 | (if (or (> 33 (setq this-char (aref args beg))) | |
138 | (< 127 this-char)) | |
139 | (aset args beg 32)) | |
140 | (setq beg (1+ beg))) | |
141 | (setq beg (1- (length args))) | |
142 | (while (= 32 (aref args beg)) (setq beg (1- beg))) | |
143 | (setq args (substring args 0 (1+ beg))) | |
144 | (setq beg 0) | |
145 | ;;; now start parsing args | |
146 | (while (< beg (length args)) | |
147 | (while (and (< beg (length args)) | |
148 | (or (> 33 (setq this-char (aref args beg))) | |
149 | (< 127 this-char)) | |
150 | (setq beg (1+ beg)))) | |
151 | (setq end (1+ beg)) | |
152 | (while (and (< end (length args)) | |
153 | (< 32 (setq this-char (aref args end))) | |
154 | (> 127 this-char)) | |
155 | (setq end (1+ end))) | |
f1180544 | 156 | (setq command-line-args (append |
55badf85 RS |
157 | command-line-args |
158 | (list (substring args beg end)))) | |
159 | (setq beg (1+ end))) | |
160 | (command-line))))) | |
161 | ||
a2535589 JA |
162 | (defun vms-read-directory (dirname switches buffer) |
163 | (save-excursion | |
164 | (set-buffer buffer) | |
165 | (subprocess-command-to-buffer | |
166 | (concat "DIRECTORY " switches " " dirname) | |
167 | buffer) | |
168 | (goto-char (point-min)) | |
169 | ;; Remove all the trailing blanks. | |
170 | (while (search-forward " \n") | |
171 | (forward-char -1) | |
172 | (delete-horizontal-space)) | |
173 | (goto-char (point-min)))) | |
174 | ||
175 | (setq dired-listing-switches | |
176 | "/SIZE/DATE/OWNER/WIDTH=(FILENAME=32,SIZE=5)") | |
86581d96 JB |
177 | |
178 | (setq print-region-function | |
a44442ba | 179 | (lambda (start end command ign1 ign2 ign3 &rest switches) |
86581d96 JB |
180 | (write-region start end "sys$login:delete-me.txt") |
181 | (send-command-to-subprocess | |
182 | 1 | |
183 | (concat command | |
6f680efb | 184 | " sys$login:delete-me.txt/name=\"GNUprintbuffer\" " |
86581d96 JB |
185 | (mapconcat 'identity switches " ")) |
186 | nil nil nil))) | |
d501f516 | 187 | |
55badf85 RS |
188 | ;;; |
189 | ;;; Fuctions for using Emacs as a VMS Mail editor | |
190 | ;;; | |
191 | (autoload 'vms-pmail-setup "vms-pmail" | |
192 | "Set up file assuming use by VMS Mail utility. | |
193 | The buffer is put into text-mode, auto-save is turned off and the | |
194 | following bindings are established. | |
195 | ||
196 | \\[vms-pmail-save-and-exit] vms-pmail-save-and-exit | |
197 | \\[vms-pmail-abort] vms-pmail-abort | |
198 | ||
199 | All other Emacs commands are still available." | |
200 | t) | |
201 | ||
214dd398 TTN |
202 | ;;; |
203 | ;;; Filename handling in the minibuffer | |
204 | ;;; | |
205 | (defun vms-magic-right-square-brace () | |
206 | "\ | |
207 | Insert a right square brace, but do other things first depending on context. | |
208 | During filename completion, when point is at the end of the line and the | |
209 | character before is not a right square brace, do one of three things before | |
210 | inserting the brace: | |
211 | - If there are already two left square braces preceding, do nothing special. | |
212 | - If there is a previous right-square-brace, convert it to dot. | |
213 | - If the character before is dot, delete it. | |
214 | Additionally, if the preceding chars are right-square-brace followed by | |
215 | either \"-\" or \"..\", strip one level of directory hierarchy." | |
216 | (interactive) | |
217 | (when (and minibuffer-completing-file-name | |
218 | (= (point) (point-max)) | |
219 | (not (= 93 (char-before)))) | |
220 | (cond | |
221 | ;; Avoid clobbering: user:[one.path][another.path | |
222 | ((search-backward "[" (field-beginning) t 2)) | |
223 | ((search-backward "]" (field-beginning) t) | |
224 | (delete-char 1) | |
225 | (insert ".") | |
226 | (goto-char (point-max))) | |
227 | ((= ?. (char-before)) | |
228 | (delete-char -1))) | |
229 | (goto-char (point-max)) | |
230 | (let ((specs '(".." "-")) | |
231 | (pmax (point-max))) | |
232 | (while specs | |
233 | (let* ((up (car specs)) | |
234 | (len (length up)) | |
235 | (cut (- (point) len))) | |
236 | (when (and (< (1+ len) pmax) | |
237 | (= ?. (char-before cut)) | |
238 | (string= up (buffer-substring cut (point)))) | |
239 | (delete-char (- (1+ len))) | |
240 | (while (not (let ((c (char-before))) | |
241 | (or (= ?. c) (= 91 c)))) | |
242 | (delete-char -1)) | |
243 | (when (= ?. (char-before)) (delete-char -1)) | |
244 | (setq specs nil))) | |
245 | (setq specs (cdr specs))))) | |
246 | (insert "]")) | |
247 | ||
248 | (defun vms-magic-colon () | |
249 | "\ | |
250 | Insert a colon, but do other things first depending on context. | |
251 | During filename completion, when point is at the end of the line | |
252 | and the line contains a right square brace, remove all characters | |
253 | from the beginning of the line up to and including such brace. | |
254 | This enables one to type a new filespec without having to delete | |
255 | the old one." | |
256 | (interactive) | |
257 | (when (and minibuffer-completing-file-name | |
258 | (= (point) (point-max)) | |
259 | (search-backward "]" (field-beginning) t)) | |
260 | (delete-region (field-beginning) (1+ (point))) | |
261 | (goto-char (point-max))) | |
262 | (insert ":")) | |
263 | ||
264 | (let ((m minibuffer-local-completion-map)) | |
265 | (define-key m "]" 'vms-magic-right-square-brace) | |
266 | (define-key m "/" 'vms-magic-right-square-brace) | |
267 | (define-key m ":" 'vms-magic-colon)) | |
268 | ||
cbee283d | 269 | ;; arch-tag: c178494e-2c37-4d02-99b7-e47e615656cf |
d501f516 | 270 | ;;; vms-patch.el ends here |