/[emacs]/emacs/lisp/progmodes/sh-script.el
ViewVC logotype

Diff of /emacs/lisp/progmodes/sh-script.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.161 by monnier, Wed Jul 13 04:55:41 2005 UTC revision 1.162 by rms, Mon Aug 15 02:01:38 2005 UTC
# Line 815  See `sh-feature'.") Line 815  See `sh-feature'.")
815    :group 'sh-script    :group 'sh-script
816    :version "22.1")    :version "22.1")
817    
818  (defvar sh-font-lock-keywords  (defvar sh-font-lock-keywords-var
819    '((csh sh-append shell    '((csh sh-append shell
820           ("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1           ("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1
821            font-lock-variable-name-face))            font-lock-variable-name-face))
# Line 838  See `sh-feature'.") Line 838  See `sh-feature'.")
838           1 font-lock-negation-char-face))           1 font-lock-negation-char-face))
839    
840      ;; The next entry is only used for defining the others      ;; The next entry is only used for defining the others
841      (shell sh-append executable-font-lock-keywords      (shell
842             ;; Using font-lock-string-face here confuses sh-get-indent-info.             ;; Using font-lock-string-face here confuses sh-get-indent-info.
843             ("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline)             ("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline)
844             ("\\\\[^A-Za-z0-9]" 0 font-lock-string-face)             ("\\\\[^A-Za-z0-9]" 0 font-lock-string-face)
# Line 850  See `sh-feature'.") Line 850  See `sh-feature'.")
850            ("^\\(\\sw+\\):"  1 font-lock-variable-name-face)))            ("^\\(\\sw+\\):"  1 font-lock-variable-name-face)))
851    "Default expressions to highlight in Shell Script modes.  See `sh-feature'.")    "Default expressions to highlight in Shell Script modes.  See `sh-feature'.")
852    
853  (defvar sh-font-lock-keywords-1  (defvar sh-font-lock-keywords-var-1
854    '((sh "[ \t]in\\>"))    '((sh "[ \t]in\\>"))
855    "Subdued level highlighting for Shell Script modes.")    "Subdued level highlighting for Shell Script modes.")
856    
857  (defvar sh-font-lock-keywords-2 ()  (defvar sh-font-lock-keywords-var-2 ()
858    "Gaudy level highlighting for Shell Script modes.")    "Gaudy level highlighting for Shell Script modes.")
859    
860  ;; These are used for the syntax table stuff (derived from cperl-mode).  ;; These are used for the syntax table stuff (derived from cperl-mode).
# Line 1364  with your script for an edit-interpret-d Line 1364  with your script for an edit-interpret-d
1364          paragraph-start (concat page-delimiter "\\|$")          paragraph-start (concat page-delimiter "\\|$")
1365          paragraph-separate paragraph-start          paragraph-separate paragraph-start
1366          comment-start "# "          comment-start "# "
1367            comment-start-skip "#+[\t ]*"
1368            local-abbrev-table sh-mode-abbrev-table
1369          comint-dynamic-complete-functions sh-dynamic-complete-functions          comint-dynamic-complete-functions sh-dynamic-complete-functions
1370          ;; we can't look if previous line ended with `\'          ;; we can't look if previous line ended with `\'
1371          comint-prompt-regexp "^[ \t]*"          comint-prompt-regexp "^[ \t]*"
1372            imenu-case-fold-search nil
1373          font-lock-defaults          font-lock-defaults
1374          `((sh-font-lock-keywords          `((sh-font-lock-keywords
1375             sh-font-lock-keywords-1 sh-font-lock-keywords-2)             sh-font-lock-keywords-1 sh-font-lock-keywords-2)
# Line 1403  with your script for an edit-interpret-d Line 1406  with your script for an edit-interpret-d
1406  (defun sh-font-lock-keywords (&optional keywords)  (defun sh-font-lock-keywords (&optional keywords)
1407    "Function to get simple fontification based on `sh-font-lock-keywords'.    "Function to get simple fontification based on `sh-font-lock-keywords'.
1408  This adds rules for comments and assignments."  This adds rules for comments and assignments."
1409    (sh-feature sh-font-lock-keywords    (sh-feature sh-font-lock-keywords-var
1410                (when (stringp (sh-feature sh-assignment-regexp))                (when (stringp (sh-feature sh-assignment-regexp))
1411                  (lambda (list)                  (lambda (list)
1412                    `((,(sh-feature sh-assignment-regexp)                    `((,(sh-feature sh-assignment-regexp)
1413                       1 font-lock-variable-name-face)                       1 font-lock-variable-name-face)
1414                      ,@keywords                      ,@keywords
1415                      ,@list)))))                      ,@list
1416                        ,@executable-font-lock-keywords)))))
1417    
1418  (defun sh-font-lock-keywords-1 (&optional builtins)  (defun sh-font-lock-keywords-1 (&optional builtins)
1419    "Function to get better fontification including keywords."    "Function to get better fontification including keywords."
# Line 1426  This adds rules for comments and assignm Line 1430  This adds rules for comments and assignm
1430                           "\\>")                           "\\>")
1431                  (2 font-lock-keyword-face nil t)                  (2 font-lock-keyword-face nil t)
1432                  (6 font-lock-builtin-face))                  (6 font-lock-builtin-face))
1433                 ,@(sh-feature sh-font-lock-keywords-2)))                 ,@(sh-feature sh-font-lock-keywords-var-2)))
1434           (,(concat keywords "\\)\\>")           (,(concat keywords "\\)\\>")
1435            2 font-lock-keyword-face)            2 font-lock-keyword-face)
1436           ,@(sh-feature sh-font-lock-keywords-1)))))           ,@(sh-feature sh-font-lock-keywords-var-1)))))
1437    
1438  (defun sh-font-lock-keywords-2 ()  (defun sh-font-lock-keywords-2 ()
1439    "Function to get better fontification including keywords and builtins."    "Function to get better fontification including keywords and builtins."
# Line 1491  This adds rules for comments and assignm Line 1495  This adds rules for comments and assignm
1495       ("case" sh-handle-this-rc-case sh-handle-prev-rc-case))))       ("case" sh-handle-this-rc-case sh-handle-prev-rc-case))))
1496    
1497    
1498    
1499  (defun sh-set-shell (shell &optional no-query-flag insert-flag)  (defun sh-set-shell (shell &optional no-query-flag insert-flag)
1500    "Set this buffer's shell to SHELL (a string).    "Set this buffer's shell to SHELL (a string).
1501  When used interactively, insert the proper starting #!-line,  When used interactively, insert the proper starting #!-line,
# Line 1523  Calls the value of `sh-set-shell-hook' i Line 1528  Calls the value of `sh-set-shell-hook' i
1528      (if (eq tem t)      (if (eq tem t)
1529          (setq require-final-newline mode-require-final-newline)))          (setq require-final-newline mode-require-final-newline)))
1530    (setq    (setq
         comment-start-skip "#+[\t ]*"  
         local-abbrev-table sh-mode-abbrev-table  
1531          mode-line-process (format "[%s]" sh-shell)          mode-line-process (format "[%s]" sh-shell)
1532          sh-shell-variables nil          sh-shell-variables nil
1533          sh-shell-variables-initialized nil          sh-shell-variables-initialized nil
1534          imenu-generic-expression (sh-feature sh-imenu-generic-expression)          imenu-generic-expression (sh-feature sh-imenu-generic-expression))
         imenu-case-fold-search nil)  
1535    (make-local-variable 'sh-mode-syntax-table)    (make-local-variable 'sh-mode-syntax-table)
1536    (let ((tem (sh-feature sh-mode-syntax-table-input)))    (let ((tem (sh-feature sh-mode-syntax-table-input)))
1537      (setq sh-mode-syntax-table      (setq sh-mode-syntax-table
# Line 1557  Calls the value of `sh-set-shell-hook' i Line 1559  Calls the value of `sh-set-shell-hook' i
1559          (message "Indentation setup for shell type %s" sh-shell))          (message "Indentation setup for shell type %s" sh-shell))
1560      (message "No indentation for this shell type.")      (message "No indentation for this shell type.")
1561      (setq indent-line-function 'sh-basic-indent-line))      (setq indent-line-function 'sh-basic-indent-line))
1562      (when font-lock-mode
1563        (setq font-lock-set-defaults nil)
1564        (font-lock-set-defaults)
1565        (font-lock-fontify-buffer))
1566    (run-hooks 'sh-set-shell-hook))    (run-hooks 'sh-set-shell-hook))
1567    
1568    
   
1569  (defun sh-feature (alist &optional function)  (defun sh-feature (alist &optional function)
1570    "Index ALIST by the current shell.    "Index ALIST by the current shell.
1571  If ALIST isn't a list where every element is a cons, it is returned as is.  If ALIST isn't a list where every element is a cons, it is returned as is.
# Line 1578  Else indexing follows an inheritance log Line 1583  Else indexing follows an inheritance log
1583      one shell to be derived from another shell.      one shell to be derived from another shell.
1584      The value thus determined is physically replaced into the alist.      The value thus determined is physically replaced into the alist.
1585    
1586  Optional FUNCTION is applied to the determined value and the result is cached  If FUNCTION is non-nil, it is called with one argument,
1587  in ALIST."  the value thus obtained, and the result is used instead."
1588    (or (if (consp alist)    (or (if (consp alist)
1589              ;; Check for something that isn't a valid alist.
1590            (let ((l alist))            (let ((l alist))
1591              (while (and l (consp (car l)))              (while (and l (consp (car l)))
1592                (setq l (cdr l)))                (setq l (cdr l)))
1593              (if l alist)))              (if l alist)))
1594        (if function  
1595            (cdr (assoc (setq function (cons sh-shell function)) alist)))        (let ((orig-sh-shell sh-shell))
1596        (let ((sh-shell sh-shell)          (let ((sh-shell sh-shell)
1597              elt val)                elt val)
1598          (while (and sh-shell            (while (and sh-shell
1599                      (not (setq elt (assq sh-shell alist))))                        (not (setq elt (assq sh-shell alist))))
1600            (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist))))              (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist))))
1601          ;; If the shell is not known, treat it as sh.            ;; If the shell is not known, treat it as sh.
1602          (unless elt            (unless elt
1603            (setq elt (assq 'sh alist)))              (setq elt (assq 'sh alist)))
1604          (if (and (consp (setq val (cdr elt)))            (setq val (cdr elt))
1605                   (memq (car val) '(sh-append sh-modify)))            (if (and (consp val)
1606              (setcdr elt                     (memq (car val) '(sh-append sh-modify)))
1607                      (setq val                (setq val
1608                            (apply (car val)                      (apply (car val)
1609                                   (let ((sh-shell (car (cdr val))))                             ;; Refer to the value for a different shell,
1610                                     (if (assq sh-shell alist)                             ;; as a kind of inheritance.
1611                                         (sh-feature alist)                             (let ((sh-shell (car (cdr val))))
1612                                       (eval sh-shell)))                               (sh-feature alist))
1613                                   (cddr val)))))                             (cddr val))))
1614          (if function            (if function
1615              (nconc alist                (setq sh-shell orig-sh-shell
1616                     (list (cons function                      val (funcall function val)))
1617                                 (setq sh-shell (car function)            val))))
                                      val (funcall (cdr function) val))))))  
         val)))  
1618    
1619    
1620    

Legend:
Removed from v.1.161  
changed lines
  Added in v.1.162

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26