annotate lisp/modes/executable.el @ 120:cca96a509cfe r20-1b12

Import from CVS: tag r20-1b12
author cvs
date Mon, 13 Aug 2007 09:25:29 +0200
parents 0d2f883870bc
children
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
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
57
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
58 (defgroup executable nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
59 "Base functionality for executable interpreter scripts"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
60 :group 'processes)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
61
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
62
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
63 (defcustom executable-insert 'other
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
64 "*What to do when newly found file has no or wrong magic number:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
65 nil do nothing
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
66 t insert or update magic number
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
67 other insert or update magic number, but mark as unmodified.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
68 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
69 This variable is used when `executable-set-magic' is called as a function,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
70 e.g. when Emacs sets some Un*x interpreter script mode.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
71 With \\[executable-set-magic], this is always treated as if it were `t'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
72 :type '(choice (const :tag "off" nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
73 (const :tag "on" t)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
74 symbol)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
75 :group 'executable)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
76
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
77
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
78 (defcustom executable-query 'function
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
79 "*If non-`nil', ask user before inserting or changing magic number.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
80 When this is `function', only ask when called non-interactively."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
81 :type '(choice (const :tag "Don't Ask" nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
82 (const :tag "Ask" t)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
83 (const :tag "Ask when non-interactive" function))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
84 :group 'executable)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
85
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
86
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
87 (defcustom executable-magicless-file-regexp "/[Mm]akefile$\\|/\\.\\(z?profile\\|bash_profile\\|z?login\\|bash_login\\|z?logout\\|bash_logout\\|.+shrc\\|esrc\\|rcrc\\|[kz]shenv\\)$"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
88 "*On files with this kind of name no magic is inserted or changed."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
89 :type 'regexp
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
90 :group 'executable)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
91
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
92
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
93 (defcustom executable-prefix "#! "
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
94 "*Interpreter magic number prefix inserted when there was no magic number."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
95 :type 'string
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
96 :group 'executable)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
97
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
98
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
99
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
100 (defcustom executable-chmod 73
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
101 "*After saving, if the file is not executable, set this mode.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
102 This mode passed to `set-file-modes' is taken absolutely when negative, or
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
103 relative to the files existing modes. Do nothing if this is nil.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
104 Typical values are 73 (+x) or -493 (rwxr-xr-x)."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
105 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
106 :group 'executable)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
107
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
108
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
109 (defvar executable-command nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
110
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
111 (defcustom executable-self-display "tail"
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
112 "*Command you use with argument `+2' to make text files self-display.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
113 Note that the like of `more' doesn't work too well under Emacs \\[shell]."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
114 :type 'string
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 98
diff changeset
115 :group 'executable)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
116
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
117
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
118 (defvar executable-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
119 '(("\\`#!.*/\\([^ \t\n]+\\)" 1 font-lock-keyword-face t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
120 "*Rules for highlighting executable scripts' magic number.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
121 This can be included in `font-lock-keywords' by modes that call `executable'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
122
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
123
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
124 (defvar executable-error-regexp-alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
125 '(;; /bin/xyz: syntax error at line 14: `(' unexpected
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
126 ;; /bin/xyz[5]: syntax error at line 8 : ``' unmatched
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
127 ("^\\(.*[^[/]\\)\\(\\[[0-9]+\\]\\)?: .* error .* line \\([0-9]+\\)" 1 3)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
128 ;; /bin/xyz[27]: ehco: not found
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
129 ("^\\(.*[^/]\\)\\[\\([0-9]+\\)\\]: .*: " 1 2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
130 ;; /bin/xyz: syntax error near unexpected token `)'
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
131 ;; /bin/xyz: /bin/xyz: line 2: `)'
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
132 ("^\\(.*[^/]\\): [^0-9\n]+\n\\1: \\1: line \\([0-9]+\\):" 1 2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
133 ;; /usr/bin/awk: syntax error at line 5 of file /bin/xyz
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
134 (" error .* line \\([0-9]+\\) of file \\(.+\\)$" 2 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
135 ;; /usr/bin/awk: calling undefined function toto
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
136 ;; input record number 3, file awktestdata
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
137 ;; source line 4 of file /bin/xyz
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
138 ("^[^ ].+\n\\( .+\n\\)* line \\([0-9]+\\) of file \\(.+\\)$" 3 2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
139 ;; makefile:1: *** target pattern contains no `%'. Stop.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
140 ("^\\(.+\\):\\([0-9]+\\): " 1 2))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
141 "Alist of regexps used to match script errors.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
142 See `compilation-error-regexp-alist'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
143
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
144 ;; The C function openp slightly modified would do the trick fine
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
145 (defun executable-find (command)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
146 "Search for COMMAND in exec-path and return the absolute file name.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
147 Return nil if COMMAND is not found anywhere in `exec-path'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
148 (let ((list exec-path)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
149 file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
150 (while list
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
151 (setq list (if (and (setq file (expand-file-name command (car list)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
152 (file-executable-p file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
153 (not (file-directory-p file)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
154 nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
155 (setq file nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
156 (cdr list))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
157 file))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
158
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
159
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
160 (defun executable-chmod ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
161 "This gets called after saving a file to assure that it be executable.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
162 You can set the absolute or relative mode in variable `executable-chmod' for
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
163 non-executable files."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
164 (and executable-chmod
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
165 buffer-file-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
166 (or (file-executable-p buffer-file-name)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
167 (set-file-modes buffer-file-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
168 (if (< executable-chmod 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
169 (- executable-chmod)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
170 (logior executable-chmod
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
171 (file-modes buffer-file-name)))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
172
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
173
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
174 (defun executable-interpret (command)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
175 "Run script with user-specified args, and collect output in a buffer.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
176 While script runs asynchronously, you can use the \\[next-error] command
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
177 to find the next error."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
178 (interactive (list (read-string "Run script: "
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
179 (or executable-command
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
180 buffer-file-name))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
181 (require 'compile)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
182 (save-some-buffers (not compilation-ask-about-save))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
183 (make-local-variable 'executable-command)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
184 (compile-internal (setq executable-command command)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
185 "No more errors." "Interpretation"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
186 ;; Give it a simpler regexp to match.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
187 nil executable-error-regexp-alist))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
188
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
189
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
190
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
191 ;;;###autoload
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
192 (defun executable-set-magic (interpreter &optional argument
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
193 no-query-flag insert-flag)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
194 "Set this buffer's interpreter to INTERPRETER with optional ARGUMENT.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
195 The variables `executable-magicless-file-regexp', `executable-prefix',
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
196 `executable-insert', `executable-query' and `executable-chmod' control
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
197 when and how magic numbers are inserted or replaced and scripts made
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
198 executable."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
199 (interactive
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
200 (let* ((name (read-string "Name or file name of interpreter: "))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
201 (arg (read-string (format "Argument for %s: " name))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
202 (list name arg (eq executable-query 'function) t)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
203 (setq interpreter (if (file-name-absolute-p interpreter)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
204 interpreter
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
205 (or (executable-find interpreter)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
206 (error "Interpreter %s not recognized" interpreter)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
207 argument (concat interpreter
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
208 (and argument (string< "" argument) " ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
209 argument))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
210 (or buffer-read-only
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
211 (if buffer-file-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
212 (string-match executable-magicless-file-regexp
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
213 buffer-file-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
214 (not (or insert-flag executable-insert))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
215 (> (point-min) 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
216 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
217 (let ((point (point-marker))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
218 (buffer-modified-p (buffer-modified-p)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
219 (goto-char (point-min))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
220 (make-local-hook 'after-save-hook)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
221 (add-hook 'after-save-hook 'executable-chmod nil t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
222 (if (looking-at "#![ \t]*\\(.*\\)$")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
223 (and (goto-char (match-beginning 1))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
224 ;; If the line ends in a space,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
225 ;; don't offer to change it.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
226 (not (= (char-after (1- (match-end 1))) ?\ ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
227 (not (string= argument
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
228 (buffer-substring (point) (match-end 1))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
229 (if (or (not executable-query) no-query-flag
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
230 (save-window-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
231 ;; Make buffer visible before question.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
232 (switch-to-buffer (current-buffer))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
233 (y-or-n-p (concat "Replace magic number by `"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
234 executable-prefix argument "'? "))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
235 (progn
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
236 (replace-match (concat executable-prefix argument)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
237 t t nil 1)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
238 (message "Magic number changed to `%s'"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
239 (concat executable-prefix argument)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
240 (insert executable-prefix argument ?\n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
241 (message "Magic number changed to `%s'"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
242 (concat executable-prefix argument)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
243 ;;; (or insert-flag
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
244 ;;; (eq executable-insert t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
245 ;;; (set-buffer-modified-p buffer-modified-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
246 )))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
247 interpreter)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
248
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
249
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
250
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
251 ;;;###autoload
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
252 (defun executable-self-display ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
253 "Turn a text file into a self-displaying Un*x command.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
254 The magic number of such a command displays all lines but itself."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
255 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
256 (if (eq this-command 'executable-self-display)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
257 (setq this-command 'executable-set-magic))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
258 (executable-set-magic executable-self-display "+2"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
259
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
260
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
261
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
262 (provide 'executable)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
263
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
264 ;; executable.el ends here
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
265
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
266