bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: executable.el / sh-script.el problem?


From: Ehud Karni
Subject: Re: executable.el / sh-script.el problem?
Date: Mon, 28 Jan 2002 17:16:58 +0200

On Thu, 24 Jan 2002 01:00:41 -0700 (MST), Richard Stallman <rms@gnu.org> wrote:
> 
>     So I guess this is a feature request rather than a bug report, namely
>     that it be possible to locally customise my emacs in some way so that
>     insert-flag is non-nil even when I'm visiting a shell-script for the
>     first time.
> 
> You can do that by redefining functions.  It is not hard.
> 
> It would be a bad idea to try to add specific customization code for
> everything than any user wants to change.  There are too many of them.

I have this in my initialization files:

;; insert a skeleton for empty shell script 
(defun sh-ins-template ()
       (if (< (point-max) 3)
           (let ((pos))
               (goto-char (point-min))
               (insert "#! /bin/sh -ex\n"
                       "# Compile by: /bin/sh -ex $* \n"
                       "# --------------------------------------------------\n")
               (setq pos (point))
               (insert "\n\n\n\n\n\n"
                       "############################## "
                       (file-name-nondirectory
                           (or (buffer-file-name) "UnKnown"))
                       " ##############################\n")
               (goto-char pos)
               )))

(add-hook 'sh-mode-hook 'sh-ins-template)

;; ensure saving of script sets the the executable bit (x)
;; By Noah Friedman <friedman@splode.com>
;; Date: Sun, 11 Jul 1999 14:08:16 -0700 (PDT)
(defun make-buffer-file-executable-if-script-p ()
  "Make file executable according to umask if not already executable.
If file already has any execute bits set at all, do not change existing
file modes."
  (and (not (ange-ftp-get-hash-entry  (buffer-file-name) 
ange-ftp-inodes-hashtable))
       (save-excursion
         (save-restriction
           (widen)
           (goto-char (point-min))
           (save-match-data
             (looking-at "^#!"))))
       (let* ((current-mode (file-modes (buffer-file-name)))
              (add-mode (logand ?\111 (default-file-modes)))
              (new-mode (logior current-mode add-mode)))
         (or (/= (logand current-mode ?\111) 0)
             (= add-mode 0)
             (set-file-modes (buffer-file-name) new-mode)))))

(add-hook 'after-save-hook 'make-buffer-file-executable-if-script-p)

Ehud.


-- 
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 mailto:ehud@unix.simonwiesel.co.il          Better  Safe  Than  Sorry



reply via email to

[Prev in Thread] Current Thread [Next in Thread]