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

Add menu item for formatting the source code #117

Open
rillig opened this issue Dec 30, 2019 · 1 comment
Open

Add menu item for formatting the source code #117

rillig opened this issue Dec 30, 2019 · 1 comment

Comments

@rillig
Copy link

rillig commented Dec 30, 2019

When I edit the source code of my program, the editor doesn't get the indentation correct:

  • Type demo :-, press Enter, press Backspace 4 times, press Tab, press Enter. Now the indentation uses a mixture of tabs and spaces, which will look wrong if the next editor has a different tab width.

Type the following text:

demo :-
	L = [
        [
        karte(A)
        ],
          [
          karte(B),
            ],
          ],
    write(L), nl.
  • The second [ should be indented by 4 more spaces.
  • The third [ should not be indented by an additional 2 spaces.
  • Each closing bracket should be aligned with its corresponding opening bracket.
  • The karte(B) should be indented by an additional 4 spaces.

To fix these, either the automatic indentation should be fixed, or at least there should be a menu item with which I can re-indent the existing code.

@JanWielemaker
Copy link
Member

There are a number of issue.

  • The list layout code expects the first element of the list on the same line as the [. It will then indent subsequent elements to the same level and align the final ] if it it is preceded by a newline. We could of course argue what should happen if the first argument is on a newline. AFAIK that is not very common in the Prolog world.
  • The failure to align after karte(B), and the last ] are due to the fact that there is a , after the last list element. That is not allowed in Prolog.
  • Re-layout of a block is done by selecting the block and using SHIFT-TAB. Without a selection SHIFT-TAB re-indents the current line.

See https://swish.swi-prolog.org/p/kGbNFuOK.pl

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

No branches or pull requests

2 participants