0

I'm using web-mode package.

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?

The config in .spacemacs

(defun dotspacemacs/user-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))))


dotspacemacs-configuration-layers
'(
┆ (typescript :variables
┆    ┆   ┆   ┆javascript-backend 'tide
┆    ┆   ┆   ┆typescript-fmt-tool 'prettier
┆    ┆   ┆   ┆typescript-linter 'eslint
┆    ┆   ┆   ┆typescript-fmt-on-save t)
11
  • Maybe your indent-level in this mode is 4 and when you paste the content, it auto indent. You can confirm it with press tab before name in your first snippet. Jun 15, 2022 at 3:33
  • @TianshuWang Yes, when I type tab it was 4 indent. Then how to change to 2 if use prettier and editorconfig? I already set them to 2. I'm using Spacemacs. Jun 15, 2022 at 4:16
  • FWIW pasting text doesn't normally trigger any kind of auto-indentation, so that part is something you've configured (I'm going to hazard a guess that you've installed the "aggressive indentation" package, as IIUC it does things like that).
    – phils
    Jun 15, 2022 at 5:15
  • @phils I checked the .spacemacs configuration and didn't find the package aggressive indentation. But I find out highlight-indentation. I don't know if it did the same thing. Jun 15, 2022 at 5:29
  • @phils This only happened for .tsx file but .ts file works well. I'm using web-mode. Jun 15, 2022 at 5:40

1 Answer 1

0

maybe you have enabled better-defaults layer in spacemacs, if so, then it will automatically indent when you paste (yank). In order to paste (yank) without indenting, then prefix the command with C-u

C-u C-y

3
  • Yes, I'm using better-defaults. But even I disable it still the same as before. I can't understand C-u C-y clearly. When I type it there happened nothing. Jun 16, 2022 at 0:18
  • C-u C-y means press Ctrl-u, then Ctrl-y
    – Arkan
    Jun 16, 2022 at 15:50
  • Another solution, this way works: emacs.stackexchange.com/a/57893/38278 Jun 17, 2022 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.