diff options
| author | Juri Linkov | 2025-05-05 19:57:29 +0300 |
|---|---|---|
| committer | Juri Linkov | 2025-05-05 19:57:29 +0300 |
| commit | 61cb73a2dbe756b060d4256c3b7ebe09f71ed2b7 (patch) | |
| tree | e33421c2409bdef2c1eda7a0fe35a59f946d07d1 | |
| parent | e5746d3677b86ef3d0ba0d7f1e916180cc4b6f69 (diff) | |
| download | emacs-61cb73a2dbe756b060d4256c3b7ebe09f71ed2b7.tar.gz emacs-61cb73a2dbe756b060d4256c3b7ebe09f71ed2b7.zip | |
New variable 'comment-setup-function' for multi-language modes.
* lisp/newcomment.el (comment-setup-function): New variable.
(comment-normalize-vars): Call non-nil 'comment-setup-function'.
* lisp/textmodes/mhtml-ts-mode.el
(mhtml-ts-mode--comment-current-lang): New internal variable.
(mhtml-ts-mode--comment-setup): New function.
(mhtml-ts-mode): Set 'comment-setup-function' to
'mhtml-ts-mode--comment-setup' instead of using
'c-ts-common-comment-setup' only for JavaScript.
https://lists.gnu.org/archive/html/emacs-devel/2025-05/msg00025.html
| -rw-r--r-- | lisp/newcomment.el | 5 | ||||
| -rw-r--r-- | lisp/textmodes/mhtml-ts-mode.el | 23 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 4da3b55d2f0..a6a1b7340a6 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el | |||
| @@ -344,6 +344,9 @@ terminated by the end of line (i.e., `comment-end' is empty)." | |||
| 344 | "Return the mirror image of string S, without any trailing space." | 344 | "Return the mirror image of string S, without any trailing space." |
| 345 | (comment-string-strip (concat (nreverse (string-to-list s))) nil t)) | 345 | (comment-string-strip (concat (nreverse (string-to-list s))) nil t)) |
| 346 | 346 | ||
| 347 | (defvar comment-setup-function nil | ||
| 348 | "Function to set up variables needed by commenting functions.") | ||
| 349 | |||
| 347 | ;;;###autoload | 350 | ;;;###autoload |
| 348 | (defun comment-normalize-vars (&optional noerror) | 351 | (defun comment-normalize-vars (&optional noerror) |
| 349 | "Check and set up variables needed by other commenting functions. | 352 | "Check and set up variables needed by other commenting functions. |
| @@ -351,6 +354,8 @@ All the `comment-*' commands call this function to set up various | |||
| 351 | variables, like `comment-start', to ensure that the commenting | 354 | variables, like `comment-start', to ensure that the commenting |
| 352 | functions work correctly. Lisp callers of any other `comment-*' | 355 | functions work correctly. Lisp callers of any other `comment-*' |
| 353 | function should first call this function explicitly." | 356 | function should first call this function explicitly." |
| 357 | (when (functionp comment-setup-function) | ||
| 358 | (funcall comment-setup-function)) | ||
| 354 | (unless (and (not comment-start) noerror) | 359 | (unless (and (not comment-start) noerror) |
| 355 | (unless comment-start | 360 | (unless comment-start |
| 356 | (let ((cs (read-string "No comment syntax is defined. Use: "))) | 361 | (let ((cs (read-string "No comment syntax is defined. Use: "))) |
diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el index d41f93e2682..6b261205409 100644 --- a/lisp/textmodes/mhtml-ts-mode.el +++ b/lisp/textmodes/mhtml-ts-mode.el | |||
| @@ -356,6 +356,26 @@ Return nil if there is no name or if NODE is not a defun node." | |||
| 356 | (js-name js-name) | 356 | (js-name js-name) |
| 357 | (css-name css-name)))) | 357 | (css-name css-name)))) |
| 358 | 358 | ||
| 359 | (defvar-local mhtml-ts-mode--comment-current-lang nil) | ||
| 360 | |||
| 361 | (defun mhtml-ts-mode--comment-setup () | ||
| 362 | (let ((lang (treesit-language-at (point)))) | ||
| 363 | (unless (eq mhtml-ts-mode--comment-current-lang lang) | ||
| 364 | (setq mhtml-ts-mode--comment-current-lang lang) | ||
| 365 | (pcase lang | ||
| 366 | ('html | ||
| 367 | (setq-local comment-start "<!-- ") | ||
| 368 | (setq-local comment-start-skip nil) | ||
| 369 | (setq-local comment-end " -->") | ||
| 370 | (setq-local comment-end-skip nil)) | ||
| 371 | ('css | ||
| 372 | (setq-local comment-start "/*") | ||
| 373 | (setq-local comment-start-skip "/\\*+[ \t]*") | ||
| 374 | (setq-local comment-end "*/") | ||
| 375 | (setq-local comment-end-skip "[ \t]*\\*+/")) | ||
| 376 | ('javascript | ||
| 377 | (c-ts-common-comment-setup)))))) | ||
| 378 | |||
| 359 | ;;; Flymake integration | 379 | ;;; Flymake integration |
| 360 | 380 | ||
| 361 | (defvar-local mhtml-ts-mode--flymake-process nil | 381 | (defvar-local mhtml-ts-mode--flymake-process nil |
| @@ -431,9 +451,8 @@ Powered by tree-sitter." | |||
| 431 | ;; just like it's done in the original mode. | 451 | ;; just like it's done in the original mode. |
| 432 | 452 | ||
| 433 | ;; Comment. | 453 | ;; Comment. |
| 434 | ;; indenting settings for js-ts-mode. | ||
| 435 | (c-ts-common-comment-setup) | ||
| 436 | (setq-local comment-multi-line t) | 454 | (setq-local comment-multi-line t) |
| 455 | (setq-local comment-setup-function #'mhtml-ts-mode--comment-setup) | ||
| 437 | 456 | ||
| 438 | ;; Font-lock. | 457 | ;; Font-lock. |
| 439 | 458 | ||