reddit / emacs

Why emacs editor changes indent automatically when copy a context into it?

HumanResult3379 · 2022-06-15 02:08
The source(`.tsx file`) in Emacs before: import React from "react"; export default { ... args: { name: "", // Here }, decorators, }; The source in Emacs after: import React from "react"; export default { ... args: { name: "Awesome", // Here }, decorators, }; I copied an `Awesome` text from other place and paste it to the editor, the indent changed from 2 to 4 at that line. Why it changed? How to avoid it?
yurikhan · 2022-06-15 04:59
Are you using `web-mode`? It has pretty aggressive autoindentation behavior. Try customizing `web-mode-code-indent-offset` and `web-mode-markup-indent-offset` to 2 or whatever fits your coding style.
[deleted] · 2022-06-15 05:34
[deleted]
HumanResult3379 · 2022-06-15 05:37
Yes, I'm using `web-mode`. This is my config: (defun tide-setup-hook () (tide-setup) (eldoc-mode) (tide-hl-identifier-mode +1) (setq web-mode-enable-auto-quoting nil) (setq web-mode-markup-indent-offset 2) (setq web-mode-code-indent-offset 2) (setq web-mode-attr-indent-offset 2) (setq web-mode-attr-value-indent-offset 2) (setq lsp-eslint-server-command '("node" (concat (getenv "HOME") "/var/src/vscode-eslint/server/out/eslintServer.js") "--stdio")) (set (make-local-variable 'company-backends) ┆ ┆'((company-tide company-files :with company-yasnippet) ┆ ┆ (company-dabbrev-code company-dabbrev)))) They are already been set to 2. The configuration-layer: ┆(typescript :variables ┆ ┆ ┆ ┆javascript-backend 'tide ┆ ┆ ┆ ┆typescript-fmt-tool 'prettier ┆ ┆ ┆ ┆typescript-linter 'eslint ┆ ┆ ┆ ┆typescript-fmt-on-save t)
yurikhan · 2022-06-15 05:41
Then I’m out of ideas, you might need to dive into edebug to see what variables are consulted.
vifon · 2022-06-15 16:26
Judging by you also pasting your indentation guides, are you using Emacs in a terminal? Emacs might not be able to differentiate between a user input and a paste when used this way.
HumanResult3379 · 2022-06-16 00:19
Yes, I'm using emacs in a terminal. But even I use it in a GUI tool still got the same issue.