vue-mode icon indicating copy to clipboard operation
vue-mode copied to clipboard

Indentation problems in <script> tags

Open Yamakaky opened this issue 6 years ago • 35 comments

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?

Yamakaky avatar Apr 08 '18 10:04 Yamakaky

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?

AdamNiederer avatar Apr 08 '18 19:04 AdamNiederer

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

Yamakaky avatar Apr 10 '18 18:04 Yamakaky

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

AdamNiederer avatar Apr 12 '18 00:04 AdamNiederer

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

Yamakaky avatar Apr 14 '18 08:04 Yamakaky

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>

AdamNiederer avatar Apr 14 '18 23:04 AdamNiederer

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

Yamakaky avatar Apr 15 '18 11:04 Yamakaky

Yep, still unable to reproduce.

AdamNiederer avatar Apr 15 '18 18:04 AdamNiederer

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

BlindingDark avatar Jun 21 '18 07:06 BlindingDark

Hum, could be it

Yamakaky avatar Jun 23 '18 16:06 Yamakaky

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 ?

differentMonster avatar Jan 28 '19 04:01 differentMonster

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

aki-s avatar Sep 04 '19 23:09 aki-s

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

felipebalbi avatar Sep 05 '19 08:09 felipebalbi

@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)))

pashinin avatar Sep 05 '19 20:09 pashinin

@pashinin should be something like so:

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

felipebalbi avatar Sep 06 '19 09:09 felipebalbi

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

pera avatar Oct 02 '19 18:10 pera

for me syntax-ppss-table does not exist.

bhanuvrat avatar Oct 05 '19 16:10 bhanuvrat

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

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

jcs090218 avatar Oct 07 '19 15:10 jcs090218

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)))

lzhoucs avatar Oct 08 '19 21:10 lzhoucs

no syntax-ppss-table for me either.

syrkuit avatar Nov 25 '19 18:11 syrkuit

(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

azzamsa avatar Dec 13 '19 12:12 azzamsa

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

pbgc avatar Dec 13 '19 14:12 pbgc

@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

azzamsa avatar Dec 14 '19 03:12 azzamsa

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.

Stazer avatar Dec 19 '19 20:12 Stazer

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.

machack666 avatar Jan 22 '20 19:01 machack666

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

sp3c73r2038 avatar Apr 03 '20 06:04 sp3c73r2038

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

srcrip avatar Apr 17 '20 23:04 srcrip

~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 avatar Nov 05 '20 13:11 AlexDaniel

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 avatar Nov 05 '20 13:11 AlexDaniel

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. :(

AlexDaniel avatar Nov 05 '20 15:11 AlexDaniel

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

pbgc avatar Nov 05 '20 15:11 pbgc