1 ;; -*- no-byte-compile: t -*-
2 ;;; vms-patch.el --- override parts of files.el for VMS
4 ;; Copyright (C) 1986, 1992, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
31 (defvar print-region-function
)
33 (setq auto-mode-alist
(cons '(("\\.com\\'" . dcl-mode
)) auto-mode-alist
))
35 ;;; Functions that need redefinition
37 ;;; VMS file names are upper case, but buffer names are more
38 ;;; convenient in lower case.
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
))))
46 ;;; Given a string FN, return a similar name which is a legal VMS filename.
47 ;;; This is used to avoid invalid auto save file names.
48 (defun make-legal-file-name (fn)
49 (setq fn
(copy-sequence fn
))
50 (let ((dot nil
) (indx 0) (len (length fn
)) chr
)
52 (setq chr
(aref fn indx
))
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))))
59 (setq indx
(1+ indx
))))
62 ;;; Auto save filesnames start with _$ and end with $.
64 (defun make-auto-save-file-name ()
65 "Return file name to use for auto-saves of current buffer.
66 This function does not consider `auto-save-visited-file-name';
67 the caller should check that before calling this function.
68 This is a separate function so that your `.emacs' file or the site's
69 `site-init.el' can redefine it.
70 See also `auto-save-file-name-p'."
72 (concat (file-name-directory buffer-file-name
)
74 (file-name-nondirectory buffer-file-name
)
76 (expand-file-name (concat "_$_" (make-legal-file-name (buffer-name)) "$"))))
78 (defun auto-save-file-name-p (filename)
79 "Return t if FILENAME can be yielded by `make-auto-save-file-name'.
80 FILENAME should lack slashes.
81 This is a separate function so that your `.emacs' file or the site's
82 `site-init.el' can redefine it."
83 (string-match "^_\\$.*\\$" filename
))
86 ;;; This goes along with kepteditor.com which defines these logicals
87 ;;; If EMACS_COMMAND_ARGS is defined, it supersedes EMACS_FILE_NAME,
88 ;;; which is probably set up incorrectly anyway.
89 ;;; The function command-line-again is a kludge, but it does the job.
91 (defun vms-suspend-resume-hook ()
92 "When resuming suspended Emacs, check for file to be found.
93 If the logical name `EMACS_FILE_NAME' is defined, `find-file' that file."
94 (let ((file (vms-system-info "LOGICAL" "EMACS_FILE_NAME"))
95 (args (vms-system-info "LOGICAL" "EMACS_COMMAND_ARGS"))
96 (line (vms-system-info "LOGICAL" "EMACS_FILE_LINE")))
99 (progn (find-file file
)
100 (if line
(goto-line (string-to-number line
)))))
101 (cd (file-name-directory file
))
102 (vms-command-line-again))))
104 (setq suspend-resume-hook
'vms-suspend-resume-hook
)
106 (defun vms-suspend-hook ()
107 "Don't allow suspending if logical name `DONT_SUSPEND_EMACS' is defined."
108 (if (vms-system-info "LOGICAL" "DONT_SUSPEND_EMACS")
109 (error "Can't suspend this emacs"))
112 (setq suspend-hook
'vms-suspend-hook
)
115 ;;; A kludge that allows reprocessing of the command line. This is mostly
116 ;;; to allow a spawned VMS mail process to do something reasonable when
117 ;;; used in conjunction with the modifications to sysdep.c that allow
118 ;;; Emacs to attach to a "foster" parent.
120 (defun vms-command-line-again ()
121 "Reprocess command line arguments. VMS specific.
122 Command line arguments are initialized from the logical EMACS_COMMAND_ARGS
123 which is defined by kepteditor.com. On VMS this allows attaching to a
124 spawned Emacs and doing things like \"emacs -l myfile.el -f doit\""
125 (let* ((args (downcase (vms-system-info "LOGICAL" "EMACS_COMMAND_ARGS")))
126 (command-line-args (list "emacs"))
133 ;;; replace non-printable stuff with spaces
134 (while (< beg
(length args
))
135 (if (or (> 33 (setq this-char
(aref args beg
)))
139 (setq beg
(1- (length args
)))
140 (while (= 32 (aref args beg
)) (setq beg
(1- beg
)))
141 (setq args
(substring args
0 (1+ beg
)))
143 ;;; now start parsing args
144 (while (< beg
(length args
))
145 (while (and (< beg
(length args
))
146 (or (> 33 (setq this-char
(aref args beg
)))
148 (setq beg
(1+ beg
))))
150 (while (and (< end
(length args
))
151 (< 32 (setq this-char
(aref args end
)))
154 (setq command-line-args
(append
156 (list (substring args beg end
))))
160 (defun vms-read-directory (dirname switches buffer
)
163 (subprocess-command-to-buffer
164 (concat "DIRECTORY " switches
" " dirname
)
166 (goto-char (point-min))
167 ;; Remove all the trailing blanks.
168 (while (search-forward " \n")
170 (delete-horizontal-space))
171 (goto-char (point-min))))
173 (setq dired-listing-switches
174 "/SIZE/DATE/OWNER/WIDTH=(FILENAME=32,SIZE=5)")
176 (setq print-region-function
177 (lambda (start end command ign1 ign2 ign3
&rest switches
)
178 (write-region start end
"sys$login:delete-me.txt")
179 (send-command-to-subprocess
182 " sys$login:delete-me.txt/name=\"GNUprintbuffer\" "
183 (mapconcat 'identity switches
" "))
187 ;;; Fuctions for using Emacs as a VMS Mail editor
189 (autoload 'vms-pmail-setup
"vms-pmail"
190 "Set up file assuming use by VMS Mail utility.
191 The buffer is put into text-mode, auto-save is turned off and the
192 following bindings are established.
194 \\[vms-pmail-save-and-exit] vms-pmail-save-and-exit
195 \\[vms-pmail-abort] vms-pmail-abort
197 All other Emacs commands are still available."
201 ;;; Filename handling in the minibuffer
203 (defun vms-magic-right-square-brace ()
205 Insert a right square brace, but do other things first depending on context.
206 During filename completion, when point is at the end of the line and the
207 character before is not a right square brace, do one of three things before
209 - If there are already two left square braces preceding, do nothing special.
210 - If there is a previous right-square-brace, convert it to dot.
211 - If the character before is dot, delete it.
212 Additionally, if the preceding chars are right-square-brace followed by
213 either \"-\" or \"..\", strip one level of directory hierarchy."
215 (when (and minibuffer-completing-file-name
216 (= (point) (point-max))
217 (not (= 93 (char-before))))
219 ;; Avoid clobbering: user:[one.path][another.path
220 ((search-backward "[" (field-beginning) t
2))
221 ((search-backward "]" (field-beginning) t
)
224 (goto-char (point-max)))
225 ((= ?.
(char-before))
227 (goto-char (point-max))
228 (let ((specs '(".." "-"))
231 (let* ((up (car specs
))
233 (cut (- (point) len
)))
234 (when (and (< (1+ len
) pmax
)
235 (= ?.
(char-before cut
))
236 (string= up
(buffer-substring cut
(point))))
237 (delete-char (- (1+ len
)))
238 (while (not (let ((c (char-before)))
239 (or (= ?. c
) (= 91 c
))))
241 (when (= ?.
(char-before)) (delete-char -
1))
243 (setq specs
(cdr specs
)))))
246 (defun vms-magic-colon ()
248 Insert a colon, but do other things first depending on context.
249 During filename completion, when point is at the end of the line
250 and the line contains a right square brace, remove all characters
251 from the beginning of the line up to and including such brace.
252 This enables one to type a new filespec without having to delete
255 (when (and minibuffer-completing-file-name
256 (= (point) (point-max))
257 (search-backward "]" (field-beginning) t
))
258 (delete-region (field-beginning) (1+ (point)))
259 (goto-char (point-max)))
262 (let ((m minibuffer-local-completion-map
))
263 (define-key m
"]" 'vms-magic-right-square-brace
)
264 (define-key m
"/" 'vms-magic-right-square-brace
)
265 (define-key m
":" 'vms-magic-colon
))
267 ;;; arch-tag: c178494e-2c37-4d02-99b7-e47e615656cf
268 ;;; vms-patch.el ends here