X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/322b7dab59b98b5d8625d2cd29e48f1ce605f769..54fe3b6ec0557941c5759523b36bfdec21003f77:/lisp/progmodes/executable.el diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el index d8133cb6b9..173bf85bb5 100644 --- a/lisp/progmodes/executable.el +++ b/lisp/progmodes/executable.el @@ -1,6 +1,6 @@ ;;; executable.el --- base functionality for executable interpreter scripts -*- byte-compile-dynamic: t -*- -;; Copyright (C) 1994-1996, 2000-2011 Free Software Foundation, Inc. +;; Copyright (C) 1994-1996, 2000-2016 Free Software Foundation, Inc. ;; Author: Daniel Pfeiffer ;; Keywords: languages, unix @@ -57,7 +57,7 @@ ;; This used to default to `other', but that doesn't seem to have any ;; significance. fx 2000-02-11. (defcustom executable-insert t ; 'other - "*Non-nil means offer to add a magic number to a file. + "Non-nil means offer to add a magic number to a file. This takes effect when you switch to certain major modes, including Shell-script mode (`sh-mode'). When you type \\[executable-set-magic], it always offers to add or @@ -70,7 +70,7 @@ update the magic number." (defcustom executable-query 'function - "*If non-nil, ask user before changing an existing magic number. + "If non-nil, ask user before changing an existing magic number. When this is `function', only ask when called non-interactively." :type '(choice (const :tag "Don't Ask" nil) (const :tag "Ask when non-interactive" function) @@ -79,19 +79,20 @@ When this is `function', only ask when called non-interactively." (defcustom executable-magicless-file-regexp "/[Mm]akefile$\\|/\\.\\(z?profile\\|bash_profile\\|z?login\\|bash_login\\|z?logout\\|bash_logout\\|.+shrc\\|esrc\\|rcrc\\|[kz]shenv\\)$" - "*On files with this kind of name no magic is inserted or changed." + "On files with this kind of name no magic is inserted or changed." :type 'regexp :group 'executable) -(defcustom executable-prefix "#! " - "*Interpreter magic number prefix inserted when there was no magic number." +(defcustom executable-prefix "#!" + "Interpreter magic number prefix inserted when there was no magic number." + :version "24.3" ; "#! " -> "#!" :type 'string :group 'executable) (defcustom executable-chmod 73 - "*After saving, if the file is not executable, set this mode. + "After saving, if the file is not executable, set this mode. This mode passed to `set-file-modes' is taken absolutely when negative, or relative to the files existing modes. Do nothing if this is nil. Typical values are 73 (+x) or -493 (rwxr-xr-x)." @@ -103,15 +104,17 @@ Typical values are 73 (+x) or -493 (rwxr-xr-x)." (defvar executable-command nil) (defcustom executable-self-display "tail" - "*Command you use with argument `+2' to make text files self-display. + "Command you use with argument `-n+2' to make text files self-display. Note that the like of `more' doesn't work too well under Emacs \\[shell]." :type 'string :group 'executable) +(make-obsolete-variable 'executable-self-display nil "25.1" 'set) + (defvar executable-font-lock-keywords '(("\\`#!.*/\\([^ \t\n]+\\)" 1 font-lock-keyword-face t)) - "*Rules for highlighting executable scripts' magic number. + "Rules for highlighting executable scripts' magic number. This can be included in `font-lock-keywords' by modes that call `executable'.") @@ -237,8 +240,9 @@ executable." (save-window-excursion ;; Make buffer visible before question. (switch-to-buffer (current-buffer)) - (y-or-n-p (concat "Replace magic number by `" - executable-prefix argument "'? ")))) + (y-or-n-p (format-message + "Replace magic number by `%s%s'? " + executable-prefix argument)))) (progn (replace-match argument t t nil 1) (message "Magic number changed to `%s'" @@ -250,14 +254,14 @@ executable." -;;;###autoload (defun executable-self-display () "Turn a text file into a self-displaying Un*x command. The magic number of such a command displays all lines but itself." + (declare (obsolete nil "25.1")) (interactive) (if (eq this-command 'executable-self-display) (setq this-command 'executable-set-magic)) - (executable-set-magic executable-self-display "+2")) + (executable-set-magic executable-self-display "-n+2")) ;;;###autoload (defun executable-make-buffer-file-executable-if-script-p () @@ -268,12 +272,15 @@ file modes." (save-restriction (widen) (string= "#!" (buffer-substring (point-min) (+ 2 (point-min))))) - (let* ((current-mode (file-modes (buffer-file-name))) - (add-mode (logand ?\111 (default-file-modes)))) - (or (/= (logand ?\111 current-mode) 0) - (zerop add-mode) - (set-file-modes (buffer-file-name) - (logior current-mode add-mode)))))) + ;; Eg file-modes can return nil (bug#9879). It should not, + ;; in this context, but we should handle it all the same. + (with-demoted-errors "Unable to make file executable: %s" + (let* ((current-mode (file-modes (buffer-file-name))) + (add-mode (logand ?\111 (default-file-modes)))) + (or (/= (logand ?\111 current-mode) 0) + (zerop add-mode) + (set-file-modes (buffer-file-name) + (logior current-mode add-mode))))))) (provide 'executable)