Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation problems in <script> tags #74

Open
Yamakaky opened this issue Apr 8, 2018 · 35 comments
Open

Indentation problems in <script> tags #74

Yamakaky opened this issue Apr 8, 2018 · 35 comments

Comments

@Yamakaky
Copy link

Yamakaky commented Apr 8, 2018

Often, when I open a .vue file, the indentation in the <script> tag is broken, with new lines aligned on the left. Sometimes, the indentation is correct when I open a file, I don't know why. Are you aware of this kind of problem?

I have a big spacemacs config, I will try to bisect the problem some time.

As a quick-fix, is there a way to force vue-mode to use the js indentation mode?

@AdamNiederer
Copy link
Owner

vue-mode already uses js-mode's indenation function via mmm-mode. Could you post a snippet in which you observe this behavior, and your installed versions of emacs, vue-mode, and mmm-mode?

@Yamakaky
Copy link
Author

Yamakaky commented Apr 10, 2018

I did some progress.
https://0bin.net/paste/-xcYpHw9K14DhHCD#lu0DluLNFacuTV2Hcik+-C4kHA6e8cc1xxpAFzyv88E
If I "space q R" while in the <template> tag then reopen the file with "space f r", indentation works fine. If I'm in the <script> or <style> tag, the indentation is off.
mmm-mode 0.5.5
vue-mode 20180105.111
emacs 25.3.1

@AdamNiederer
Copy link
Owner

It looks like your paste has expired. Could you dump a minimal example in a comment here?

@Yamakaky
Copy link
Author

Oops, sorry https://0bin.net/paste/6nm9WpmEwN9ecM0S#H5om5vukLPRKvV4hVVTpa5lvSw+PYkS5Wv-I2IVyAGm
I tried to trim it down, but sometimes the indentation problem is fixed...

@AdamNiederer
Copy link
Owner

Looks good to me; this is what I get when indenting the whole component

<script>
export default {
  data() {
    return {
      username: null,
      password: null,
      error: false,
    }
  },
  
  methods: {
    login() {
      if (!this.seems_good) {
        return false
      }
      
      const success = () => this.$router.push({ name: "root" })
      const error = () => {
        this.error = true
        this.password = null
      }
      this.$store.dispatch('reconnect', {
        username: this.username,
        password: this.password,
      }).then(success, error)
    },
  },
  
  computed: {
    seems_good() {
      return !!(this.username && this.password)
    },
  },
}
</script>

@Yamakaky
Copy link
Author

Hum, did you try the instructions in my 2nd post?

@AdamNiederer
Copy link
Owner

Yep, still unable to reproduce.

@BlindingDark
Copy link

I think > in arrow function cause this problem.
seems it treat this as a tag (<>)

@Yamakaky
Copy link
Author

Hum, could be it

@differentMonster
Copy link

i am having the same problem , the script tag and my js code is all white , sometimes it detect as js file , is there any way to fix it ?

@aki-s
Copy link

aki-s commented Sep 4, 2019

Hi, I had the same problem.
If I set syntax-ppss-table to nil in the buffer where this problem happens, then this problem is fixed.

My env

  • Emacs26.3 (Ubuntu 18)
  • vue-mode 20190415.231
  • lsp-vue 20181030.1136

@felipebalbi
Copy link

felipebalbi commented Sep 5, 2019

Same thing here. Setting syntax-ppss-table to nil solves it as well

  • Emacs 26.3 (Arch Linux)
  • vue-mode 20190415.231
  • lsp-vue 20181030.1136

@pashinin
Copy link

pashinin commented Sep 5, 2019

@aki-s, @felipebalbi How to do it automatically? Tried some hooks.. didn't work.

Edit: something like this:

(setq mmm-js-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))
(setq mmm-typescript-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))

@felipebalbi
Copy link

@pashinin should be something like so:

(add-hook 'js-mode-hook (lambda () (setq syntax-ppss-table nil)))

@pera
Copy link

pera commented Oct 2, 2019

Setting syntax-ppss-table to nil also fixed the issue to me, are there any side effects? couldn't quite understand the docs

@bhanuvrat
Copy link

for me syntax-ppss-table does not exist.

@jcs090218
Copy link

jcs090218 commented Oct 7, 2019

I got indentation error in script tag with multi-line comment in here. Anyone having the same issue?

<script>
/**
 *
 */
</script>

@lzhoucs
Copy link

lzhoucs commented Oct 8, 2019

ran into the same issue on 26.3. Switching to 26.2 works, with the exact same packages and config.

Tried the following fix but it doesn't seem to work.

(add-hook 'js-mode-hook (lambda () (setq syntax-ppss-table nil)))

Tried the following and it works.

(setq mmm-js-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))
(setq mmm-typescript-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))

elim added a commit to elim/dotemacs that referenced this issue Oct 18, 2019
@syrkuit
Copy link

syrkuit commented Nov 25, 2019

no syntax-ppss-table for me either.

@azzamsa
Copy link

azzamsa commented Dec 13, 2019

(setq mmm-js-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))
(setq mmm-typescript-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))

didn't work for me. Emacs 26.1

@pbgc
Copy link

pbgc commented Dec 13, 2019

@azzamsa The problem only occurs with Emacs 23.3 ... with 26.1 and 26.2 you should not need those lines

@azzamsa
Copy link

azzamsa commented Dec 14, 2019

@pbgc yes. Turns out I've put wrong line (add-hook 'vue-mode-hook #'prettier-js). Everything works out-of the box after removing it.

I am using stock Emacs, and I've documented the steps here Setup Emacs for Vue.js Development

@Stazer
Copy link

Stazer commented Dec 19, 2019

ran into the same issue on 26.3. Switching to 26.2 works, with the exact same packages and config.

Tried the following fix but it doesn't seem to work.

(add-hook 'js-mode-hook (lambda () (setq syntax-ppss-table nil)))

Tried the following and it works.

(setq mmm-js-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))
(setq mmm-typescript-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))

Works for me as well with emacs 26.3 and spacemacs distribution. I just added the expression to the user-config block.

@machack666
Copy link

machack666 commented Jan 22, 2020

This worked for me (Emacs 26.3):

(add-hook 'vue-mode-hook (lambda () (setq syntax-ppss-table nil)))

Note the difference in the hook name compared to some of the answers above.

@sp3c73r2038
Copy link

sp3c73r2038 commented Apr 3, 2020

This worked for me (Emacs 26.3):

(add-hook 'vue-mode-hook (lambda () (setq syntax-ppss-table nil)))

Note the difference in the hook name compared to some of the answers above.

Confirmed working with Emacs 26.3

@srcrip
Copy link

srcrip commented Apr 17, 2020

Do we know why this happens and can this be set upstream in vue-mode instead of in all our configs?

@AlexDaniel
Copy link

AlexDaniel commented Nov 5, 2020

Doom Emacs (Emacs 27.1), the workaround does not work. When applied, indentation and syntax highlighting in <script> section starts working, but indentation breaks for <template>. (Actually, it works, read the comments below!)

@AlexDaniel
Copy link

Ah, it seems like some kind of fix was applied in mmm-mode, but the last release (0.5.7) was in 2018. That said, if you install the latest version from the git repo, the workaround mentioned in this ticket is no longer needed, highlighting and indentation works fine in <script> sections!

However, indentation in <template> is still broken :(

@AlexDaniel
Copy link

Taking my words back, it's just that the issue is very intermittent and honestly vue-mode right now is completely unusable with emacs 27. Very often it doesn't even detect the scoped sections, in which case mmm-parse-buffer can help a little bit. But even then, the syntax highlighting is usually broken unless you edit affected lines, and indentation is broken but in a very intermittent way. :(

@pbgc
Copy link

pbgc commented Nov 5, 2020

@AlexDaniel I use vue-mode with Emacs 27 (stock emacs with custom configuration) and lsp-mode everyday without any problem!

@pbgc
Copy link

pbgc commented Nov 5, 2020

@AlexDaniel my conf for vue is:

(require 'vue-mode)
(add-hook 'vue-mode-hook #'lsp-deferred)

(defun vuejs-custom ()
  (setq vue-html-tab-width 2)
  (global-set-key (kbd "C-c C-l") 'vue-mode-reparse)
  (global-set-key (kbd "C-c C-e") 'vue-mode-edit-indirect-at-point)
  (add-to-list 'write-file-functions 'delete-trailing-whitespace)
  (turn-on-diff-hl-mode))

(add-hook 'vue-mode-hook 'vuejs-custom)

(setq mmm-submode-decoration-level 0)

(defun js-custom ()
  (flycheck-mode t)
  (company-mode)
  (set (make-local-variable 'tab-width) 2)
  (setq js-indent-level 2))

(add-hook 'js-mode-hook 'js-custom)

(setq mmm-js-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))
(setq mmm-typescript-mode-enter-hook (lambda () (setq syntax-ppss-table nil)))

@AlexDaniel
Copy link

@pbgc thank you very much for your config! I think you're right. I managed to get it working more or less (but mostly more!). Knowing that it works for you, I started digging. Turns out there was a conflict with hl-todo package. I disabled hl-todo for now, and vue-mode seems to be working! Thank you!

@AlexDaniel
Copy link

Actually, no, it is very broken, I'd say even unusable. There's at least one very explicit issue, which is reported here: dgutov/mmm-mode#112

When using it, it constantly loses highlighting and almost always gets confused about indentation.

@pbgc
Copy link

pbgc commented Jan 16, 2021

@AlexDaniel I'm using:

Emacs 27.1
vue-mode 20190415.231
mmm-mode 20200908.2236

and I DON'T have those problems and use vue mode every single day!
Occasionally a little glitch but nothing major! and the experience with this setup and lsp mode for vue files is great!

@AlexDaniel
Copy link

Occasionally a little glitch

Yeah, it is much more often for me than just occasionally. Good to know that it is also buggy for you, so it's not just my setup.

I tried this approach and it works: #109

We'll see how it goes, but so far it is almost perfect.

tomiacannondale added a commit to tomiacannondale/dot.emacs.d that referenced this issue Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests