Skip to content

Leave everything inside #| ... |# as is#12

Open
iamFIREcracker wants to merge 2 commits intods26gte:masterfrom
iamFIREcracker:commented-out-regions
Open

Leave everything inside #| ... |# as is#12
iamFIREcracker wants to merge 2 commits intods26gte:masterfrom
iamFIREcracker:commented-out-regions

Conversation

@iamFIREcracker
Copy link

Imagine you had a file that looked like this:

#|
I like quotes:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.  Nam hendrerit
    nisi sed sollicitudin pellentesque.
|#
(define hello-world ()
  (format t "Hello, world!~%"))

Feed it to lispindent and you would get back something like this (note
how the last line gets aligned to the indented _quote):

#|
I like quotes:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.  Nam hendrerit
    nisi sed sollicitudin pellentesque.
    |#
(define hello-world ()
  (format t "Hello, world!~%"))

In addition, lispindent would now assume everything needed an extra
4 space of indentation -- this does not show up in the example, because
the code is already properly indented.

Anyways, this commit tries to fix that by building a small state
machine
to handle with commented out regions:

  • First it waits for the # reader macro character, followed by |
    (i.e. the start marker for these commented out regions)
  • Then for | -- from this moment on, everything read from the input
    stream is kept as is
  • Then waits for a | character again, follwed by a # (i.e. the end
    of the region)

Imagine you had a file that looked like this:

    #|
    I like quotes:

        Lorem ipsum dolor sit amet, consectetur adipiscing elit.  Nam hendrerit
        nisi sed sollicitudin pellentesque.
    |#
    (define hello-world ()
      (format t "Hello, world!~%"))

Feed it to lispindent and you would get back something like this (note
how the last line gets aligned to the indented _quote):

    #|
    I like quotes:

        Lorem ipsum dolor sit amet, consectetur adipiscing elit.  Nam hendrerit
        nisi sed sollicitudin pellentesque.
        |#
    (define hello-world ()
      (format t "Hello, world!~%"))

In addition, lispindent would now assume everything needed an extra
4 space of indentation -- this does not show up in the example, because
the code is already _properly_ indented.

Anyways, this commit tries to fix that by building a small _state
machine_ to handle with commented out regions:

- First it waits for the `#` reader macro character, followed by `|`
  (i.e. the start marker for these commented out regions)
- Then for `|` -- from this moment on, everything read from the input
  stream is kept _as is_
- Then waits for a `|` character again, follwed by a `#` (i.e. the end
  of the region)
reader-macro-p was introduced to understand while inside a #| ... |#
block, and unless the character following the # is a |, we should just
reset the flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant