[5157] | 1 | ; Bash syntax highlighting |
---|
| 2 | |
---|
| 3 | (defvar bash-builtins ;; Unrecognized UNIX commands |
---|
| 4 | '("awk" "basename" "cat" "cp" "cut" "date" "diff" "dirname" "env" "find" |
---|
| 5 | "grep" "head" "ls" "make" "mkdir" "mv" "rm" "sed" "sort" "svn" "tail" "tee" |
---|
| 6 | "touch" "uniq" "xargs" )) |
---|
| 7 | |
---|
| 8 | (defvar bash-keywords ;; Bash keywords (consistency with 'return' command fontification) |
---|
| 9 | '("declare" "let" "local" "readonly" "typeset" "set" "unset" )) |
---|
| 10 | |
---|
| 11 | (defvar bash-functions ;; Sourced or declared fonctions |
---|
| 12 | '("fake_func" ;; |
---|
| 13 | "em" "ev" "ge" "heil" "mkcd" "ok" ;; Common |
---|
| 14 | "nemch" "nemde" "nemid" "nemtr" "nemst" ;; NEMO branchs |
---|
| 15 | "cmpcf" "if90" "gf90" ;; NEMO cmp |
---|
| 16 | "nemo_help" "nemo_cfg" ;; NEMO cfg |
---|
| 17 | "append_output_file" "appech_output_file" "super_grep" "check_args_count" ;; NEMO SETTE |
---|
| 18 | "set_namelist" "set_xio" "post_test_tidyup" )) ;; Id |
---|
| 19 | |
---|
| 20 | (defvar bash-font-lock ;; Be careful with order |
---|
| 21 | '(;; Variables |
---|
| 22 | ;;; GLOBALS variables|arrays |
---|
| 23 | ("\\(?:export +\\)?\\$?{?\\(#?[A-Z][A-Z_0-9]+\\)\\(?:\\[\\(?2:[@*]\\)\\]\\)?" |
---|
| 24 | (1 font-lock-constant-face ) (2 font-lock-constant-face nil t)) |
---|
| 25 | ;;; Locals arrays |
---|
| 26 | ("\\(?1:#?[a-z][a-z_0-9]+\\)\\[\\([@*]\\)?" |
---|
| 27 | (1 font-lock-variable-name-face) (2 font-lock-variable-name-face nil t)) |
---|
| 28 | ;;; Shell specials variables |
---|
| 29 | ("\\${?\\([#@?!_-]?[a-z]?[a-z_0-9]*\\)}?" 1 font-lock-variable-name-face) |
---|
| 30 | |
---|
| 31 | ;; Tests '[ ... ]' '[[ ... ]]' '(( ... ))' |
---|
| 32 | ("\\((\\{2\\}\\) \\(?:.*\\) \\()\\{2\\}\\)" |
---|
| 33 | (1 font-lock-builtin-face) (2 font-lock-builtin-face)) |
---|
| 34 | ("\\(\\[\\{1,2\\}\\) \\(?:[^]]+\\) \\(\\]\\{1,2\\}\\)" |
---|
| 35 | (1 font-lock-builtin-face) (2 font-lock-builtin-face)) |
---|
| 36 | |
---|
| 37 | ;; Operators ' ! ' ' != ' ' ~= ' ' && ' ' || ' |
---|
| 38 | (" \\!=? \\| ~= " 0 font-lock-negation-char-face) |
---|
| 39 | (" && \\| || " 0 font-lock-keyword-face ) |
---|
| 40 | |
---|
| 41 | ;; Compound commands |
---|
| 42 | ("\\\\$" 0 font-lock-warning-face) ; '\' |
---|
| 43 | ("\\(?:[^;]\\)\\(;\\) " 1 font-lock-keyword-face) ; '; ' |
---|
| 44 | ;;; Function |
---|
| 45 | ("^\\(?:function +\\)?\\(\\sw+\\)(?)? +\\({\\)" |
---|
| 46 | (1 font-lock-function-name-face) (2 font-lock-warning-face )) |
---|
| 47 | ("^}$" 0 font-lock-warning-face ) |
---|
| 48 | ;;; Commands block ' { ...; }' |
---|
| 49 | ("\\({\\) \\(?:[^}]*\\); +\\(}\\)?" (1 font-lock-warning-face) (2 font-lock-warning-face nil t)) |
---|
| 50 | ("\\(?:.*\\); +\\(}\\)$" 1 font-lock-warning-face ) |
---|
| 51 | ;;; Sub-shell '( ... )' |
---|
| 52 | ("\\((\\) \\(?:[^)]*\\) \\()\\)" (1 font-lock-warning-face) (2 font-lock-warning-face)) |
---|
| 53 | |
---|
| 54 | ;; 'case ... in ...) ...;; esac' |
---|
| 55 | ("\\()\\)\\(?:[^)]*\\)\\(;;\\)" (1 font-lock-keyword-face) (2 font-lock-keyword-face)) |
---|
| 56 | ("^[^(]*\\()\\)$" 1 font-lock-keyword-face) ; Regular syntax |
---|
| 57 | ("^\\s-+;;$" 0 font-lock-keyword-face) ; " "" |
---|
| 58 | ) |
---|
| 59 | ) |
---|
| 60 | |
---|
| 61 | ; Configuration loading |
---|
| 62 | (font-lock-add-keywords 'sh-mode `((,(regexp-opt bash-builtins 'words) 0 font-lock-builtin-face ))) |
---|
| 63 | (font-lock-add-keywords 'sh-mode `((,(regexp-opt bash-keywords 'words) 0 font-lock-keyword-face ))) |
---|
| 64 | (font-lock-add-keywords 'sh-mode `((,(regexp-opt bash-functions 'words) 0 font-lock-function-name-face))) |
---|
| 65 | (font-lock-add-keywords 'sh-mode bash-font-lock ) |
---|
| 66 | |
---|
| 67 | ; Highlighting example for font lock faces |
---|
| 68 | (font-lock-add-keywords 'sh-mode '( |
---|
| 69 | ("font-lock-warning-face" . font-lock-warning-face ) |
---|
| 70 | ("font-lock-function-name-face" . font-lock-function-name-face ) |
---|
| 71 | ("font-lock-variable-name-face" . font-lock-variable-name-face ) |
---|
| 72 | ("font-lock-keyword-face" . font-lock-keyword-face ) |
---|
| 73 | ("font-lock-comment-face" . font-lock-comment-face ) |
---|
| 74 | ("font-lock-comment-delimiter-face" . font-lock-comment-delimiter-face) |
---|
| 75 | ("font-lock-type-face" . font-lock-type-face ) |
---|
| 76 | ("font-lock-constant-face" . font-lock-constant-face ) |
---|
| 77 | ("font-lock-builtin-face" . font-lock-builtin-face ) |
---|
| 78 | ("font-lock-preprocessor-face" . font-lock-preprocessor-face ) |
---|
| 79 | ("font-lock-string-face" . font-lock-string-face ) |
---|
| 80 | ("font-lock-doc-face" . font-lock-doc-face ) |
---|
| 81 | ("font-lock-negation-char-face" . font-lock-negation-char-face ))) |
---|