emacs-typescript / typescript.el

TypeScript-support for Emacs
GNU General Public License v3.0
266 stars 79 forks source link

M-j in /** foo */ comment blocks is broken. Reasonbly easy to fix #150

Open joaotavora opened 3 years ago

joaotavora commented 3 years ago

To reproduce:

emacs -Q -L /path/to/typescript.el -l typescript-mode ~/tmp/something.ts

In something.ts, this exists:

/**
 * foo <cursor here>
 */

Pressing M-j begets:

/**
 * foo */
/**
 */

In #41 (sorry, not #42) , a reasonable suggestion is to rebind M-j to c-indent-new-comment-line, but that requires this patch to typescript.el:

diff -u --label /home/capitaomorte/.emacs.d/elpa/typescript-mode-20201002.1109/typescript-mode.el --label \#\<buffer\ typescript-mode.el\> /home/capitaomorte/.emacs.d/elpa/typescript-mode-20201002.1109/typescript-mode.el /tmp/buffer-content-NJt1TY
--- /home/capitaomorte/.emacs.d/elpa/typescript-mode-20201002.1109/typescript-mode.el
+++ #<buffer typescript-mode.el>
@@ -2945,6 +2945,7 @@
         c-paragraph-start "$"
         c-paragraph-separate "$"
         c-block-comment-prefix "* "
+        c-block-comment-ender-regexp "\\*/"
         c-line-comment-starter "//"
         c-comment-start-regexp "/[*/]\\|\\s!"
         comment-start-skip "\\(//+\\|/\\*+\\)\\s *")

Diff finished.  Wed Aug 11 12:13:38 2021
zzantares commented 2 years ago

Until this gets fixed, here's another workaround which doesn't require patching the library:

(defun my-custom-auto-fill ()
  "Break the line and continue with comment if there's any."
  (when (> (current-column) fill-column)
    (c-indent-new-comment-line)))

(add-hook 'typescript-mode-hook
          (lambda ()
            (setq-local auto-fill-function 'my-custom-auto-fill)))

it's not pretty though ...

josteink commented 2 years ago

Wow. Has this been lying around since August? :fearful:

That c-based fix looks doable. Let me fix that up for you.

josteink commented 2 years ago

Should work with c-indent-new-comment-line with the code in current master now.

So now at least key rebinding should be an option.