diff options
| author | Yuan Fu | 2022-11-17 09:40:37 -0800 |
|---|---|---|
| committer | Yuan Fu | 2022-11-17 10:11:21 -0800 |
| commit | 28490cd65ba50ce4e1f411556e1faa36f1db84ec (patch) | |
| tree | 0a274950f9f8fa5deb4edb8d73ef705581b85d0b | |
| parent | d06127e5736b0564daf99a41c77c8c23d394e759 (diff) | |
| download | emacs-28490cd65ba50ce4e1f411556e1faa36f1db84ec.tar.gz emacs-28490cd65ba50ce4e1f411556e1faa36f1db84ec.zip | |
; Minor stylistic fix for previous change on sh-script.el
* lisp/progmodes/sh-script.el: Stylistic change.
| -rw-r--r-- | lisp/progmodes/sh-script.el | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index c6a828548da..54284ff284f 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -3210,7 +3210,7 @@ member of `flymake-diagnostic-functions'." | |||
| 3210 | (defvar sh-mode--treesit-operators | 3210 | (defvar sh-mode--treesit-operators |
| 3211 | '("|" "|&" "||" "&&" ">" ">>" "<" "<<" "<<-" "<<<" "==" "!=" ";" | 3211 | '("|" "|&" "||" "&&" ">" ">>" "<" "<<" "<<-" "<<<" "==" "!=" ";" |
| 3212 | ";;" ";&" ";;&") | 3212 | ";;" ";&" ";;&") |
| 3213 | "List of `sh-mode' operator to fontify") | 3213 | "A list of `sh-mode' operators to fontify.") |
| 3214 | 3214 | ||
| 3215 | (defvar sh-mode--treesit-keywords | 3215 | (defvar sh-mode--treesit-keywords |
| 3216 | '("case" "do" "done" "elif" "else" "esac" "export" "fi" "for" | 3216 | '("case" "do" "done" "elif" "else" "esac" "export" "fi" "for" |
| @@ -3218,15 +3218,15 @@ member of `flymake-diagnostic-functions'." | |||
| 3218 | "Minimal list of keywords that belong to tree-sitter-bash's grammar. | 3218 | "Minimal list of keywords that belong to tree-sitter-bash's grammar. |
| 3219 | 3219 | ||
| 3220 | Some reserved words are not recognize to keep the grammar | 3220 | Some reserved words are not recognize to keep the grammar |
| 3221 | simpler. Those are identified with regex-based filtered queries. | 3221 | simpler. Those are identified with regex-based filtered queries. |
| 3222 | 3222 | ||
| 3223 | See `sh-mode--treesit-other-keywords' and | 3223 | \(See `sh-mode--treesit-other-keywords' and |
| 3224 | `sh-mode--treesit-settings').") | 3224 | `sh-mode--treesit-settings').") |
| 3225 | 3225 | ||
| 3226 | (defun sh-mode--treesit-other-keywords () | 3226 | (defun sh-mode--treesit-other-keywords () |
| 3227 | "Returns a list `others' of key/reserved words to be fontified with | 3227 | "Return a list `others' of key/reserved words. |
| 3228 | regex-based queries as they are not part of tree-sitter-bash's | 3228 | These words are fontified with regex-based queries as they are |
| 3229 | grammar. | 3229 | not part of tree-sitter-bash's grammar. |
| 3230 | 3230 | ||
| 3231 | See `sh-mode--treesit-other-keywords' and | 3231 | See `sh-mode--treesit-other-keywords' and |
| 3232 | `sh-mode--treesit-settings')." | 3232 | `sh-mode--treesit-settings')." |
| @@ -3238,41 +3238,49 @@ See `sh-mode--treesit-other-keywords' and | |||
| 3238 | (if (not (member keyword minimal)) | 3238 | (if (not (member keyword minimal)) |
| 3239 | (setq others (cons keyword others)))))) | 3239 | (setq others (cons keyword others)))))) |
| 3240 | 3240 | ||
| 3241 | (defun sh-mode--treesit-fontify-decl-command (node override _start _end) | 3241 | (defun sh-mode--treesit-fontify-decl-command (node override start end &rest _) |
| 3242 | "Fontifies only the name of declaration_command nodes. | 3242 | "Fontifies only the name of declaration_command nodes. |
| 3243 | 3243 | ||
| 3244 | This is used instead of `font-lock-builtion-face' directly because | 3244 | NODE should be the first child of a declaration_command node. |
| 3245 | otherwise the whole command, including the variable assignment part, | 3245 | For OVERRIDE, START and END see `treesit-font-lock-rules'. |
| 3246 | is fontified with with `font-lock-builtin-face'. An alternative to | 3246 | |
| 3247 | this would be to declaration_command to have a `name:' field." | 3247 | This is used instead of `font-lock-builtion-face' directly |
| 3248 | because otherwise the whole command, including the variable | ||
| 3249 | assignment part, is fontified with with `font-lock-builtin-face'. | ||
| 3250 | An alternative to this would be to declaration_command to have a | ||
| 3251 | `name:' field." | ||
| 3248 | (let* ((maybe-decl-cmd (treesit-node-parent node)) | 3252 | (let* ((maybe-decl-cmd (treesit-node-parent node)) |
| 3249 | (node-type (treesit-node-type maybe-decl-cmd))) | 3253 | (node-type (treesit-node-type maybe-decl-cmd))) |
| 3250 | (when (string= node-type "declaration_command") | 3254 | (when (string= node-type "declaration_command") |
| 3251 | (let* ((name-node (car (treesit-node-children maybe-decl-cmd))) | 3255 | (let* ((name-node (treesit-node-child maybe-decl-cmd 0)) |
| 3252 | (name-beg (treesit-node-start name-node)) | 3256 | (name-beg (treesit-node-start name-node)) |
| 3253 | (name-end (treesit-node-end name-node))) | 3257 | (name-end (treesit-node-end name-node))) |
| 3254 | (put-text-property name-beg | 3258 | (treesit-fontify-with-override |
| 3255 | name-end | 3259 | (max start name-beg) (min end name-end) |
| 3256 | 'face | 3260 | 'font-lock-builtin-face override))))) |
| 3257 | font-lock-builtin-face))))) | ||
| 3258 | 3261 | ||
| 3259 | (defvar sh-mode--treesit-settings | 3262 | (defvar sh-mode--treesit-settings |
| 3260 | (treesit-font-lock-rules | 3263 | (treesit-font-lock-rules |
| 3261 | :feature 'comments | 3264 | :feature 'comments |
| 3262 | :language 'bash | 3265 | :language 'bash |
| 3263 | '((comment) @font-lock-comment-face) | 3266 | '((comment) @font-lock-comment-face) |
| 3267 | |||
| 3264 | :feature 'functions | 3268 | :feature 'functions |
| 3265 | :language 'bash | 3269 | :language 'bash |
| 3266 | '((function_definition name: (word) @font-lock-function-name-face)) | 3270 | '((function_definition name: (word) @font-lock-function-name-face)) |
| 3271 | |||
| 3267 | :feature 'strings | 3272 | :feature 'strings |
| 3268 | :language 'bash | 3273 | :language 'bash |
| 3269 | '([(string) (raw_string)] @font-lock-string-face) | 3274 | '([(string) (raw_string)] @font-lock-string-face) |
| 3275 | |||
| 3270 | :feature 'heredocs | 3276 | :feature 'heredocs |
| 3271 | :language 'bash | 3277 | :language 'bash |
| 3272 | '([(heredoc_start) (heredoc_body)] @sh-heredoc) | 3278 | '([(heredoc_start) (heredoc_body)] @sh-heredoc) |
| 3279 | |||
| 3273 | :feature 'variables | 3280 | :feature 'variables |
| 3274 | :language 'bash | 3281 | :language 'bash |
| 3275 | '((variable_name) @font-lock-variable-name-face) | 3282 | '((variable_name) @font-lock-variable-name-face) |
| 3283 | |||
| 3276 | :feature 'keywords | 3284 | :feature 'keywords |
| 3277 | :language 'bash | 3285 | :language 'bash |
| 3278 | `(;; keywords | 3286 | `(;; keywords |
| @@ -3282,10 +3290,11 @@ this would be to declaration_command to have a `name:' field." | |||
| 3282 | ((word) @font-lock-keyword-face | 3290 | ((word) @font-lock-keyword-face |
| 3283 | (:match | 3291 | (:match |
| 3284 | ,(rx-to-string | 3292 | ,(rx-to-string |
| 3285 | `(seq bol | 3293 | `(seq bol |
| 3286 | (or ,@(sh-mode--treesit-other-keywords)) | 3294 | (or ,@(sh-mode--treesit-other-keywords)) |
| 3287 | eol)) | 3295 | eol)) |
| 3288 | @font-lock-keyword-face)))) | 3296 | @font-lock-keyword-face)))) |
| 3297 | |||
| 3289 | :feature 'commands | 3298 | :feature 'commands |
| 3290 | :language 'bash | 3299 | :language 'bash |
| 3291 | `(;; function/non-builtin command calls | 3300 | `(;; function/non-builtin command calls |
| @@ -3300,17 +3309,21 @@ this would be to declaration_command to have a `name:' field." | |||
| 3300 | (or ,@builtins) | 3309 | (or ,@builtins) |
| 3301 | eol))) | 3310 | eol))) |
| 3302 | @font-lock-builtin-face)))) | 3311 | @font-lock-builtin-face)))) |
| 3312 | |||
| 3303 | :feature 'decl-commands | 3313 | :feature 'decl-commands |
| 3304 | :language 'bash | 3314 | :language 'bash |
| 3305 | '(;; declaration commands | 3315 | '(;; declaration commands |
| 3306 | (declaration_command _ @sh-mode--treesit-fontify-decl-command)) | 3316 | (declaration_command _ @sh-mode--treesit-fontify-decl-command)) |
| 3317 | |||
| 3307 | :feature 'constants | 3318 | :feature 'constants |
| 3308 | :language 'bash | 3319 | :language 'bash |
| 3309 | '((case_item value: (word) @font-lock-constant-face) | 3320 | '((case_item value: (word) @font-lock-constant-face) |
| 3310 | (file_descriptor) @font-lock-constant-face) | 3321 | (file_descriptor) @font-lock-constant-face) |
| 3322 | |||
| 3311 | :feature 'operators | 3323 | :feature 'operators |
| 3312 | :language 'bash | 3324 | :language 'bash |
| 3313 | `([ ,@sh-mode--treesit-operators ] @font-lock-builtin-face) | 3325 | `([ ,@sh-mode--treesit-operators ] @font-lock-builtin-face) |
| 3326 | |||
| 3314 | :feature 'builtin-variables | 3327 | :feature 'builtin-variables |
| 3315 | :language 'bash | 3328 | :language 'bash |
| 3316 | `(((special_variable_name) @font-lock-builtin-face | 3329 | `(((special_variable_name) @font-lock-builtin-face |