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