;;; ;;; script-executor.el: #! 行を自動補完する. ;;; ;;; [1998/10/16] OSHIRO Naoki. ML-elf の皆様の助言を受け作成. ;;; ;;; $Log:$ ;;; ;;; ;;; Usage: ~/.emacs に次のように書く. ;;; (autoload 'get-script-executor "script-executor" "Script Executor" t) ;;; (global-set-key "\e\#" 'get-script-executor) ;;; ;;; 必要に応じて script-executor-list を自前で設定する. ;;; ;;; 自動で 'chmod +x' してくれる次の EmacsLisp コードと組み合わせると快適. ;;; ;;; http://www-nagao.kuee.kyoto-u.ac.jp/member/tsuchiya/elisp/#chmod ;;; ;;; script-executor (defvar script-executor-list '(("perl") ("sh") ("csh") ("tclsh") ("wish"))) (defun which-exec (command) (let ((exec-path exec-path)) (catch 'loop (while exec-path (setq path (concat (car exec-path) "/" command)) (if (file-executable-p path) (throw 'loop path)) (setq exec-path (cdr exec-path))) (message (concat "Can't find specified interpreter : " command))))) (defun get-script-executor (&optional command) (interactive) (if (or (interactive-p) (not command)) (setq command (completing-read "Specify command shell: " script-executor-list))) (let ((path (concat "#!" (which-exec command)))) (if (interactive-p) (insert (concat path "\n\n")) path)) (normal-mode)) ;(defun add-auto-insert-script-executor (mode command) ; (add-to-list 'auto-insert-alist ; (list mode (get-script-executor command)))) ;(add-auto-insert-script-executor 'perl-mode "perl")