comparison lisp/progmodes/sh-script.el @ 16552:fe3d32bca2c5

(sh-set-shell): Pass args no-query-flag and insert-flag to executable-set-magic. Don't call executable-set-magic if insert-flag is nil. (sh-mode): Always call sh-set-shell, but use insert-flag arg to control whether to call executable-set-magic. No need to set comment-start-skip directly here. (sh-mode): Parse the interpreter from the file text.
author Richard M. Stallman <rms@gnu.org>
date Sat, 09 Nov 1996 22:17:58 +0000
parents d5eeca7cdaf2
children 20dc495230a0
comparison
equal deleted inserted replaced
16551:588a76a5a840 16552:fe3d32bca2c5
620 skeleton-end-hook (lambda () 620 skeleton-end-hook (lambda ()
621 (or (eolp) (newline) (indent-relative))) 621 (or (eolp) (newline) (indent-relative)))
622 paragraph-start (concat page-delimiter "\\|$") 622 paragraph-start (concat page-delimiter "\\|$")
623 paragraph-separate paragraph-start 623 paragraph-separate paragraph-start
624 comment-start "# " 624 comment-start "# "
625 comment-start-skip "#+[\t ]*"
626 comint-dynamic-complete-functions sh-dynamic-complete-functions 625 comint-dynamic-complete-functions sh-dynamic-complete-functions
627 ;; we can't look if previous line ended with `\' 626 ;; we can't look if previous line ended with `\'
628 comint-prompt-regexp "^[ \t]*" 627 comint-prompt-regexp "^[ \t]*"
629 font-lock-defaults 628 font-lock-defaults
630 `((sh-font-lock-keywords 629 `((sh-font-lock-keywords
636 skeleton-pair-filter 'sh-quoted-p 635 skeleton-pair-filter 'sh-quoted-p
637 skeleton-further-elements '((< '(- (min sh-indentation 636 skeleton-further-elements '((< '(- (min sh-indentation
638 (current-column))))) 637 (current-column)))))
639 skeleton-filter 'sh-feature 638 skeleton-filter 'sh-feature
640 skeleton-newline-indent-rigidly t) 639 skeleton-newline-indent-rigidly t)
641 (save-excursion 640 ;; Parse or insert magic number for exec, and set all variables depending
642 ;; Parse or insert magic number for exec, and set all variables depending 641 ;; on the shell thus determined.
643 ;; on the shell thus determined. 642 (let ((interpreter
644 (goto-char (point-min)) 643 (save-excursion
645 (and (zerop (buffer-size)) 644 (goto-char (point-min))
646 (not buffer-read-only) 645 (if (looking-at "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)")
647 (sh-set-shell sh-shell-file))) 646 (buffer-substring (match-beginning 2)
647 (match-end 2)))))
648 elt)
649 (if interpreter
650 (sh-set-shell interpreter nil
651 (and (zerop (buffer-size))
652 (not buffer-read-only)))))
648 (run-hooks 'sh-mode-hook)) 653 (run-hooks 'sh-mode-hook))
649 ;;;###autoload 654 ;;;###autoload
650 (defalias 'shell-script-mode 'sh-mode) 655 (defalias 'shell-script-mode 'sh-mode)
651 656
652 657
689 (sh-font-lock-keywords-1 t)) 694 (sh-font-lock-keywords-1 t))
690 695
691 696
692 (defun sh-set-shell (shell &optional no-query-flag insert-flag) 697 (defun sh-set-shell (shell &optional no-query-flag insert-flag)
693 "Set this buffer's shell to SHELL (a string). 698 "Set this buffer's shell to SHELL (a string).
694 Makes this script executable via `executable-set-magic'. 699 Makes this script executable via `executable-set-magic', and sets up the
700 proper starting #!-line, if INSERT-FLAG is non-nil.
695 Calls the value of `sh-set-shell-hook' if set." 701 Calls the value of `sh-set-shell-hook' if set."
696 (interactive (list (completing-read "Name or path of shell: " 702 (interactive (list (completing-read "Name or path of shell: "
697 interpreter-mode-alist 703 interpreter-mode-alist
698 (lambda (x) (eq (cdr x) 'sh-mode))) 704 (lambda (x) (eq (cdr x) 'sh-mode)))
699 (eq executable-query 'function) 705 (eq executable-query 'function)
700 t)) 706 t))
701 (setq sh-shell (intern (file-name-nondirectory shell)) 707 (setq sh-shell (intern (file-name-nondirectory shell))
702 sh-shell (or (cdr (assq sh-shell sh-alias-alist)) 708 sh-shell (or (cdr (assq sh-shell sh-alias-alist))
703 sh-shell)) 709 sh-shell))
704 (setq sh-shell-file (executable-set-magic shell (sh-feature sh-shell-arg))) 710 (if insert-flag
711 (setq sh-shell-file
712 (executable-set-magic shell (sh-feature sh-shell-arg)
713 no-query-flag insert-flag)))
705 (setq require-final-newline (sh-feature sh-require-final-newline) 714 (setq require-final-newline (sh-feature sh-require-final-newline)
706 ;;; local-abbrev-table (sh-feature sh-abbrevs) 715 ;;; local-abbrev-table (sh-feature sh-abbrevs)
707 font-lock-keywords nil ; force resetting 716 font-lock-keywords nil ; force resetting
708 font-lock-syntax-table nil 717 font-lock-syntax-table nil
709 comment-start-skip "#+[\t ]*" 718 comment-start-skip "#+[\t ]*"