jscheid / prettier.el

Prettier code formatting for Emacs.
GNU General Public License v3.0
172 stars 12 forks source link

Emacs Crashes when saving a file on the last line in prettier mode #71

Closed MPE2016 closed 3 years ago

MPE2016 commented 3 years ago

Describe the bug Ok, a small disclaimer to start of with: I don't know if this problem is caused by prettier.el. But I don't know where else to start, and it seemed logical to start here, because the problem seems to be related to prettier.el, which of course does not mean it is caused by prettier.el. In other words, I would not be surprised if this is not at all caused by prettier.el:)

First things first. I'm on:

The title pretty much explains the problem: Emacs crashes(or is running in some kind of infinite loop) when I am using prettier.el (either in an html, css or javascript file) and saving a file with the cursor the last line of said file. I noticed that it doesn't crash when I switch prettier.el off. My own assessment is that this is either something in prettier.el, or perhaps some kind of conflict issue with another package which I haven't been able to find out. When I press ctrl+g, I regain control of emacs however.

Link to M-x prettier-info output https://gist.github.com/MPE2016/dc6cdbf92dabcaff0a39ba0d69c1f909

To Reproduce See bug description

Expected behavior No crash of emacs.

Additional context not applicable

jscheid commented 3 years ago

It does sound like it's this packet to blame. Is there anything interesting in buffer *prettier (local)*?

jscheid commented 3 years ago

And could you attach one of the files it happens with?

Also, a copy of the output of M-x describe-mode (in a buffer where you have the problem) would be useful.

MPE2016 commented 3 years ago

Hmm, I don't appear to be having a prettier (local) buffer. Is that normal?

Op maandag 1 februari 2021 om 0u32 schreef Julian Scheid notifications@github.com:

It does sound like it's this packet to blame. Is there anything interesting in buffer prettier (local)?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jscheid/prettier.el/issues/71#issuecomment-770673450, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADYWBBGRTMFGX35EKJMOGQ3S4ZRI3ANCNFSM4W4KBW2Q.

MPE2016 commented 3 years ago

More than happy to do so, (see attachment) but it really happens with every js html and css file I've checked, so I don't expect this to be file specific (of course I could be wrong).

Op maandag 1 februari 2021 om 1u29 schreef Julian Scheid notifications@github.com:

And could you attach one of the files it happens with?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jscheid/prettier.el/issues/71#issuecomment-770712681, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADYWBBA6FL7P5UYKSHCWNOTS4ZX5ZANCNFSM4W4KBW2Q.

jscheid commented 3 years ago

Let's take a step back: when you're not on the last line, does prettier-mode work? Is it reformatting the buffer on save? If it does, then you should definitely have a buffer whose name starts with *prettier.

When you say "I noticed that it doesn't crash when I switch prettier.el off", how do you switch it off? By disabling prettier-mode?

MPE2016 commented 3 years ago

Let's take a step back: when you're not on the last line, does prettier-mode work? Is it reformatting the buffer on save? If it does, then you should definitely have a buffer whose name starts with *prettier.

Ok. When I'm not on the last line and I save the file with a change - for example adding a space to the beginning of the first line - it reformats the buffer on save, and then the prettier (local) buffer exists, but it is completely empty.

If I then go to the last line and save the file, it crashes, and the prettier (local) buffer is gone.

When you say "I noticed that it doesn't crash when I switch prettier.el off", how do you switch it off? By disabling prettier-mode?

Yes.

Op maandag 1 februari 2021 om 3u53 schreef Julian Scheid notifications@github.com:

Let's take a step back: when you're not on the last line, does prettier-mode work? Is it reformatting the buffer on save? If it does, then you should definitely have a buffer whose name starts with *prettier.

When you say "I noticed that it doesn't crash when I switch prettier.el off", how do you switch it off? By disabling prettier-mode?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jscheid/prettier.el/issues/71#issuecomment-770801070, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADYWBBBYORLYQ3GFIZHJTRDS42I5DANCNFSM4W4KBW2Q.

jscheid commented 3 years ago

Interesting. Can you send me the describe-mode output please and I'll have closer look tomorrow.

MPE2016 commented 3 years ago

Ok, cool, here it is, and thank you for looking into this!

All the best

Maarten

Op maandag 1 februari 2021 om 4u11 schreef Julian Scheid notifications@github.com:

Interesting. Can you send me the describe-mode output please and I'll have closer look tomorrow.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jscheid/prettier.el/issues/71#issuecomment-770811204, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADYWBBBNEDIAH2KIJ7JBMATS42K6HANCNFSM4W4KBW2Q.

Enabled minor modes: Adaptive-Wrap-Prefix Auto-Composition Auto-Compression Auto-Encryption Beacon Blink-Cursor Company Cursor-Sensor Delete-Selection Diff-Auto-Refine Dimmer Eldoc File-Name-Shadow Font-Lock Global-Company Global-Eldoc Global-Font-Lock Global-Prettify-Symbols Highlight-Parentheses Line-Number Lsp Lsp-Completion Lsp-Diagnostics Lsp-Managed Lsp-Modeline-Code-Actions Lsp-Modeline-Diagnostics Lsp-Ui Lsp-Ui-Sideline Mouse-Wheel Pdf-Occur-Global Prettier Prettify-Symbols Pyvenv Shell-Dirtrack Smartparens Tooltip Transient-Mark Treemacs-Filewatch Treemacs-Follow Treemacs-Fringe-Indicator Treemacs-Git Visual-Line Yas Yas-Global

(Information about these minor modes follows the major mode info.)

Javascript-IDE mode defined in ‘js2-mode.el’: Major mode for editing JavaScript code.

In addition to any hooks its parent mode ‘js-mode’ might have run, this mode runs the hook ‘js2-mode-hook’, as the final or penultimate step during initialization.

key binding


C-c Prefix Command ESC Prefix Command

js2-down-mouse-3 Prefix Command C-c C-a js2-mode-show-all C-c C-e js2-mode-hide-element C-c C-f js2-mode-toggle-hide-functions C-c C-o js2-mode-toggle-element C-c C-s js2-mode-show-element C-c C-t js2-mode-toggle-hide-comments C-c C-w js2-mode-toggle-warnings-and-errors js2-line-break js2-jump-to-definition C-M-x js-eval-defun M-. js-find-symbol C-c C-j js-set-js-context C-c ESC Prefix Command C-M-q prog-indent-sexp C-c M-: js-eval Adaptive-Wrap-Prefix minor mode (no indicator): Wrap the buffer text with adaptive filling. Auto-Composition minor mode (no indicator): Toggle Auto Composition mode. With a prefix argument ARG, enable Auto Composition mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. When Auto Composition mode is enabled, text characters are automatically composed by functions registered in ‘composition-function-table’. You can use ‘global-auto-composition-mode’ to turn on Auto Composition mode in all buffers (this is the default). Auto-Compression minor mode (no indicator): Toggle Auto Compression mode. With a prefix argument ARG, enable Auto Compression mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. Auto Compression mode is a global minor mode. When enabled, compressed files are automatically uncompressed for reading, and compressed when writing. Auto-Encryption minor mode (no indicator): Toggle automatic file encryption/decryption (Auto Encryption mode). With a prefix argument ARG, enable Auto Encryption mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. (fn &optional ARG) Beacon minor mode (indicator (*)): Toggle Beacon mode on or off. With a prefix argument ARG, enable Beacon mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil, and toggle it if ARG is ‘toggle’. Uses keymap ‘beacon-mode-map’, which is not currently defined. (fn &optional ARG) Blink-Cursor minor mode (no indicator): Toggle cursor blinking (Blink Cursor mode). With a prefix argument ARG, enable Blink Cursor mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. If the value of ‘blink-cursor-blinks’ is positive (10 by default), the cursor stops blinking after that number of blinks, if Emacs gets no input during that time. See also ‘blink-cursor-interval’ and ‘blink-cursor-delay’. This command is effective only on graphical frames. On text-only terminals, cursor blinking is controlled by the terminal. (fn &optional ARG) Company minor mode (no indicator): "complete anything"; is an in-buffer completion framework. Completion starts automatically, depending on the values ‘company-idle-delay’ and ‘company-minimum-prefix-length’. Completion can be controlled with the commands: ‘company-complete-common’, ‘company-complete-selection’, ‘company-complete’, ‘company-select-next’, ‘company-select-previous’. If these commands are called before ‘company-idle-delay’, completion will also start. Completions can be searched with ‘company-search-candidates’ or ‘company-filter-candidates’. These can be used while completion is inactive, as well. The completion data is retrieved using ‘company-backends’ and displayed using ‘company-frontends’. If you want to start a specific backend, call it interactively or use ‘company-begin-backend’. By default, the completions list is sorted alphabetically, unless the backend chooses otherwise, or ‘company-transformers’ changes it later. regular keymap (‘company-mode-map’): key binding --- ------- keymap during active completions (‘company-active-map’): key binding --- ------- C-d company-show-doc-buffer C-g company-abort C-h company-show-doc-buffer TAB company-complete-common RET company-complete-selection C-s company-search-candidates C-w company-show-location ESC Prefix Command company-select-next-or-abort ignore ignore company-show-doc-buffer company-complete-mouse company-select-mouse Prefix Command company-complete-selection company-complete-common company-select-previous-or-abort ignore ignore company-previous-page company-next-page C-M-s company-filter-candidates ESC ESC Prefix Command M-0 .. M-9 company-complete-number M-n company-select-next M-p company-select-previous M-ESC ESC company-abort (fn &optional ARG) Cursor-Sensor minor mode (no indicator): Handle the ‘cursor-sensor-functions’ text property. This property should hold a list of functions which react to the motion of the cursor. They’re called with three arguments (WINDOW OLDPOS DIR) where WINDOW is the affected window, OLDPOS is the last known position of the cursor and DIR can be ‘entered’ or ‘left’ depending on whether the cursor is entering the area covered by the text-property property or leaving it. (fn &optional ARG) Delete-Selection minor mode (no indicator): Toggle Delete Selection mode. Interactively, with a prefix argument, enable Delete Selection mode if the prefix argument is positive, and disable it otherwise. If called from Lisp, toggle the mode if ARG is ‘toggle’, disable the mode if ARG is a non-positive integer, and enable the mode otherwise (including if ARG is omitted or nil or a positive integer). When Delete Selection mode is enabled, typed text replaces the selection if the selection is active. Otherwise, typed text is just inserted at point regardless of any selection. See ‘delete-selection-helper’ and ‘delete-selection-pre-hook’ for information on adapting behavior of commands in Delete Selection mode. (fn &optional ARG) Diff-Auto-Refine minor mode (no indicator): Toggle automatic diff hunk highlighting (Diff Auto Refine mode). With a prefix argument ARG, enable Diff Auto Refine mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. Diff Auto Refine mode is a buffer-local minor mode used with ‘diff-mode’. When enabled, Emacs automatically highlights changes in detail as the user visits hunks. When transitioning from disabled to enabled, it tries to refine the current hunk, as well. (fn &optional ARG) Dimmer minor mode (no indicator): visually highlight the selected buffer Eldoc minor mode (no indicator): Toggle echo area display of Lisp objects at point (ElDoc mode). With a prefix argument ARG, enable ElDoc mode if ARG is positive, and disable it otherwise. If called from Lisp, enable ElDoc mode if ARG is omitted or nil. ElDoc mode is a buffer-local minor mode. When enabled, the echo area displays information about a function or variable in the text where point is. If point is on a documented variable, it displays the first line of that variable’s doc string. Otherwise it displays the argument list of the function called in the expression point is on. (fn &optional ARG) File-Name-Shadow minor mode (no indicator): Toggle file-name shadowing in minibuffers (File-Name Shadow mode). With a prefix argument ARG, enable File-Name Shadow mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. File-Name Shadow mode is a global minor mode. When enabled, any part of a filename being read in the minibuffer that would be ignored (because the result is passed through ‘substitute-in-file-name’) is given the properties in ‘file-name-shadow-properties’, which can be used to make that portion dim, invisible, or otherwise less visually noticeable. Font-Lock minor mode (no indicator): Toggle syntax highlighting in this buffer (Font Lock mode). With a prefix argument ARG, enable Font Lock mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. When Font Lock mode is enabled, text is fontified as you type it: - Comments are displayed in ‘font-lock-comment-face’; - Strings are displayed in ‘font-lock-string-face’; - Certain other expressions are displayed in other faces according to the value of the variable ‘font-lock-keywords’. To customize the faces (colors, fonts, etc.) used by Font Lock for fontifying different parts of buffer text, use M-x customize-face. You can enable Font Lock mode in any major mode automatically by turning on in the major mode’s hook. For example, put in your ~/.emacs: (add-hook 'c-mode-hook 'turn-on-font-lock) Alternatively, you can use Global Font Lock mode to automagically turn on Font Lock mode in buffers whose major mode supports it and whose major mode is one of ‘font-lock-global-modes’. For example, put in your ~/.emacs: (global-font-lock-mode t) Where major modes support different levels of fontification, you can use the variable ‘font-lock-maximum-decoration’ to specify which level you generally prefer. When you turn Font Lock mode on/off the buffer is fontified/defontified, though fontification occurs only if the buffer is less than ‘font-lock-maximum-size’. To add your own highlighting for some major mode, and modify the highlighting selected automatically via the variable ‘font-lock-maximum-decoration’, you can use ‘font-lock-add-keywords’. To fontify a buffer, without turning on Font Lock mode and regardless of buffer size, you can use M-x font-lock-fontify-buffer. To fontify a block (the function or paragraph containing point, or a number of lines around point), perhaps because modification on the current line caused syntactic change on other lines, you can use M-o M-o. You can set your own default settings for some mode, by setting a buffer local value for ‘font-lock-defaults’, via its mode hook. The above is the default behavior of ‘font-lock-mode’; you may specify your own function which is called when ‘font-lock-mode’ is toggled via ‘font-lock-function’. Global-Company minor mode (no indicator): Toggle Company mode in all buffers. With prefix ARG, enable Global Company mode if ARG is positive; otherwise, disable it. If called from Lisp, enable the mode if ARG is omitted or nil. Company mode is enabled in all buffers where ‘company-mode-on’ would do it. See ‘company-mode’ for more information on Company mode. (fn &optional ARG) Global-Eldoc minor mode (no indicator): Toggle Eldoc mode in all buffers. With prefix ARG, enable Global Eldoc mode if ARG is positive; otherwise, disable it. If called from Lisp, enable the mode if ARG is omitted or nil. Eldoc mode is enabled in all buffers where ‘turn-on-eldoc-mode’ would do it. See ‘eldoc-mode’ for more information on Eldoc mode. (fn &optional ARG) Global-Font-Lock minor mode (no indicator): Toggle Font-Lock mode in all buffers. With prefix ARG, enable Global Font-Lock mode if ARG is positive; otherwise, disable it. If called from Lisp, enable the mode if ARG is omitted or nil. Font-Lock mode is enabled in all buffers where ‘turn-on-font-lock-if-desired’ would do it. See ‘font-lock-mode’ for more information on Font-Lock mode
jscheid commented 3 years ago

Thanks.

Could you run this expression: (setq prettier-keep-server-buffer-flag t) and then try again? This time the *prettier (local)* buffer shouldn't vanish after the crash and hopefully there's going to be something useful in it.

MPE2016 commented 3 years ago

Ok, it's not much, but this is what you get:

C-1 Z0

Op maandag 1 februari 2021 om 12u01 schreef Julian Scheid notifications@github.com:

Thanks.

Could you run this expression: (setq prettier-keep-server-buffer-flag t) and then try again? This time the prettier (local) buffer shouldn't vanish after the crash and hopefully there's going to be something useful in it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jscheid/prettier.el/issues/71#issuecomment-771119995, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADYWBBBOMUFH6PBO3KOSRG3S44CCTANCNFSM4W4KBW2Q.

jscheid commented 3 years ago

That bug has long been fixed. You said you're using prettier.el 1.1 but in your prettier-info I can see that it's in fact 1.0. Upgrade to the latest and you should be fine.

MPE2016 commented 3 years ago

Well, consider this one the consequences of a prolonged lockdown:D.

I turns out I've been looking at my package list in the wrong way. I just updated, and everything is fine now.

Thanks so much for your patience:)

Maarten

Op dinsdag 2 februari 2021 om 0u51 schreef Julian Scheid notifications@github.com:

That bug has long been fixed. You said you're using prettier.el 1.1 but in your prettier-info I can see that it's in fact 1.0. Upgrade to the latest and you should be fine.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jscheid/prettier.el/issues/71#issuecomment-771474290, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADYWBBCCFEWOQ2UXOUEUZXLS464KRANCNFSM4W4KBW2Q.

jscheid commented 3 years ago

No problem, glad it's working now.