Skip to content

Unexpected indentation in Polymode #49

@flooose

Description

@flooose

I work a lot in with ruby, where our tests have a lot of graphql queries written in HEREDOCs. I've written the following polymode definition to allow graphql-mode nested in ruby-mode:

(require 'polymode)
(define-hostmode poly-ruby-hostmode :mode 'ruby-mode)

(define-innermode poly-ruby-gql-metadata-innermode
  :mode 'graphql-mode
  :head-matcher ".*<<[~-]GRAPHQL\n"
  :tail-matcher ".*GRAPHQL\n"
  :head-mode 'host
  :tail-mode 'host)

(define-polymode poly-ruby-mode
  :hostmode 'poly-ruby-hostmode
  :innermodes '(poly-ruby-gql-metadata-innermode))

which allows me to write the following in ruby:

def bla
  blubb = <<~GRAPHQL
  query bla($parent: Int) {
  foo
  bar {
    id
    babar {
      id
      type
    }
  }
  }
  GRAPHQL
end

As you can see the indentation works for all but the first and the last lines. For me the expectation would be that these lines are also indented and every indentation after is relative to this first indentation, like in this buffer that only has graphql-mode active (i.e. no polymode).

query bla($parent: Int) {
  foo
  bar {
    id
    babar {
      id
      type
    }
  }
}

I was able to reproduce the error by defining a polymode for sh-mode, which also supports HEREDOCs

(require 'polymode)
(define-hostmode poly-sh-hostmode :mode 'sh-mode)

(define-innermode poly-sh-gql-metadata-innermode
  :mode 'graphql-mode
  :head-matcher ".*<<[~-]GRAPHQL\n"
  :tail-matcher ".*GRAPHQL\n"
  :head-mode 'host
  :tail-mode 'host)

(define-polymode poly-sh-mode
  :hostmode 'poly-sh-hostmode
  :innermodes '(poly-sh-gql-metadata-innermode))

here's the result:

echo 'this is a sh-mode buffer'

bla=<<-GRAPHQL
  query($parent: Int) {
  foo
  bar {
    id
    babar {
      id
      type
    }
  }
}
GRAPHQL

echo 'no longer in the HEREDOC'

If this really is a graphql-mode issue, I'd be happy to take a look at the code, you just have to point me in the right direction.

Thank you in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions