diff options
| author | Richard M. Stallman | 2005-08-15 02:01:38 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-08-15 02:01:38 +0000 |
| commit | 5789bd837d0ab7bec1ac69ca0de2fceed258d8db (patch) | |
| tree | 1ec98479e5cd5e9701a05d374a705f24ff2a7d9c | |
| parent | 444465c803c67e9b833291dbc381d9fe63ebd317 (diff) | |
| download | emacs-5789bd837d0ab7bec1ac69ca0de2fceed258d8db.tar.gz emacs-5789bd837d0ab7bec1ac69ca0de2fceed258d8db.zip | |
(sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
In the `shell' entry, don't try to refer to executable-font-lock-keywords.
(sh-font-lock-keywords-var-1): Renamed from sh-font-lock-keywords-1.
(sh-font-lock-keywords-var-2): Renamed from sh-font-lock-keywords-2.
(sh-font-lock-keywords): Append executable-font-lock-keywords here.
(sh-mode): Set comment-start-skip, local-abbrev-table, imenu-case-fold-search.
(sh-set-shell): Don't set them here.
(sh-feature): Simplify. Get rid of the eval-a-variable feature.
Don't cache the results in the original alist; don't ever modify that alist.
| -rw-r--r-- | lisp/progmodes/sh-script.el | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 99e367a8633..ab23b31a963 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -815,7 +815,7 @@ See `sh-feature'.") | |||
| 815 | :group 'sh-script | 815 | :group 'sh-script |
| 816 | :version "22.1") | 816 | :version "22.1") |
| 817 | 817 | ||
| 818 | (defvar sh-font-lock-keywords | 818 | (defvar sh-font-lock-keywords-var |
| 819 | '((csh sh-append shell | 819 | '((csh sh-append shell |
| 820 | ("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1 | 820 | ("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1 |
| 821 | font-lock-variable-name-face)) | 821 | font-lock-variable-name-face)) |
| @@ -838,7 +838,7 @@ See `sh-feature'.") | |||
| 838 | 1 font-lock-negation-char-face)) | 838 | 1 font-lock-negation-char-face)) |
| 839 | 839 | ||
| 840 | ;; The next entry is only used for defining the others | 840 | ;; The next entry is only used for defining the others |
| 841 | (shell sh-append executable-font-lock-keywords | 841 | (shell |
| 842 | ;; Using font-lock-string-face here confuses sh-get-indent-info. | 842 | ;; Using font-lock-string-face here confuses sh-get-indent-info. |
| 843 | ("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline) | 843 | ("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline) |
| 844 | ("\\\\[^A-Za-z0-9]" 0 font-lock-string-face) | 844 | ("\\\\[^A-Za-z0-9]" 0 font-lock-string-face) |
| @@ -850,11 +850,11 @@ See `sh-feature'.") | |||
| 850 | ("^\\(\\sw+\\):" 1 font-lock-variable-name-face))) | 850 | ("^\\(\\sw+\\):" 1 font-lock-variable-name-face))) |
| 851 | "Default expressions to highlight in Shell Script modes. See `sh-feature'.") | 851 | "Default expressions to highlight in Shell Script modes. See `sh-feature'.") |
| 852 | 852 | ||
| 853 | (defvar sh-font-lock-keywords-1 | 853 | (defvar sh-font-lock-keywords-var-1 |
| 854 | '((sh "[ \t]in\\>")) | 854 | '((sh "[ \t]in\\>")) |
| 855 | "Subdued level highlighting for Shell Script modes.") | 855 | "Subdued level highlighting for Shell Script modes.") |
| 856 | 856 | ||
| 857 | (defvar sh-font-lock-keywords-2 () | 857 | (defvar sh-font-lock-keywords-var-2 () |
| 858 | "Gaudy level highlighting for Shell Script modes.") | 858 | "Gaudy level highlighting for Shell Script modes.") |
| 859 | 859 | ||
| 860 | ;; These are used for the syntax table stuff (derived from cperl-mode). | 860 | ;; These are used for the syntax table stuff (derived from cperl-mode). |
| @@ -1364,9 +1364,12 @@ with your script for an edit-interpret-debug cycle." | |||
| 1364 | paragraph-start (concat page-delimiter "\\|$") | 1364 | paragraph-start (concat page-delimiter "\\|$") |
| 1365 | paragraph-separate paragraph-start | 1365 | paragraph-separate paragraph-start |
| 1366 | comment-start "# " | 1366 | comment-start "# " |
| 1367 | comment-start-skip "#+[\t ]*" | ||
| 1368 | local-abbrev-table sh-mode-abbrev-table | ||
| 1367 | comint-dynamic-complete-functions sh-dynamic-complete-functions | 1369 | comint-dynamic-complete-functions sh-dynamic-complete-functions |
| 1368 | ;; we can't look if previous line ended with `\' | 1370 | ;; we can't look if previous line ended with `\' |
| 1369 | comint-prompt-regexp "^[ \t]*" | 1371 | comint-prompt-regexp "^[ \t]*" |
| 1372 | imenu-case-fold-search nil | ||
| 1370 | font-lock-defaults | 1373 | font-lock-defaults |
| 1371 | `((sh-font-lock-keywords | 1374 | `((sh-font-lock-keywords |
| 1372 | sh-font-lock-keywords-1 sh-font-lock-keywords-2) | 1375 | sh-font-lock-keywords-1 sh-font-lock-keywords-2) |
| @@ -1403,13 +1406,14 @@ with your script for an edit-interpret-debug cycle." | |||
| 1403 | (defun sh-font-lock-keywords (&optional keywords) | 1406 | (defun sh-font-lock-keywords (&optional keywords) |
| 1404 | "Function to get simple fontification based on `sh-font-lock-keywords'. | 1407 | "Function to get simple fontification based on `sh-font-lock-keywords'. |
| 1405 | This adds rules for comments and assignments." | 1408 | This adds rules for comments and assignments." |
| 1406 | (sh-feature sh-font-lock-keywords | 1409 | (sh-feature sh-font-lock-keywords-var |
| 1407 | (when (stringp (sh-feature sh-assignment-regexp)) | 1410 | (when (stringp (sh-feature sh-assignment-regexp)) |
| 1408 | (lambda (list) | 1411 | (lambda (list) |
| 1409 | `((,(sh-feature sh-assignment-regexp) | 1412 | `((,(sh-feature sh-assignment-regexp) |
| 1410 | 1 font-lock-variable-name-face) | 1413 | 1 font-lock-variable-name-face) |
| 1411 | ,@keywords | 1414 | ,@keywords |
| 1412 | ,@list))))) | 1415 | ,@list |
| 1416 | ,@executable-font-lock-keywords))))) | ||
| 1413 | 1417 | ||
| 1414 | (defun sh-font-lock-keywords-1 (&optional builtins) | 1418 | (defun sh-font-lock-keywords-1 (&optional builtins) |
| 1415 | "Function to get better fontification including keywords." | 1419 | "Function to get better fontification including keywords." |
| @@ -1426,10 +1430,10 @@ This adds rules for comments and assignments." | |||
| 1426 | "\\>") | 1430 | "\\>") |
| 1427 | (2 font-lock-keyword-face nil t) | 1431 | (2 font-lock-keyword-face nil t) |
| 1428 | (6 font-lock-builtin-face)) | 1432 | (6 font-lock-builtin-face)) |
| 1429 | ,@(sh-feature sh-font-lock-keywords-2))) | 1433 | ,@(sh-feature sh-font-lock-keywords-var-2))) |
| 1430 | (,(concat keywords "\\)\\>") | 1434 | (,(concat keywords "\\)\\>") |
| 1431 | 2 font-lock-keyword-face) | 1435 | 2 font-lock-keyword-face) |
| 1432 | ,@(sh-feature sh-font-lock-keywords-1))))) | 1436 | ,@(sh-feature sh-font-lock-keywords-var-1))))) |
| 1433 | 1437 | ||
| 1434 | (defun sh-font-lock-keywords-2 () | 1438 | (defun sh-font-lock-keywords-2 () |
| 1435 | "Function to get better fontification including keywords and builtins." | 1439 | "Function to get better fontification including keywords and builtins." |
| @@ -1491,6 +1495,7 @@ This adds rules for comments and assignments." | |||
| 1491 | ("case" sh-handle-this-rc-case sh-handle-prev-rc-case)))) | 1495 | ("case" sh-handle-this-rc-case sh-handle-prev-rc-case)))) |
| 1492 | 1496 | ||
| 1493 | 1497 | ||
| 1498 | |||
| 1494 | (defun sh-set-shell (shell &optional no-query-flag insert-flag) | 1499 | (defun sh-set-shell (shell &optional no-query-flag insert-flag) |
| 1495 | "Set this buffer's shell to SHELL (a string). | 1500 | "Set this buffer's shell to SHELL (a string). |
| 1496 | When used interactively, insert the proper starting #!-line, | 1501 | When used interactively, insert the proper starting #!-line, |
| @@ -1523,13 +1528,10 @@ Calls the value of `sh-set-shell-hook' if set." | |||
| 1523 | (if (eq tem t) | 1528 | (if (eq tem t) |
| 1524 | (setq require-final-newline mode-require-final-newline))) | 1529 | (setq require-final-newline mode-require-final-newline))) |
| 1525 | (setq | 1530 | (setq |
| 1526 | comment-start-skip "#+[\t ]*" | ||
| 1527 | local-abbrev-table sh-mode-abbrev-table | ||
| 1528 | mode-line-process (format "[%s]" sh-shell) | 1531 | mode-line-process (format "[%s]" sh-shell) |
| 1529 | sh-shell-variables nil | 1532 | sh-shell-variables nil |
| 1530 | sh-shell-variables-initialized nil | 1533 | sh-shell-variables-initialized nil |
| 1531 | imenu-generic-expression (sh-feature sh-imenu-generic-expression) | 1534 | imenu-generic-expression (sh-feature sh-imenu-generic-expression)) |
| 1532 | imenu-case-fold-search nil) | ||
| 1533 | (make-local-variable 'sh-mode-syntax-table) | 1535 | (make-local-variable 'sh-mode-syntax-table) |
| 1534 | (let ((tem (sh-feature sh-mode-syntax-table-input))) | 1536 | (let ((tem (sh-feature sh-mode-syntax-table-input))) |
| 1535 | (setq sh-mode-syntax-table | 1537 | (setq sh-mode-syntax-table |
| @@ -1557,10 +1559,13 @@ Calls the value of `sh-set-shell-hook' if set." | |||
| 1557 | (message "Indentation setup for shell type %s" sh-shell)) | 1559 | (message "Indentation setup for shell type %s" sh-shell)) |
| 1558 | (message "No indentation for this shell type.") | 1560 | (message "No indentation for this shell type.") |
| 1559 | (setq indent-line-function 'sh-basic-indent-line)) | 1561 | (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)) | ||
| 1560 | (run-hooks 'sh-set-shell-hook)) | 1566 | (run-hooks 'sh-set-shell-hook)) |
| 1561 | 1567 | ||
| 1562 | 1568 | ||
| 1563 | |||
| 1564 | (defun sh-feature (alist &optional function) | 1569 | (defun sh-feature (alist &optional function) |
| 1565 | "Index ALIST by the current shell. | 1570 | "Index ALIST by the current shell. |
| 1566 | If ALIST isn't a list where every element is a cons, it is returned as is. | 1571 | If ALIST isn't a list where every element is a cons, it is returned as is. |
| @@ -1578,39 +1583,38 @@ Else indexing follows an inheritance logic which works in two ways: | |||
| 1578 | one shell to be derived from another shell. | 1583 | one shell to be derived from another shell. |
| 1579 | The value thus determined is physically replaced into the alist. | 1584 | The value thus determined is physically replaced into the alist. |
| 1580 | 1585 | ||
| 1581 | Optional FUNCTION is applied to the determined value and the result is cached | 1586 | If FUNCTION is non-nil, it is called with one argument, |
| 1582 | in ALIST." | 1587 | the value thus obtained, and the result is used instead." |
| 1583 | (or (if (consp alist) | 1588 | (or (if (consp alist) |
| 1589 | ;; Check for something that isn't a valid alist. | ||
| 1584 | (let ((l alist)) | 1590 | (let ((l alist)) |
| 1585 | (while (and l (consp (car l))) | 1591 | (while (and l (consp (car l))) |
| 1586 | (setq l (cdr l))) | 1592 | (setq l (cdr l))) |
| 1587 | (if l alist))) | 1593 | (if l alist))) |
| 1588 | (if function | 1594 | |
| 1589 | (cdr (assoc (setq function (cons sh-shell function)) alist))) | 1595 | (let ((orig-sh-shell sh-shell)) |
| 1590 | (let ((sh-shell sh-shell) | 1596 | (let ((sh-shell sh-shell) |
| 1591 | elt val) | 1597 | elt val) |
| 1592 | (while (and sh-shell | 1598 | (while (and sh-shell |
| 1593 | (not (setq elt (assq sh-shell alist)))) | 1599 | (not (setq elt (assq sh-shell alist)))) |
| 1594 | (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist)))) | 1600 | (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist)))) |
| 1595 | ;; If the shell is not known, treat it as sh. | 1601 | ;; If the shell is not known, treat it as sh. |
| 1596 | (unless elt | 1602 | (unless elt |
| 1597 | (setq elt (assq 'sh alist))) | 1603 | (setq elt (assq 'sh alist))) |
| 1598 | (if (and (consp (setq val (cdr elt))) | 1604 | (setq val (cdr elt)) |
| 1599 | (memq (car val) '(sh-append sh-modify))) | 1605 | (if (and (consp val) |
| 1600 | (setcdr elt | 1606 | (memq (car val) '(sh-append sh-modify))) |
| 1601 | (setq val | 1607 | (setq val |
| 1602 | (apply (car val) | 1608 | (apply (car val) |
| 1603 | (let ((sh-shell (car (cdr val)))) | 1609 | ;; Refer to the value for a different shell, |
| 1604 | (if (assq sh-shell alist) | 1610 | ;; as a kind of inheritance. |
| 1605 | (sh-feature alist) | 1611 | (let ((sh-shell (car (cdr val)))) |
| 1606 | (eval sh-shell))) | 1612 | (sh-feature alist)) |
| 1607 | (cddr val))))) | 1613 | (cddr val)))) |
| 1608 | (if function | 1614 | (if function |
| 1609 | (nconc alist | 1615 | (setq sh-shell orig-sh-shell |
| 1610 | (list (cons function | 1616 | val (funcall function val))) |
| 1611 | (setq sh-shell (car function) | 1617 | val)))) |
| 1612 | val (funcall (cdr function) val)))))) | ||
| 1613 | val))) | ||
| 1614 | 1618 | ||
| 1615 | 1619 | ||
| 1616 | 1620 | ||