fxbois / web-mode

web template editing mode for emacs
https://web-mode.org
GNU General Public License v3.0
1.64k stars 260 forks source link

fill-paragraph seems to have no effect in javascript code #1263

Closed raxod502 closed 1 year ago

raxod502 commented 1 year ago

Hello, thank you for the excellent mode. I am investigating a problem which I suspect may be a misunderstanding or misconfiguration on my part. What I see is that M-q (M-x fill-paragraph, which runs web-mode-fill-paragraph) doesn't seem to do anything in a block of line comments (//) in JavaScript code (*.js).

For example, in a file called lucky.js:

  // This functionality seems to be wholly undocumented. Let's
  // foo bar baz|<-- point is here
  // copy and paste an example and hope it works.

If I invoke M-q with a default fill-column of 70 then I'd expect it to fill as follows:

  // This functionality seems to be wholly undocumented. Let's foo bar
  // baz copy and paste an example and hope it works.

I checked using Edebug that M-q is correctly invoking web-mode-fill-paragraph, however, I don't quite understand the intention of the logic in that function. I noticed that the part-token and block-token text properties are both nil at the end of a line, so M-q does nothing when invoked at the end of a line because it fails these checks:

https://github.com/fxbois/web-mode/blob/53bed1e6a8554da877c27ffad6bd65113dc758e3/web-mode.el#L7586-L7587

If I invoke it in the middle of a line, where part-token is set properly to comment, then it can still do nothing if the line is too short, due to failing the following condition:

https://github.com/fxbois/web-mode/blob/53bed1e6a8554da877c27ffad6bd65113dc758e3/web-mode.el#L7591

If I invoke M-q in the middle of a line that is long enough, then it still doesn't do anything, because beg and end get computed as the beginning and end of the comment on the current line only, meaning that the following fill-region invocation has no effect:

https://github.com/fxbois/web-mode/blob/53bed1e6a8554da877c27ffad6bd65113dc758e3/web-mode.el#L7620-L7621

Looking at the code I'm not entirely sure of the intent, maybe I am looking in the wrong place or expecting the wrong thing? I tried to rule out issues from my Emacs configuration by installing the latest version of web-mode in an isolated emacs -Q environment, opening a .js file, and manually running M-x web-mode. I observed the same behavior on M-q.

Do I need to change some settings to enable filling this style of comments? Change the assigned engine (currently "none")? Something else?

web-mode debug info ``` --- WEB-MODE DEBUG BEG --- versions: emacs(28.1) web-mode("17.3.8") vars: engine("none") minor("none") content-type("jsx") file("/home/raxod502/files/code/web/riju/backend/k8s.js") system: window(x) config("x86_64-pc-linux-gnu") colors: fg(nil) bg(nil) minor modes: (auto-fill-function show-paren-mode eldoc-mode global-eldoc-mode straight-package-neutering-mode straight-use-package-mode el-patch-use-package-mode override-global-mode which-key-mode vertico-mode prescient-persist-mode vertico-prescient-mode windmove-mode winner-mode save-place-mode radian-fix-whitespace-mode radian-fix-whitespace-global-mode outline-minor-mode global-outline-minor-mode undo-tree-mode global-undo-tree-mode subword-mode global-subword-mode ctrlf-local-mode ctrlf-mode smartparens-mode smartparens-global-mode show-smartparens-mode show-smartparens-global-mode apheleia-mode apheleia-global-mode company-mode global-company-mode company-prescient-mode projectile-mode global-auto-revert-mode git-gutter-mode global-git-gutter-mode global-atomic-chrome-edit-mode lsp-mode lsp-managed-mode lsp-completion-mode flycheck-mode lsp-ui-sideline-mode lsp-ui-doc-mode lsp-ui-mode lsp-modeline-code-actions-mode lsp-modeline-diagnostics-mode lsp-modeline-workspace-status-mode lsp-headerline-breadcrumb-mode lsp-diagnostics-mode radian-universal-keyboard-quit-mode shell-dirtrack-mode magit-auto-revert-mode global-git-commit-mode) vars: web-mode-enable-current-column-highlight=nil web-mode-enable-current-element-highlight=nil indent-tabs-mode=nil --- WEB-MODE DEBUG END --- ```
fxbois commented 1 year ago

Hi I won't have time to work on this. If you can provide a path, I'll look at it.