comparison lisp/modes/sh-script.el @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents 4103f0995bd7
children 56c54cf7c5b6
comparison
equal deleted inserted replaced
25:383a494979f8 26:441bb1e64a06
46 ;; page 2: mode-command and utility functions 46 ;; page 2: mode-command and utility functions
47 ;; page 3: statement syntax-commands for various shells 47 ;; page 3: statement syntax-commands for various shells
48 ;; page 4: various other commands 48 ;; page 4: various other commands
49 49
50 (require 'executable) 50 (require 'executable)
51
52 ;;; interpreter-mode-alist is not compatible between Emacs and XEmacs.
53 ;;; So fake it.
54
55 (defvar sh-interpreter-mode-alist
56 '(("perl" . perl-mode)
57 ("perl5" . perl-mode)
58 ("wish" . tcl-mode)
59 ("wishx" . tcl-mode)
60 ("tcl" . tcl-mode)
61 ("tclsh" . tcl-mode)
62 ("awk" . awk-mode)
63 ("mawk" . awk-mode)
64 ("nawk" . awk-mode)
65 ("gawk" . awk-mode)
66 ("scm" . scheme-mode)
67 ("ash" . sh-mode)
68 ("bash" . sh-mode)
69 ("csh" . sh-mode)
70 ("dtksh" . sh-mode)
71 ("es" . sh-mode)
72 ("itcsh" . sh-mode)
73 ("jsh" . sh-mode)
74 ("ksh" . sh-mode)
75 ("oash" . sh-mode)
76 ("pdksh" . sh-mode)
77 ("rc" . sh-mode)
78 ("sh" . sh-mode)
79 ("sh5" . sh-mode)
80 ("tcsh" . sh-mode)
81 ("wksh" . sh-mode)
82 ("wsh" . sh-mode)
83 ("zsh" . sh-mode)
84 ("tail" . text-mode)
85 ("more" . text-mode)
86 ("less" . text-mode)
87 ("pg" . text-mode))
88 "Alist mapping interpreter names to major modes.
89 This alist applies to files whose first line starts with `#!'.
90 Each element looks like (INTERPRETER . MODE).
91 The car of each element is compared with
92 the name of the interpreter specified in the first line.
93 If it matches, mode MODE is selected.")
51 94
52 (defvar sh-mode-hook nil 95 (defvar sh-mode-hook nil
53 "*Hook run by `sh-mode'.") 96 "*Hook run by `sh-mode'.")
54 97
55 (defvar sh-set-shell-hook nil 98 (defvar sh-set-shell-hook nil
337 380
338 (defvar sh-here-document-word "EOF" 381 (defvar sh-here-document-word "EOF"
339 "Word to delimit here documents.") 382 "Word to delimit here documents.")
340 383
341 (defvar sh-test 384 (defvar sh-test
342 '((sh "[ ]" . 3) 385 '((sh "[ ]" . 2)
343 (ksh88 "[[ ]]" . 4)) 386 (ksh88 "[[ ]]" . 3))
344 "Initial input in Bourne if, while and until skeletons. See `sh-feature'.") 387 "Initial input in Bourne if, while and until skeletons. See `sh-feature'.")
345 388
346 389
347 (defvar sh-builtins 390 (defvar sh-builtins
348 '((bash eval sh-append posix 391 '((bash eval sh-append posix
676 (sh-set-shell sh-shell-file))) 719 (sh-set-shell sh-shell-file)))
677 (run-hooks 'sh-mode-hook)) 720 (run-hooks 'sh-mode-hook))
678 ;;;###autoload 721 ;;;###autoload
679 (defalias 'shell-script-mode 'sh-mode) 722 (defalias 'shell-script-mode 'sh-mode)
680 723
724 ;;; XEmacs
725 (put 'sh-mode 'font-lock-defaults
726 `((sh-font-lock-keywords
727 sh-font-lock-keywords-1
728 sh-font-lock-keywords-2)
729 ,sh-font-lock-keywords-only
730 nil
731 ((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w"))))
732
681 733
682 (defun sh-font-lock-keywords (&optional keywords) 734 (defun sh-font-lock-keywords (&optional keywords)
683 "Function to get simple fontification based on `sh-font-lock-keywords'. 735 "Function to get simple fontification based on `sh-font-lock-keywords'.
684 This adds rules for comments and assignments." 736 This adds rules for comments and assignments."
685 (sh-feature sh-font-lock-keywords 737 (sh-feature sh-font-lock-keywords
723 (defun sh-set-shell (shell &optional no-query-flag insert-flag) 775 (defun sh-set-shell (shell &optional no-query-flag insert-flag)
724 "Set this buffer's shell to SHELL (a string). 776 "Set this buffer's shell to SHELL (a string).
725 Makes this script executable via `executable-set-magic'. 777 Makes this script executable via `executable-set-magic'.
726 Calls the value of `sh-set-shell-hook' if set." 778 Calls the value of `sh-set-shell-hook' if set."
727 (interactive (list (completing-read "Name or path of shell: " 779 (interactive (list (completing-read "Name or path of shell: "
728 interpreter-mode-alist 780 ;; XEmacs change
781 sh-interpreter-mode-alist
729 (lambda (x) (eq (cdr x) 'sh-mode))) 782 (lambda (x) (eq (cdr x) 'sh-mode)))
730 (eq executable-query 'function) 783 (eq executable-query 'function)
731 t)) 784 t))
732 (setq sh-shell (intern (file-name-nondirectory shell)) 785 (setq sh-shell (intern (file-name-nondirectory shell))
733 sh-shell (or (cdr (assq sh-shell sh-alias-alist)) 786 sh-shell (or (cdr (assq sh-shell sh-alias-alist))
734 sh-shell)) 787 sh-shell))
735 (setq sh-shell-file (executable-set-magic shell (sh-feature sh-shell-arg))) 788 (setq sh-shell-file (executable-set-magic shell (sh-feature sh-shell-arg)))
736 (setq require-final-newline (sh-feature sh-require-final-newline) 789 (setq require-final-newline (sh-feature sh-require-final-newline)
737 ;;; local-abbrev-table (sh-feature sh-abbrevs) 790 ;;; local-abbrev-table (sh-feature sh-abbrevs)
738 font-lock-keywords nil ; force resetting 791 font-lock-defaults-computed nil
739 font-lock-syntax-table nil 792 ;; Next two lines kill XEmacs
793 ;font-lock-keywords nil ; force resetting
794 ;font-lock-syntax-table nil
740 comment-start-skip (concat (sh-feature sh-comment-prefix) "#+[\t ]*") 795 comment-start-skip (concat (sh-feature sh-comment-prefix) "#+[\t ]*")
741 mode-line-process (format "[%s]" sh-shell) 796 mode-line-process (format "[%s]" sh-shell)
742 sh-shell-variables nil 797 sh-shell-variables nil
743 sh-shell-variables-initialized nil 798 sh-shell-variables-initialized nil
744 shell (sh-feature sh-variables)) 799 shell (sh-feature sh-variables))
746 (while shell 801 (while shell
747 (sh-remember-variable (car shell)) 802 (sh-remember-variable (car shell))
748 (setq shell (cdr shell))) 803 (setq shell (cdr shell)))
749 (and (boundp 'font-lock-mode) 804 (and (boundp 'font-lock-mode)
750 font-lock-mode 805 font-lock-mode
806 ;; Gnu Emacs, doesn't work
751 (font-lock-mode (font-lock-mode 0))) 807 (font-lock-mode (font-lock-mode 0)))
808 ;; (font-lock-fontify-buffer))
752 (run-hooks 'sh-set-shell-hook)) 809 (run-hooks 'sh-set-shell-hook))
753 810
754 811
755 812
756 (defun sh-feature (list &optional function) 813 (defun sh-feature (list &optional function)