comparison lisp/progmodes/executable.el @ 29526:64d6ad22bce7

Byte compile dynamic. (executable-insert): Change custom type. (executable-find): Add autoload cookie. (make-buffer-file-executable-if-script-p): New function from Noah Friedman.
author Dave Love <fx@gnu.org>
date Fri, 09 Jun 2000 09:38:58 +0000
parents 8d2bb5d1416a
children 2485d23636b2
comparison
equal deleted inserted replaced
29525:1b0629c98957 29526:64d6ad22bce7
1 ;;; executable.el --- base functionality for executable interpreter scripts 1 ;;; executable.el --- base functionality for executable interpreter scripts -*- byte-compile-dynamic: t -*-
2 2
3 ;; Copyright (C) 1994, 1995, 1996 by Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 1995, 1996, 2000 by Free Software Foundation, Inc.
4 4
5 ;; Author: Daniel Pfeiffer <occitan@esperanto.org> 5 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
6 ;; Keywords: languages, unix 6 ;; Keywords: languages, unix
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
54 54
55 (defgroup executable nil 55 (defgroup executable nil
56 "Base functionality for executable interpreter scripts" 56 "Base functionality for executable interpreter scripts"
57 :group 'processes) 57 :group 'processes)
58 58
59 (defcustom executable-insert 'other 59 ;; This used to default to `other', but that doesn't seem to have any
60 ;; significance. fx 2000-02-11.
61 (defcustom executable-insert t ; 'other
60 "*Non-nil means offer to add a magic number to a file. 62 "*Non-nil means offer to add a magic number to a file.
61 This takes effect when you switch to certain major modes, 63 This takes effect when you switch to certain major modes,
62 including Shell-script mode (`sh-mode'). 64 including Shell-script mode (`sh-mode').
63 When you type \\[executable-set-magic], it always offers to add or 65 When you type \\[executable-set-magic], it always offers to add or
64 update the magic number." 66 update the magic number."
65 :type '(choice (const :tag "off" nil) 67 ;;; :type '(choice (const :tag "off" nil)
66 (const :tag "on" t) 68 ;;; (const :tag "on" t)
67 symbol) 69 ;;; symbol)
70 :type 'boolean
68 :group 'executable) 71 :group 'executable)
69 72
70 73
71 (defcustom executable-query 'function 74 (defcustom executable-query 'function
72 "*If non-nil, ask user before changing an existing magic number. 75 "*If non-nil, ask user before changing an existing magic number.
101 104
102 (defvar executable-command nil) 105 (defvar executable-command nil)
103 106
104 (defcustom executable-self-display "tail" 107 (defcustom executable-self-display "tail"
105 "*Command you use with argument `+2' to make text files self-display. 108 "*Command you use with argument `+2' to make text files self-display.
106 Note that the like of `more' doesn't work too well under Emacs \\[shell]." 109 Note that the like of `more' doesn't work too well under Emacs \\[shell]."
107 :type 'string 110 :type 'string
108 :group 'executable) 111 :group 'executable)
109 112
110 113
111 (defvar executable-font-lock-keywords 114 (defvar executable-font-lock-keywords
137 ;; The C function openp slightly modified would do the trick fine 140 ;; The C function openp slightly modified would do the trick fine
138 (defvar executable-binary-suffixes 141 (defvar executable-binary-suffixes
139 (if (memq system-type '(ms-dos windows-nt)) 142 (if (memq system-type '(ms-dos windows-nt))
140 '(".exe" ".com" ".bat" ".cmd" ".btm" "") 143 '(".exe" ".com" ".bat" ".cmd" ".btm" "")
141 '(""))) 144 '("")))
145
146 ;;;###autoload
142 (defun executable-find (command) 147 (defun executable-find (command)
143 "Search for COMMAND in exec-path and return the absolute file name. 148 "Search for COMMAND in exec-path and return the absolute file name.
144 Return nil if COMMAND is not found anywhere in `exec-path'." 149 Return nil if COMMAND is not found anywhere in `exec-path'."
145 (let ((list exec-path) 150 (let ((list exec-path)
146 file) 151 file)
259 (interactive) 264 (interactive)
260 (if (eq this-command 'executable-self-display) 265 (if (eq this-command 'executable-self-display)
261 (setq this-command 'executable-set-magic)) 266 (setq this-command 'executable-set-magic))
262 (executable-set-magic executable-self-display "+2")) 267 (executable-set-magic executable-self-display "+2"))
263 268
264 269 ;;;###autoload
270 (defun make-buffer-file-executable-if-script-p ()
271 "Make file executable according to umask if not already executable.
272 If file already has any execute bits set at all, do not change existing
273 file modes."
274 (and (save-excursion
275 (save-restriction
276 (widen)
277 (goto-char (point-min))
278 (save-match-data
279 (looking-at "^#!"))))
280 (let* ((current-mode (file-modes (buffer-file-name)))
281 (add-mode (logand ?\111 (default-file-modes))))
282 (or (/= (logand ?\111 current-mode) 0)
283 (zerop add-mode)
284 (set-file-modes (buffer-file-name)
285 (logior current-mode add-mode))))))
265 286
266 (provide 'executable) 287 (provide 'executable)
267 288
268 ;; executable.el ends here 289 ;; executable.el ends here