1 ;;; vms-patch.el --- override parts of files.el for VMS.
3 ;; Copyright (C) 1986, 1992 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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.
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.
26 ;;; Functions that need redefinition
28 ;;; VMS file names are upper case, but buffer names are more
29 ;;; convenient in lower case.
31 (defun create-file-buffer (filename)
32 "Create a suitably named buffer for visiting FILENAME, and return it.
33 FILENAME (sans directory) is used unchanged if that name is free;
34 otherwise a string <2> or <3> or ... is appended to get an unused name."
35 (generate-new-buffer (downcase (file-name-nondirectory filename
))))
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
)
43 (setq chr
(aref fn indx
))
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))))
50 (setq indx
(1+ indx
))))
53 ;;; Auto save filesnames start with _$ and end with $.
55 (defun make-auto-save-file-name ()
56 "Return file name to use for auto-saves of current buffer.
57 Does not consider auto-save-visited-file-name; that is checked
58 before calling this function.
59 This is a separate function so your .emacs file or site-init.el can redefine it.
60 See also auto-save-file-name-p."
62 (concat (file-name-directory buffer-file-name
)
64 (file-name-nondirectory buffer-file-name
)
66 (expand-file-name (concat "_$_" (make-legal-file-name (buffer-name)) "$"))))
68 (defun auto-save-file-name-p (filename)
69 "Return t if FILENAME can be yielded by make-auto-save-file-name.
70 FILENAME should lack slashes.
71 This is a separate function so your .emacs file or site-init.el can redefine it."
72 (string-match "^_\\$.*\\$" filename
))
75 ;;; This goes along with kepteditor.com which defines these logicals
76 ;;; If EMACS_COMMAND_ARGS is defined, it supersedes EMACS_FILE_NAME,
77 ;;; which is probably set up incorrectly anyway.
78 ;;; The function command-line-again is a kludge, but it does the job.
80 (defun vms-suspend-resume-hook ()
81 "When resuming suspended Emacs, check for file to be found.
82 If the logical name `EMACS_FILE_NAME' is defined, `find-file' that file."
83 (let ((file (vms-system-info "LOGICAL" "EMACS_FILE_NAME"))
84 (args (vms-system-info "LOGICAL" "EMACS_COMMAND_ARGS"))
85 (line (vms-system-info "LOGICAL" "EMACS_FILE_LINE")))
88 (progn (find-file file
)
89 (if line
(goto-line (string-to-int line
)))))
90 (cd (file-name-directory file
))
91 (vms-command-line-again))))
93 (setq suspend-resume-hook
'vms-suspend-resume-hook
)
95 (defun vms-suspend-hook ()
96 "Don't allow suspending if logical name `DONT_SUSPEND_EMACS' is defined."
97 (if (vms-system-info "LOGICAL" "DONT_SUSPEND_EMACS")
98 (error "Can't suspend this emacs"))
101 (setq suspend-hook
'vms-suspend-hook
)
104 ;;; A kludge that allows reprocessing of the command line. This is mostly
105 ;;; to allow a spawned VMS mail process to do something reasonable when
106 ;;; used in conjunction with the modifications to sysdep.c that allow
107 ;;; Emacs to attach to a "foster" parent.
109 (defun vms-command-line-again ()
110 "Reprocess command line arguments. VMS specific.
111 Command line arguments are initialized from the logical EMACS_COMMAND_ARGS
112 which is defined by kepteditor.com. On VMS this allows attaching to a
113 spawned Emacs and doing things like \"emacs -l myfile.el -f doit\""
114 (let* ((args (downcase (vms-system-info "LOGICAL" "EMACS_COMMAND_ARGS")))
115 (command-line-args (list "emacs"))
122 ;;; replace non-printable stuff with spaces
123 (while (< beg
(length args
))
124 (if (or (> 33 (setq this-char
(aref args beg
)))
128 (setq beg
(1- (length args
)))
129 (while (= 32 (aref args beg
)) (setq beg
(1- beg
)))
130 (setq args
(substring args
0 (1+ beg
)))
132 ;;; now start parsing args
133 (while (< beg
(length args
))
134 (while (and (< beg
(length args
))
135 (or (> 33 (setq this-char
(aref args beg
)))
137 (setq beg
(1+ beg
))))
139 (while (and (< end
(length args
))
140 (< 32 (setq this-char
(aref args end
)))
143 (setq command-line-args
(append
145 (list (substring args beg end
))))
149 (defun vms-read-directory (dirname switches buffer
)
152 (subprocess-command-to-buffer
153 (concat "DIRECTORY " switches
" " dirname
)
155 (goto-char (point-min))
156 ;; Remove all the trailing blanks.
157 (while (search-forward " \n")
159 (delete-horizontal-space))
160 (goto-char (point-min))))
162 (setq dired-listing-switches
163 "/SIZE/DATE/OWNER/WIDTH=(FILENAME=32,SIZE=5)")
165 (setq print-region-function
166 '(lambda (start end command ign1 ign2 ign3
&rest switches
)
167 (write-region start end
"sys$login:delete-me.txt")
168 (send-command-to-subprocess
171 " sys$login:delete-me.txt/name=\"GNUprintbuffer\" "
172 (mapconcat 'identity switches
" "))
176 ;;; Fuctions for using Emacs as a VMS Mail editor
178 (autoload 'vms-pmail-setup
"vms-pmail"
179 "Set up file assuming use by VMS Mail utility.
180 The buffer is put into text-mode, auto-save is turned off and the
181 following bindings are established.
183 \\[vms-pmail-save-and-exit] vms-pmail-save-and-exit
184 \\[vms-pmail-abort] vms-pmail-abort
186 All other Emacs commands are still available."
189 ;;; vms-patch.el ends here