Commit 5789bd83 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(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.
parent 444465c8
...@@ -815,7 +815,7 @@ See `sh-feature'.") ...@@ -815,7 +815,7 @@ See `sh-feature'.")
:group 'sh-script :group 'sh-script
:version "22.1") :version "22.1")
(defvar sh-font-lock-keywords (defvar sh-font-lock-keywords-var
'((csh sh-append shell '((csh sh-append shell
("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1 ("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1
font-lock-variable-name-face)) font-lock-variable-name-face))
...@@ -838,7 +838,7 @@ See `sh-feature'.") ...@@ -838,7 +838,7 @@ See `sh-feature'.")
1 font-lock-negation-char-face)) 1 font-lock-negation-char-face))
;; The next entry is only used for defining the others ;; The next entry is only used for defining the others
(shell sh-append executable-font-lock-keywords (shell
;; Using font-lock-string-face here confuses sh-get-indent-info. ;; Using font-lock-string-face here confuses sh-get-indent-info.
("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline) ("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline)
("\\\\[^A-Za-z0-9]" 0 font-lock-string-face) ("\\\\[^A-Za-z0-9]" 0 font-lock-string-face)
...@@ -850,11 +850,11 @@ See `sh-feature'.") ...@@ -850,11 +850,11 @@ See `sh-feature'.")
("^\\(\\sw+\\):" 1 font-lock-variable-name-face))) ("^\\(\\sw+\\):" 1 font-lock-variable-name-face)))
"Default expressions to highlight in Shell Script modes. See `sh-feature'.") "Default expressions to highlight in Shell Script modes. See `sh-feature'.")
(defvar sh-font-lock-keywords-1 (defvar sh-font-lock-keywords-var-1
'((sh "[ \t]in\\>")) '((sh "[ \t]in\\>"))
"Subdued level highlighting for Shell Script modes.") "Subdued level highlighting for Shell Script modes.")
(defvar sh-font-lock-keywords-2 () (defvar sh-font-lock-keywords-var-2 ()
"Gaudy level highlighting for Shell Script modes.") "Gaudy level highlighting for Shell Script modes.")
;; These are used for the syntax table stuff (derived from cperl-mode). ;; 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,9 +1364,12 @@ with your script for an edit-interpret-debug cycle."
paragraph-start (concat page-delimiter "\\|$") paragraph-start (concat page-delimiter "\\|$")
paragraph-separate paragraph-start paragraph-separate paragraph-start
comment-start "# " comment-start "# "
comment-start-skip "#+[\t ]*"
local-abbrev-table sh-mode-abbrev-table
comint-dynamic-complete-functions sh-dynamic-complete-functions comint-dynamic-complete-functions sh-dynamic-complete-functions
;; we can't look if previous line ended with `\' ;; we can't look if previous line ended with `\'
comint-prompt-regexp "^[ \t]*" comint-prompt-regexp "^[ \t]*"
imenu-case-fold-search nil
font-lock-defaults font-lock-defaults
`((sh-font-lock-keywords `((sh-font-lock-keywords
sh-font-lock-keywords-1 sh-font-lock-keywords-2) sh-font-lock-keywords-1 sh-font-lock-keywords-2)
...@@ -1403,13 +1406,14 @@ with your script for an edit-interpret-debug cycle." ...@@ -1403,13 +1406,14 @@ with your script for an edit-interpret-debug cycle."
(defun sh-font-lock-keywords (&optional keywords) (defun sh-font-lock-keywords (&optional keywords)
"Function to get simple fontification based on `sh-font-lock-keywords'. "Function to get simple fontification based on `sh-font-lock-keywords'.
This adds rules for comments and assignments." This adds rules for comments and assignments."
(sh-feature sh-font-lock-keywords (sh-feature sh-font-lock-keywords-var
(when (stringp (sh-feature sh-assignment-regexp)) (when (stringp (sh-feature sh-assignment-regexp))
(lambda (list) (lambda (list)
`((,(sh-feature sh-assignment-regexp) `((,(sh-feature sh-assignment-regexp)
1 font-lock-variable-name-face) 1 font-lock-variable-name-face)
,@keywords ,@keywords
,@list))))) ,@list
,@executable-font-lock-keywords)))))
(defun sh-font-lock-keywords-1 (&optional builtins) (defun sh-font-lock-keywords-1 (&optional builtins)
"Function to get better fontification including keywords." "Function to get better fontification including keywords."
...@@ -1426,10 +1430,10 @@ This adds rules for comments and assignments." ...@@ -1426,10 +1430,10 @@ This adds rules for comments and assignments."
"\\>") "\\>")
(2 font-lock-keyword-face nil t) (2 font-lock-keyword-face nil t)
(6 font-lock-builtin-face)) (6 font-lock-builtin-face))
,@(sh-feature sh-font-lock-keywords-2))) ,@(sh-feature sh-font-lock-keywords-var-2)))
(,(concat keywords "\\)\\>") (,(concat keywords "\\)\\>")
2 font-lock-keyword-face) 2 font-lock-keyword-face)
,@(sh-feature sh-font-lock-keywords-1))))) ,@(sh-feature sh-font-lock-keywords-var-1)))))
(defun sh-font-lock-keywords-2 () (defun sh-font-lock-keywords-2 ()
"Function to get better fontification including keywords and builtins." "Function to get better fontification including keywords and builtins."
...@@ -1491,6 +1495,7 @@ This adds rules for comments and assignments." ...@@ -1491,6 +1495,7 @@ This adds rules for comments and assignments."
("case" sh-handle-this-rc-case sh-handle-prev-rc-case)))) ("case" sh-handle-this-rc-case sh-handle-prev-rc-case))))
(defun sh-set-shell (shell &optional no-query-flag insert-flag) (defun sh-set-shell (shell &optional no-query-flag insert-flag)
"Set this buffer's shell to SHELL (a string). "Set this buffer's shell to SHELL (a string).
When used interactively, insert the proper starting #!-line, When used interactively, insert the proper starting #!-line,
...@@ -1523,13 +1528,10 @@ Calls the value of `sh-set-shell-hook' if set." ...@@ -1523,13 +1528,10 @@ Calls the value of `sh-set-shell-hook' if set."
(if (eq tem t) (if (eq tem t)
(setq require-final-newline mode-require-final-newline))) (setq require-final-newline mode-require-final-newline)))
(setq (setq
comment-start-skip "#+[\t ]*"
local-abbrev-table sh-mode-abbrev-table
mode-line-process (format "[%s]" sh-shell) mode-line-process (format "[%s]" sh-shell)
sh-shell-variables nil sh-shell-variables nil
sh-shell-variables-initialized nil sh-shell-variables-initialized nil
imenu-generic-expression (sh-feature sh-imenu-generic-expression) imenu-generic-expression (sh-feature sh-imenu-generic-expression))
imenu-case-fold-search nil)
(make-local-variable 'sh-mode-syntax-table) (make-local-variable 'sh-mode-syntax-table)
(let ((tem (sh-feature sh-mode-syntax-table-input))) (let ((tem (sh-feature sh-mode-syntax-table-input)))
(setq sh-mode-syntax-table (setq sh-mode-syntax-table
...@@ -1557,10 +1559,13 @@ Calls the value of `sh-set-shell-hook' if set." ...@@ -1557,10 +1559,13 @@ Calls the value of `sh-set-shell-hook' if set."
(message "Indentation setup for shell type %s" sh-shell)) (message "Indentation setup for shell type %s" sh-shell))
(message "No indentation for this shell type.") (message "No indentation for this shell type.")
(setq indent-line-function 'sh-basic-indent-line)) (setq indent-line-function 'sh-basic-indent-line))
(when font-lock-mode
(setq font-lock-set-defaults nil)
(font-lock-set-defaults)
(font-lock-fontify-buffer))
(run-hooks 'sh-set-shell-hook)) (run-hooks 'sh-set-shell-hook))
(defun sh-feature (alist &optional function) (defun sh-feature (alist &optional function)
"Index ALIST by the current shell. "Index ALIST by the current shell.
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.
...@@ -1578,39 +1583,38 @@ Else indexing follows an inheritance logic which works in two ways: ...@@ -1578,39 +1583,38 @@ Else indexing follows an inheritance logic which works in two ways:
one shell to be derived from another shell. one shell to be derived from another shell.
The value thus determined is physically replaced into the alist. The value thus determined is physically replaced into the alist.
Optional FUNCTION is applied to the determined value and the result is cached If FUNCTION is non-nil, it is called with one argument,
in ALIST." the value thus obtained, and the result is used instead."
(or (if (consp alist) (or (if (consp alist)
;; Check for something that isn't a valid alist.
(let ((l alist)) (let ((l alist))
(while (and l (consp (car l))) (while (and l (consp (car l)))
(setq l (cdr l))) (setq l (cdr l)))
(if l alist))) (if l alist)))
(if function
(cdr (assoc (setq function (cons sh-shell function)) alist))) (let ((orig-sh-shell sh-shell))
(let ((sh-shell sh-shell) (let ((sh-shell sh-shell)
elt val) elt val)
(while (and sh-shell (while (and sh-shell
(not (setq elt (assq sh-shell alist)))) (not (setq elt (assq sh-shell alist))))
(setq sh-shell (cdr (assq sh-shell sh-ancestor-alist)))) (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist))))
;; If the shell is not known, treat it as sh. ;; If the shell is not known, treat it as sh.
(unless elt (unless elt
(setq elt (assq 'sh alist))) (setq elt (assq 'sh alist)))
(if (and (consp (setq val (cdr elt))) (setq val (cdr elt))
(memq (car val) '(sh-append sh-modify))) (if (and (consp val)
(setcdr elt (memq (car val) '(sh-append sh-modify)))
(setq val (setq val
(apply (car val) (apply (car val)
(let ((sh-shell (car (cdr val)))) ;; Refer to the value for a different shell,
(if (assq sh-shell alist) ;; as a kind of inheritance.
(sh-feature alist) (let ((sh-shell (car (cdr val))))
(eval sh-shell))) (sh-feature alist))
(cddr val))))) (cddr val))))
(if function (if function
(nconc alist (setq sh-shell orig-sh-shell
(list (cons function val (funcall function val)))
(setq sh-shell (car function) val))))
val (funcall (cdr function) val))))))
val)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment