Mercurial > hg > xemacs-beta
comparison lisp/modes/sh-script.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 56c54cf7c5b6 |
children | 0d2f883870bc |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
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.") | |
94 | |
95 (defvar sh-mode-hook nil | |
96 "*Hook run by `sh-mode'.") | |
97 | |
98 (defvar sh-set-shell-hook nil | |
99 "*Hook run by `sh-set-shell'.") | |
100 | 51 |
101 (defvar sh-ancestor-alist | 52 (defvar sh-ancestor-alist |
102 '((ash . sh) | 53 '((ash . sh) |
103 (bash . jsh) | 54 (bash . jsh) |
104 (dtksh . ksh) | 55 (dtksh . ksh) |
380 | 331 |
381 (defvar sh-here-document-word "EOF" | 332 (defvar sh-here-document-word "EOF" |
382 "Word to delimit here documents.") | 333 "Word to delimit here documents.") |
383 | 334 |
384 (defvar sh-test | 335 (defvar sh-test |
385 '((sh "[ ]" . 2) | 336 '((sh "[ ]" . 3) |
386 (ksh88 "[[ ]]" . 3)) | 337 (ksh88 "[[ ]]" . 4)) |
387 "Initial input in Bourne if, while and until skeletons. See `sh-feature'.") | 338 "Initial input in Bourne if, while and until skeletons. See `sh-feature'.") |
388 | 339 |
389 | 340 |
390 (defvar sh-builtins | 341 (defvar sh-builtins |
391 '((bash eval sh-append posix | 342 '((bash eval sh-append posix |
719 (sh-set-shell sh-shell-file))) | 670 (sh-set-shell sh-shell-file))) |
720 (run-hooks 'sh-mode-hook)) | 671 (run-hooks 'sh-mode-hook)) |
721 ;;;###autoload | 672 ;;;###autoload |
722 (defalias 'shell-script-mode 'sh-mode) | 673 (defalias 'shell-script-mode 'sh-mode) |
723 | 674 |
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 | |
733 | 675 |
734 (defun sh-font-lock-keywords (&optional keywords) | 676 (defun sh-font-lock-keywords (&optional keywords) |
735 "Function to get simple fontification based on `sh-font-lock-keywords'. | 677 "Function to get simple fontification based on `sh-font-lock-keywords'. |
736 This adds rules for comments and assignments." | 678 This adds rules for comments and assignments." |
737 (sh-feature sh-font-lock-keywords | 679 (sh-feature sh-font-lock-keywords |
775 (defun sh-set-shell (shell &optional no-query-flag insert-flag) | 717 (defun sh-set-shell (shell &optional no-query-flag insert-flag) |
776 "Set this buffer's shell to SHELL (a string). | 718 "Set this buffer's shell to SHELL (a string). |
777 Makes this script executable via `executable-set-magic'. | 719 Makes this script executable via `executable-set-magic'. |
778 Calls the value of `sh-set-shell-hook' if set." | 720 Calls the value of `sh-set-shell-hook' if set." |
779 (interactive (list (completing-read "Name or path of shell: " | 721 (interactive (list (completing-read "Name or path of shell: " |
780 ;; XEmacs change | 722 interpreter-mode-alist |
781 sh-interpreter-mode-alist | |
782 (lambda (x) (eq (cdr x) 'sh-mode))) | 723 (lambda (x) (eq (cdr x) 'sh-mode))) |
783 (eq executable-query 'function) | 724 (eq executable-query 'function) |
784 t)) | 725 t)) |
785 (setq sh-shell (intern (file-name-nondirectory shell)) | 726 (setq sh-shell (intern (file-name-nondirectory shell)) |
786 sh-shell (or (cdr (assq sh-shell sh-alias-alist)) | 727 sh-shell (or (cdr (assq sh-shell sh-alias-alist)) |
787 sh-shell)) | 728 sh-shell)) |
788 (setq sh-shell-file (executable-set-magic shell (sh-feature sh-shell-arg))) | 729 (setq sh-shell-file (executable-set-magic shell (sh-feature sh-shell-arg))) |
789 (setq require-final-newline (sh-feature sh-require-final-newline) | 730 (setq require-final-newline (sh-feature sh-require-final-newline) |
790 ;;; local-abbrev-table (sh-feature sh-abbrevs) | 731 ;;; local-abbrev-table (sh-feature sh-abbrevs) |
791 font-lock-defaults-computed nil | 732 font-lock-keywords nil ; force resetting |
792 ;; Next two lines kill XEmacs | 733 font-lock-syntax-table nil |
793 ;font-lock-keywords nil ; force resetting | |
794 ;font-lock-syntax-table nil | |
795 comment-start-skip (concat (sh-feature sh-comment-prefix) "#+[\t ]*") | 734 comment-start-skip (concat (sh-feature sh-comment-prefix) "#+[\t ]*") |
796 mode-line-process (format "[%s]" sh-shell) | 735 mode-line-process (format "[%s]" sh-shell) |
797 sh-shell-variables nil | 736 sh-shell-variables nil |
798 sh-shell-variables-initialized nil | 737 sh-shell-variables-initialized nil |
799 shell (sh-feature sh-variables)) | 738 shell (sh-feature sh-variables)) |
801 (while shell | 740 (while shell |
802 (sh-remember-variable (car shell)) | 741 (sh-remember-variable (car shell)) |
803 (setq shell (cdr shell))) | 742 (setq shell (cdr shell))) |
804 (and (boundp 'font-lock-mode) | 743 (and (boundp 'font-lock-mode) |
805 font-lock-mode | 744 font-lock-mode |
806 ;; Gnu Emacs, doesn't work | |
807 (font-lock-mode (font-lock-mode 0))) | 745 (font-lock-mode (font-lock-mode 0))) |
808 ;; (font-lock-fontify-buffer)) | |
809 (run-hooks 'sh-set-shell-hook)) | 746 (run-hooks 'sh-set-shell-hook)) |
810 | 747 |
811 | 748 |
812 | 749 |
813 (defun sh-feature (list &optional function) | 750 (defun sh-feature (list &optional function) |
924 "Indent as far as preceding non-empty line, then by steps of `sh-indentation'. | 861 "Indent as far as preceding non-empty line, then by steps of `sh-indentation'. |
925 Lines containing only comments are considered empty." | 862 Lines containing only comments are considered empty." |
926 (interactive) | 863 (interactive) |
927 (let ((previous (save-excursion | 864 (let ((previous (save-excursion |
928 (while (and (not (bobp)) | 865 (while (and (not (bobp)) |
929 (not (eq (point-min) (point-at-bol))) | |
930 (progn | 866 (progn |
931 (forward-line -1) | 867 (forward-line -1) |
932 (back-to-indentation) | 868 (back-to-indentation) |
933 (or (eolp) | 869 (or (eolp) |
934 (eq (following-char) ?#))))) | 870 (eq (following-char) ?#))))) |