aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorVincenzo Pupillo2025-07-10 17:20:34 +0200
committerEli Zaretskii2025-08-09 15:57:04 +0300
commite1fd7b5d89ec7f2df40fa01bf4041c0d1df147b4 (patch)
tree80b3644ccfaacc1b0c5c11eb1b350432d0099f87 /lisp/textmodes
parent3fb8ffe61eacb73df17f2a4a6c2ac240951a289b (diff)
downloademacs-e1fd7b5d89ec7f2df40fa01bf4041c0d1df147b4.tar.gz
emacs-e1fd7b5d89ec7f2df40fa01bf4041c0d1df147b4.zip
`php-ts-mode' depends on `mhtml-ts-mode' instead of JS,CSS and HTML
The direct dependence on js-ts-mode, css-ts-mode and html-ts-mode has now been replaced by 'mhtml-ts-mode'. Additional benefits are: 1. Imenu now exposes symbols for all of all languages, 2. navigation now works correctly for all languages, 3. outline works for all languages. Additional new features are: 1. indentation of PHP in mixed buffers with HTML now works much better and allows three different behaviors, an option allows you to choose the behavior. 2. a new feature shows where PHP ini files are both locally and remotely, if the buffer is associated with a remote PHP file. * etc/NEWS: Mention the rationale for those changes, the new command, and the new options. * lisp/textmodes/mhtml-ts-mode.el (mhtml-ts-mode--range-settings): New variable that store range settings. (mhtml-ts-mode--treesit-aggregated-outline-predicate): New variable that store outline predicates. (mhtml-ts-mode): Use those two new variables. * lisp/progmodes/php-ts-mode.el: Update doc string. Removed old dependencies. (php-ts-mode--language-source-alist): Updated parsers version. (php-ts-mode-install-parsers): Removed old dependencies, now relies on (mhtml-ts-mode-install-parsers). Update doc string. (php-ts-mode-js-css-indent-offset): Update doc string. (php-ts-mode-css-fontify-colors): Removed option, now relies on 'php-ts-mode-css-fontify-colors'. (php-ts-mode-html-indent-offset): New user option. (php-ts-mode-html-relative-indent): New user option. (php-ts-mode-php-default-executable): Assume \"php\" instead of \"/usr/bin/php\" if 'executable-find' fails. (php-ts-mode-php-config): Fix tag. (php-ts-mode-find-sibling-rules): New user option with the rules for finding siblings of a file. (php-ts-mode-phpdoc-highlight-errors): New user option, if non-nil highlight unkown PHPDOC nodes. (php-ts-mode--indent-style-setter): Indentation fix. (php-ts-mode-indent-style): Indentation fix. (php-ts-mode-flymake-php): Indentation fix. (php-ts-mode--executable): Indentation fix. (php-ts-mode-show-ini): New command that show the locations of PHP ini files. (php-ts-mode--get-indent-style): Indentation fix. (php-ts-mode--set-indent-property): Indentation fix. (php-ts-mode-set-style): Indentation fix. (php-ts-mode--get-parser-ranges): Indentation fix. (php-ts-mode--possibly-braceless-keyword-re): Removed no longer used constant. (php-ts-mode--open-statement-group-heuristic): Removed no longer used function. (php-ts-mode--else-heuristic): Indentation fix. (php-ts-mode--first-sibling): Indentation fix. (php-ts-mode--js-css-tag-bol): Function removed, now using 'mhtml-ts-mode--js-css-tag-bol'. (php-ts-mode--parent-html-bol): Removed no longer used function. (php-ts-mode--parent-html-heuristic): Now more reliably handles the mixed indentation of PHP and HTML. The new option 'php-ts-mode-html-relative-indent' changes the behavior of the function. When 'php-ts-mode-html-relative-indent' is 't' the new option 'php-ts-mode-html-indent-offset' controls the offset of PHP code relative to HTML tags. (php-ts-mode--array-element-heuristic): Indentation fix. (php-ts-mode--anchor-prev-sibling): Indentation fix.. (php-ts-mode--indent-styles): The indentation rules for 'program' and 'text_interpolation' are now common to all indentation styles, thanks to the new version of 'php-ts-mode-arent-html-heuristic'. New rules for 'namespace_use_clause', 'use_declaration', 'use_list', 'attribute_group' and 'string_content'. (php-ts-mode--prettify-symbols-alist): New variable to support 'prettify-symbols-alist'. (php-ts-mode--test-visibility-modifier-operation-clause-p): Rename ... (php-ts-mode--test-visibility-modifier-operation-p): ... to this more correct name. (php-ts-mode--test-property-hook-clause-p): Rename ... (php-ts-mode--test-property-hook-p): ... to this more correct name. (php-ts-mode--test-relative-name-p): New function to test if 'relative_name' is supported by the PHP parser. (php-ts-mode--font-lock-settings): Use the new function for highlight 'relative_name'. Highlight 'error_suppression_expression'. Refactoring using the renamed functions. Indentation fix. (php-ts-mode--custom-html-font-lock-settings): Replace the rules with 'mhtml-ts-mode--treesit-font-lock-settings'. Fix docs string. (php-ts-mode--phpdoc-font-lock-settings): Added support for "array" and "list" array_type. New "phpdoc-error" feature to highlight unknown nodes via new 'php-ts-mode--phpdoc-fontify-error' function. (php-ts-mode--colorize-css-value): Removed function no longer used, now highlighting is handled directly by 'mhtml-ts-mode'. (php-ts-mode--phpdoc-fontify-error): New function used by 'php-ts-mode--phpdoc-font-lock-settings'. (php-ts-mode--parent-object): Indentation fix. (php-ts-mode--defun-name-separator): Indentation fix. (php-ts-mode--defun-object-name): Indentation fix. (php-ts-mode--defun-name): The function now also returns the defun name of 'mhtml-ts-mode'. (php-ts-mode--treesit-defun-type-regexp): New regexp for 'treesit-defun-type-regexp' support. (php-ts-mode--indent-defun): Indentation fix. (php-ts-mode--defun-valid-p): Fix indentation. (php-ts-mode--comment-indent-new-line): Indentation fix. (php-ts-mode--comment-current-plist): New local variable that stores the state of the PHP comment style. (php-ts-mode--comment-setup): The function now handles changing, for different languages, comment styles, using "php-ts-mode--comment-current-plist" to store and retrieve the comment style for the PHP language. (php-ts-mode-comment-setup): Now store the PHP comment style in 'php-ts-mode--comment-current-plist'. (php-ts-mode-menu): Indentation fix. (php-ts-mode): Replace dependency from JS, CSS and HTML width 'mhtml-ts-mode'. Navigation, Imenu and Outline now support PHP, HTML, Javascript and CSS. Added support for 'prettify-symbol-mode'. Added support for 'electric-layout-rules'. (php-ts-mode-run-php-webserver, php-ts-mode--webserver-read-args) (php-ts-mode--webserver-read-args, inferior-php-ts-mode, run-php) (inferior-php-ts-mode-startup, php-ts-mode-inferior--write-history) (php-ts-mode-send-region): Indentation fixes. (Bug#78994)
Diffstat (limited to 'lisp/textmodes')
-rw-r--r--lisp/textmodes/mhtml-ts-mode.el78
1 files changed, 43 insertions, 35 deletions
diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el
index 6b261205409..66bb27ced10 100644
--- a/lisp/textmodes/mhtml-ts-mode.el
+++ b/lisp/textmodes/mhtml-ts-mode.el
@@ -333,7 +333,8 @@ NODE and PARENT are ignored."
333 "function_declaration" 333 "function_declaration"
334 "lexical_declaration" 334 "lexical_declaration"
335 "element" 335 "element"
336 "rule_set")) 336 "rule_set"
337 "keyframe_block"))
337 "Settings for `treesit-defun-type-regexp'.") 338 "Settings for `treesit-defun-type-regexp'.")
338 339
339;; In order to support `prettify-symbols-mode', just `append' the prettify 340;; In order to support `prettify-symbols-mode', just `append' the prettify
@@ -348,13 +349,11 @@ NODE and PARENT are ignored."
348(defun mhtml-ts-mode--defun-name (node) 349(defun mhtml-ts-mode--defun-name (node)
349 "Return the defun name of NODE. 350 "Return the defun name of NODE.
350Return nil if there is no name or if NODE is not a defun node." 351Return nil if there is no name or if NODE is not a defun node."
351 (let ((html-name (html-ts-mode--defun-name node)) 352 (let ((lang (treesit-node-language node)))
352 (js-name (js--treesit-defun-name node))
353 (css-name (css--treesit-defun-name node)))
354 (cond 353 (cond
355 (html-name html-name) 354 ((eq lang 'html) (html-ts-mode--defun-name node))
356 (js-name js-name) 355 ((eq lang 'javascript) (js--treesit-defun-name node))
357 (css-name css-name)))) 356 ((eq lang 'css) (css--treesit-defun-name node)))))
358 357
359(defvar-local mhtml-ts-mode--comment-current-lang nil) 358(defvar-local mhtml-ts-mode--comment-current-lang nil)
360 359
@@ -432,6 +431,41 @@ Calls REPORT-FN directly. Requires tidy."
432 (process-send-region mhtml-ts-mode--flymake-process (point-min) (point-max)) 431 (process-send-region mhtml-ts-mode--flymake-process (point-min) (point-max))
433 (process-send-eof mhtml-ts-mode--flymake-process))))) 432 (process-send-eof mhtml-ts-mode--flymake-process)))))
434 433
434(defvar mhtml-ts-mode--range-settings
435 (append
436 (treesit-range-rules
437 :embed 'javascript
438 :host 'html
439 '((script_element
440 (start_tag (tag_name))
441 (raw_text) @cap))
442
443 ;; Another rule could be added that when it matches an
444 ;; attribute_value that has as its parent an
445 ;; attribute_name "style" it captures it and then
446 ;; passes it to the css parser.
447 :embed 'css
448 :host 'html
449 '((style_element
450 (start_tag (tag_name))
451 (raw_text) @cap)))
452
453 ;; jsdoc is not mandatory for js-ts-mode, so we respect this by
454 ;; adding jsdoc range rules only when jsdoc is available.
455 (when (treesit-ensure-installed 'jsdoc)
456 (treesit-range-rules
457 :embed 'jsdoc
458 :host 'javascript
459 :local t
460 `(((comment) @cap
461 (:match ,js--treesit-jsdoc-beginning-regexp @cap)))))))
462
463(defvar mhtml-ts-mode--treesit-aggregated-outline-predicate
464 `((html . ,#'html-ts-mode--outline-predicate)
465 (javascript . ,js-ts-mode--outline-predicate)
466 (css . ,css-ts-mode--outline-predicate))
467 "Settings for `treesit-aggregated-outline-predicate'.")
468
435;;;###autoload 469;;;###autoload
436(define-derived-mode mhtml-ts-mode html-ts-mode 470(define-derived-mode mhtml-ts-mode html-ts-mode
437 '("HTML+" (:eval (let ((lang (treesit-language-at (point)))) 471 '("HTML+" (:eval (let ((lang (treesit-language-at (point))))
@@ -475,35 +509,11 @@ Powered by tree-sitter."
475 ;; Multi-language modes must set the primary parser. 509 ;; Multi-language modes must set the primary parser.
476 (setq-local treesit-primary-parser (treesit-parser-create 'html)) 510 (setq-local treesit-primary-parser (treesit-parser-create 'html))
477 511
478 (setq-local treesit-range-settings 512 (setq-local treesit-range-settings mhtml-ts-mode--range-settings)
479 (treesit-range-rules
480 :embed 'javascript
481 :host 'html
482 '((script_element
483 (start_tag (tag_name))
484 (raw_text) @cap))
485
486 ;; Another rule could be added that when it matches an
487 ;; attribute_value that has as its parent an
488 ;; attribute_name "style" it captures it and then
489 ;; passes it to the css parser.
490 :embed 'css
491 :host 'html
492 '((style_element
493 (start_tag (tag_name))
494 (raw_text) @cap))))
495 513
496 ;; jsdoc is not mandatory for js-ts-mode, so we respect this by 514 ;; jsdoc is not mandatory for js-ts-mode, so we respect this by
497 ;; adding jsdoc range rules only when jsdoc is available. 515 ;; adding jsdoc range rules only when jsdoc is available.
498 (when (treesit-ensure-installed 'jsdoc) 516 (when (treesit-ensure-installed 'jsdoc)
499 (setq-local treesit-range-settings
500 (append treesit-range-settings
501 (treesit-range-rules
502 :embed 'jsdoc
503 :host 'javascript
504 :local t
505 `(((comment) @cap
506 (:match ,js--treesit-jsdoc-beginning-regexp @cap))))))
507 (setq-local c-ts-common--comment-regexp 517 (setq-local c-ts-common--comment-regexp
508 js--treesit-jsdoc-comment-regexp)) 518 js--treesit-jsdoc-comment-regexp))
509 519
@@ -563,9 +573,7 @@ Powered by tree-sitter."
563 mhtml-ts-mode--treesit-aggregated-simple-imenu-settings) 573 mhtml-ts-mode--treesit-aggregated-simple-imenu-settings)
564 574
565 (setq-local treesit-aggregated-outline-predicate 575 (setq-local treesit-aggregated-outline-predicate
566 `((html . ,#'html-ts-mode--outline-predicate) 576 mhtml-ts-mode--treesit-aggregated-outline-predicate)
567 (javascript . ,js-ts-mode--outline-predicate)
568 (css . ,css-ts-mode--outline-predicate)))
569 577
570 (treesit-major-mode-setup) 578 (treesit-major-mode-setup)
571 579