New files.
[bpt/emacs.git] / lisp / vms-patch.el
CommitLineData
73e72da4 1;; -*- no-byte-compile: t -*-
55535639 2;;; vms-patch.el --- override parts of files.el for VMS
d501f516 3
c90f2757 4;; Copyright (C) 1986, 1992, 2001, 2002, 2003, 2004,
409cc4a3 5;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
eea8d4ef 6
e5167999 7;; Maintainer: FSF
6251ee24 8;; Keywords: vms
e5167999 9
a2535589
JA
10;; This file is part of GNU Emacs.
11
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
b4aa6026 14;; the Free Software Foundation; either version 3, or (at your option)
a2535589
JA
15;; any later version.
16
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.
21
22;; You should have received a copy of the GNU General Public License
b578f267 23;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
24;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25;; Boston, MA 02110-1301, USA.
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.
42FILENAME (sans directory) is used unchanged if that name is free;
43otherwise a string <2> or <3> or ... is appended to get an unused name."
44 (generate-new-buffer (downcase (file-name-nondirectory filename))))
45
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)
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
62;;; Auto save filesnames start with _$ and end with $.
63
64(defun make-auto-save-file-name ()
65 "Return file name to use for auto-saves of current buffer.
66657f27
RS
66This function does not consider `auto-save-visited-file-name';
67the caller should check that before calling this function.
68This is a separate function so that your `.emacs' file or the site's
69`site-init.el' can redefine it.
70See also `auto-save-file-name-p'."
a2535589
JA
71 (if buffer-file-name
72 (concat (file-name-directory buffer-file-name)
73 "_$"
74 (file-name-nondirectory buffer-file-name)
75 "$")
76 (expand-file-name (concat "_$_" (make-legal-file-name (buffer-name)) "$"))))
77
78(defun auto-save-file-name-p (filename)
66657f27 79 "Return t if FILENAME can be yielded by `make-auto-save-file-name'.
a2535589 80FILENAME should lack slashes.
66657f27
RS
81This is a separate function so that your `.emacs' file or the site's
82`site-init.el' can redefine it."
a2535589
JA
83 (string-match "^_\\$.*\\$" filename))
84
55badf85
RS
85;;;
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.
90;;;
a2535589
JA
91(defun vms-suspend-resume-hook ()
92 "When resuming suspended Emacs, check for file to be found.
93If the logical name `EMACS_FILE_NAME' is defined, `find-file' that file."
55badf85
RS
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")))
97 (if (not args)
98 (if file
99 (progn (find-file file)
027a4b6b 100 (if line (goto-line (string-to-number line)))))
55badf85
RS
101 (cd (file-name-directory file))
102 (vms-command-line-again))))
a2535589
JA
103
104(setq suspend-resume-hook 'vms-suspend-resume-hook)
105
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"))
110 nil)
111
112(setq suspend-hook 'vms-suspend-hook)
113
55badf85
RS
114;;;
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.
119;;;
120(defun vms-command-line-again ()
121 "Reprocess command line arguments. VMS specific.
122Command line arguments are initialized from the logical EMACS_COMMAND_ARGS
123which is defined by kepteditor.com. On VMS this allows attaching to a
124spawned 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"))
127 (beg 0)
128 (end 0)
129 (len (length args))
130 this-char)
131 (if args
132 (progn
133;;; replace non-printable stuff with spaces
134 (while (< beg (length args))
135 (if (or (> 33 (setq this-char (aref args beg)))
136 (< 127 this-char))
137 (aset args beg 32))
138 (setq beg (1+ 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)))
142 (setq beg 0)
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)))
147 (< 127 this-char))
148 (setq beg (1+ beg))))
149 (setq end (1+ beg))
150 (while (and (< end (length args))
151 (< 32 (setq this-char (aref args end)))
152 (> 127 this-char))
153 (setq end (1+ end)))
f1180544 154 (setq command-line-args (append
55badf85
RS
155 command-line-args
156 (list (substring args beg end))))
157 (setq beg (1+ end)))
158 (command-line)))))
159
a2535589
JA
160(defun vms-read-directory (dirname switches buffer)
161 (save-excursion
162 (set-buffer buffer)
163 (subprocess-command-to-buffer
164 (concat "DIRECTORY " switches " " dirname)
165 buffer)
166 (goto-char (point-min))
167 ;; Remove all the trailing blanks.
168 (while (search-forward " \n")
169 (forward-char -1)
170 (delete-horizontal-space))
171 (goto-char (point-min))))
172
173(setq dired-listing-switches
174 "/SIZE/DATE/OWNER/WIDTH=(FILENAME=32,SIZE=5)")
86581d96
JB
175
176(setq print-region-function
a44442ba 177 (lambda (start end command ign1 ign2 ign3 &rest switches)
86581d96
JB
178 (write-region start end "sys$login:delete-me.txt")
179 (send-command-to-subprocess
180 1
181 (concat command
6f680efb 182 " sys$login:delete-me.txt/name=\"GNUprintbuffer\" "
86581d96
JB
183 (mapconcat 'identity switches " "))
184 nil nil nil)))
d501f516 185
55badf85
RS
186;;;
187;;; Fuctions for using Emacs as a VMS Mail editor
188;;;
189(autoload 'vms-pmail-setup "vms-pmail"
190 "Set up file assuming use by VMS Mail utility.
191The buffer is put into text-mode, auto-save is turned off and the
192following bindings are established.
193
194\\[vms-pmail-save-and-exit] vms-pmail-save-and-exit
195\\[vms-pmail-abort] vms-pmail-abort
196
197All other Emacs commands are still available."
198 t)
199
214dd398
TTN
200;;;
201;;; Filename handling in the minibuffer
202;;;
203(defun vms-magic-right-square-brace ()
204 "\
205Insert a right square brace, but do other things first depending on context.
206During filename completion, when point is at the end of the line and the
207character before is not a right square brace, do one of three things before
208inserting the brace:
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.
212Additionally, if the preceding chars are right-square-brace followed by
213either \"-\" or \"..\", strip one level of directory hierarchy."
214 (interactive)
215 (when (and minibuffer-completing-file-name
216 (= (point) (point-max))
217 (not (= 93 (char-before))))
218 (cond
219 ;; Avoid clobbering: user:[one.path][another.path
220 ((search-backward "[" (field-beginning) t 2))
221 ((search-backward "]" (field-beginning) t)
222 (delete-char 1)
223 (insert ".")
224 (goto-char (point-max)))
225 ((= ?. (char-before))
226 (delete-char -1)))
227 (goto-char (point-max))
228 (let ((specs '(".." "-"))
229 (pmax (point-max)))
230 (while specs
231 (let* ((up (car specs))
232 (len (length up))
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))))
240 (delete-char -1))
241 (when (= ?. (char-before)) (delete-char -1))
242 (setq specs nil)))
243 (setq specs (cdr specs)))))
244 (insert "]"))
245
246(defun vms-magic-colon ()
247 "\
248Insert a colon, but do other things first depending on context.
249During filename completion, when point is at the end of the line
250and the line contains a right square brace, remove all characters
251from the beginning of the line up to and including such brace.
252This enables one to type a new filespec without having to delete
253the old one."
254 (interactive)
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)))
260 (insert ":"))
261
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))
266
ab5796a9 267;;; arch-tag: c178494e-2c37-4d02-99b7-e47e615656cf
d501f516 268;;; vms-patch.el ends here