annotate lisp/modes/executable.el @ 18:d95e72db5c07 r19-15b92

Import from CVS: tag r19-15b92
author cvs
date Mon, 13 Aug 2007 08:49:43 +0200
parents ac2d302a0011
children 8fc7fe29b841
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1 ;;; executable.el --- base functionality for executable interpreter scripts
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
3 ;; Copyright (C) 1994, 1995, 1996 by Free Software Foundation, Inc.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
4
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
5 ;; Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
6 ;; Keywords: languages, unix
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
7
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
9
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
13 ;; any later version.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
14
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
18 ;; General Public License for more details.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
19
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
24
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.34.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
26
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
27 ;;; Commentary:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
28
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
29 ;; executable.el is used by certain major modes to insert a suitable
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
30 ;; #! line at the beginning of the file, if the file does not already
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
31 ;; have one.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
32
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
33 ;; Unless it has a magic number, a Unix file with executable mode is passed to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
34 ;; a new instance of the running shell (or to a Bourne shell if a csh is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
35 ;; running and the file starts with `:'). Only a shell can start such a file,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
36 ;; exec() cannot, which is why it is important to have a magic number in every
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
37 ;; executable script. Such a magic number is made up by the characters `#!'
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
38 ;; the filename of an interpreter (in COFF, ELF or somesuch format) and one
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
39 ;; optional argument.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
40
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
41 ;; This library is for certain major modes like sh-, awk-, perl-, tcl- or
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
42 ;; makefile-mode to insert or update a suitable #! line at the beginning of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
43 ;; the file, if the file does not already have one and the file is not a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
44 ;; default file of that interpreter (like .profile or makefile). It also
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
45 ;; makes the file executable if it wasn't, as soon as it's saved.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
46
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
47 ;; It also allows debugging scripts, with an adaptation of compile, as far
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
48 ;; as interpreters give out meaningful error messages.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
49
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
50 ;; Modes that use this should nconc `executable-map' to the end of their own
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
51 ;; keymap and `executable-font-lock-keywords' to the end of their own font
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
52 ;; lock keywords. Their mode-setting commands should call
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
53 ;; `executable-set-magic'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
54
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
55 ;;; Code:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
56
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
57 (defvar executable-insert 'not-modified
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
58 "*What to do when newly found file has no or wrong magic number:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
59 nil do nothing
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
60 t insert or update magic number
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
61 other insert or update magic number, but mark as unmodified.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
62 When the insertion is marked as unmodified, you can save it with \\[write-file] RET.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
63 This variable is used when `executable-set-magic' is called as a function,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
64 e.g. when Emacs sets some Un*x interpreter script mode.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
65 With \\[executable-set-magic], this is always treated as if it were `t'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
66
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
67
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
68 (defvar executable-query 'function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
69 "*If non-`nil', ask user before inserting or changing magic number.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
70 When this is `function', only ask when called non-interactively.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
71
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
72
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
73 (defvar executable-magicless-file-regexp "/[Mm]akefile$\\|/\\.\\(z?profile\\|bash_profile\\|z?login\\|bash_login\\|z?logout\\|bash_logout\\|.+shrc\\|esrc\\|rcrc\\|[kz]shenv\\)$"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
74 "*On files with this kind of name no magic is inserted or changed.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
75
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
76
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
77 (defvar executable-prefix "#! "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
78 "*Interpreter magic number prefix inserted when there was no magic number.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
79
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
80
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
81
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
82 (defvar executable-chmod 73
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
83 "*After saving, if the file is not executable, set this mode.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
84 This mode passed to `set-file-modes' is taken absolutely when negative, or
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
85 relative to the files existing modes. Do nothing if this is nil.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
86 Typical values are 73 (+x) or -493 (rwxr-xr-x).")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
87
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
89 (defvar executable-command nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
90
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
91 (defvar executable-self-display "tail"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
92 "*Command you use with argument `+2' to make text files self-display.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
93 Note that the like of `more' doesn't work too well under Emacs \\[shell].")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
94
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
95
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
96 (defvar executable-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
97 '(("\\`#!.*/\\([^ \t\n]+\\)" 1 font-lock-keyword-face t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
98 "*Rules for highlighting executable scripts' magic number.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
99 This can be included in `font-lock-keywords' by modes that call `executable'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
100
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
101
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
102 (defvar executable-error-regexp-alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
103 '(;; /bin/xyz: syntax error at line 14: `(' unexpected
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
104 ;; /bin/xyz[5]: syntax error at line 8 : ``' unmatched
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
105 ("^\\(.*[^[/]\\)\\(\\[[0-9]+\\]\\)?: .* error .* line \\([0-9]+\\)" 1 3)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
106 ;; /bin/xyz[27]: ehco: not found
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
107 ("^\\(.*[^/]\\)\\[\\([0-9]+\\)\\]: .*: " 1 2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
108 ;; /bin/xyz: syntax error near unexpected token `)'
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
109 ;; /bin/xyz: /bin/xyz: line 2: `)'
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
110 ("^\\(.*[^/]\\): [^0-9\n]+\n\\1: \\1: line \\([0-9]+\\):" 1 2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
111 ;; /usr/bin/awk: syntax error at line 5 of file /bin/xyz
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
112 (" error .* line \\([0-9]+\\) of file \\(.+\\)$" 2 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
113 ;; /usr/bin/awk: calling undefined function toto
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
114 ;; input record number 3, file awktestdata
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
115 ;; source line 4 of file /bin/xyz
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
116 ("^[^ ].+\n\\( .+\n\\)* line \\([0-9]+\\) of file \\(.+\\)$" 3 2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
117 ;; makefile:1: *** target pattern contains no `%'. Stop.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
118 ("^\\(.+\\):\\([0-9]+\\): " 1 2))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
119 "Alist of regexps used to match script errors.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
120 See `compilation-error-regexp-alist'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
121
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
122 ;; The C function openp slightly modified would do the trick fine
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
123 (defun executable-find (command)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
124 "Search for COMMAND in exec-path and return the absolute file name.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
125 Return nil if COMMAND is not found anywhere in `exec-path'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
126 (let ((list exec-path)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
127 file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
128 (while list
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
129 (setq list (if (and (setq file (expand-file-name command (car list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
130 (file-executable-p file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
131 (not (file-directory-p file)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
132 nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
133 (setq file nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
134 (cdr list))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
135 file))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
136
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
137
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
138 (defun executable-chmod ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
139 "This gets called after saving a file to assure that it be executable.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
140 You can set the absolute or relative mode in variable `executable-chmod' for
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
141 non-executable files."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
142 (and executable-chmod
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
143 buffer-file-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
144 (or (file-executable-p buffer-file-name)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
145 (set-file-modes buffer-file-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
146 (if (< executable-chmod 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
147 (- executable-chmod)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
148 (logior executable-chmod
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
149 (file-modes buffer-file-name)))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
150
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
151
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
152 (defun executable-interpret (command)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
153 "Run script with user-specified args, and collect output in a buffer.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
154 While script runs asynchronously, you can use the \\[next-error] command
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
155 to find the next error."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
156 (interactive (list (read-string "Run script: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
157 (or executable-command
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
158 buffer-file-name))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
159 (require 'compile)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
160 (save-some-buffers (not compilation-ask-about-save))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
161 (make-local-variable 'executable-command)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
162 (compile-internal (setq executable-command command)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
163 "No more errors." "Interpretation"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
164 ;; Give it a simpler regexp to match.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
165 nil executable-error-regexp-alist))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
166
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
167
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
168
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
169 ;;;###autoload
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
170 (defun executable-set-magic (interpreter &optional argument
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
171 no-query-flag insert-flag)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
172 "Set this buffer's interpreter to INTERPRETER with optional ARGUMENT.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
173 The variables `executable-magicless-file-regexp', `executable-prefix',
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
174 `executable-insert', `executable-query' and `executable-chmod' control
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
175 when and how magic numbers are inserted or replaced and scripts made
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
176 executable."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
177 (interactive
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
178 (let* ((name (read-string "Name or file name of interpreter: "))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
179 (arg (read-string (format "Argument for %s: " name))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
180 (list name arg (eq executable-query 'function) t)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
181 (setq interpreter (if (file-name-absolute-p interpreter)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
182 interpreter
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
183 (or (executable-find interpreter)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
184 (error "Interpreter %s not recognized" interpreter)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
185 argument (concat interpreter
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
186 (and argument (string< "" argument) " ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
187 argument))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
188 (or buffer-read-only
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
189 (if buffer-file-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
190 (string-match executable-magicless-file-regexp
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
191 buffer-file-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
192 (not (or insert-flag executable-insert))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
193 (> (point-min) 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
194 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
195 (let ((point (point-marker))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
196 (buffer-modified-p (buffer-modified-p)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
197 (goto-char (point-min))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
198 (make-local-hook 'after-save-hook)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
199 (add-hook 'after-save-hook 'executable-chmod nil t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
200 (if (looking-at "#![ \t]*\\(.*\\)$")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
201 (and (goto-char (match-beginning 1))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
202 ;; If the line ends in a space,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
203 ;; don't offer to change it.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
204 (not (= (char-after (1- (match-end 1))) ?\ ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
205 (not (string= argument
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
206 (buffer-substring (point) (match-end 1))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
207 (if (or (not executable-query) no-query-flag
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
208 (save-window-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
209 ;; Make buffer visible before question.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
210 (switch-to-buffer (current-buffer))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
211 (y-or-n-p (concat "Replace magic number by `"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
212 executable-prefix argument "'? "))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
213 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
214 (replace-match argument t t nil 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
215 (message "Magic number changed to `%s'"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
216 (concat executable-prefix argument)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
217 (insert executable-prefix argument ?\n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
218 (message "Magic number changed to `%s'"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
219 (concat executable-prefix argument)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
220 ;;; (or insert-flag
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
221 ;;; (eq executable-insert t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
222 ;;; (set-buffer-modified-p buffer-modified-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
223 )))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
224 interpreter)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
225
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
226
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
227
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
228 ;;;###autoload
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
229 (defun executable-self-display ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
230 "Turn a text file into a self-displaying Un*x command.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
231 The magic number of such a command displays all lines but itself."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
232 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
233 (if (eq this-command 'executable-self-display)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
234 (setq this-command 'executable-set-magic))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
235 (executable-set-magic executable-self-display "+2"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
236
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
237
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
238
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
239 (provide 'executable)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
240
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
241 ;; executable.el ends here
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
242
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
243