1
1
Fork
You've already forked pgsql.vim
0

Fold SQL statements #19

Closed
mgedmin wants to merge 1 commit from folding into master
pull from: folding
merge into: lifepillar:master
lifepillar:master
mgedmin commented 2020年10月02日 13:05:13 +02:00 (Migrated from github.com)
Copy link

This is based on the way vim's default sqloracle.vim defines folds. A fold starts with a keyword like CREATE and ends with a ; at the end of a line.

There might be some regressions, e.g. I think CREATE OR REPLACE FUNCTION ... is now getting highlighted incorrectly.

This is a draft PR because I edited the generated .vim instead of src/pgsql.sql. I just want to know if the approach seems reasonable, or if there's a better way of doing folds, or maybe if you would like a variable check to enable/disable folding in a user's .vimrc?

Closes: #18.

This is based on the way vim's default [sqloracle.vim](https://github.com/vim/vim/blob/master/runtime/syntax/sqloracle.vim) defines folds. A fold starts with a keyword like CREATE and ends with a ; at the end of a line. There might be some regressions, e.g. I think `CREATE OR REPLACE FUNCTION ...` is now getting highlighted incorrectly. This is a draft PR because I edited the generated .vim instead of src/pgsql.sql. I just want to know if the approach seems reasonable, or if there's a better way of doing folds, or maybe if you would like a variable check to enable/disable folding in a user's .vimrc? Closes: #18.
lifepillar commented 2020年10月02日 20:18:57 +02:00 (Migrated from github.com)
Copy link

This may be a useful addition. That is the correct way to define folding based on syntax, AFAIK. There is no need for additional variables: foldmethod can be set according to one's preferences.

There might be some regressions

Maybe they can be fixed by reordering the syntax statements (see :h syn-priority)?

This may be a useful addition. That is the correct way to define folding based on syntax, AFAIK. There is no need for additional variables: `foldmethod` can be set according to one's preferences. >There might be some regressions Maybe they can be fixed by reordering the syntax statements (see `:h syn-priority`)?
mgedmin commented 2020年10月03日 11:54:27 +02:00 (Migrated from github.com)
Copy link

Maybe they can be fixed by reordering the syntax statements (see :h syn-priority)?

I tried that, but if I move sqlFold above syn match sqlStatement /\<create\_s\+or\_s\+replace\>/, that breaks folding for the CREATE OR REPLACE statement. I also tried adding contained to the syn match, but then it remains not highligted as one thing, no mater where it's placed in relation to sqlFold.

> Maybe they can be fixed by reordering the syntax statements (see :h syn-priority)? I tried that, but if I move sqlFold above `syn match sqlStatement /\<create\_s\+or\_s\+replace\>/`, that breaks folding for the `CREATE OR REPLACE` statement. I also tried adding `contained` to the `syn match`, but then it remains not highligted as one thing, no mater where it's placed in relation to sqlFold.
lifepillar commented 2020年10月03日 15:18:04 +02:00 (Migrated from github.com)
Copy link

Ok then, I'll merge this locally and see how that can be fixed.

Ok then, I'll merge this locally and see how that can be fixed.
lifepillar commented 2020年10月03日 18:45:01 +02:00 (Migrated from github.com)
Copy link

Can you test the current master? I have merged this and fixed the issue with highlighting. For some reason, GitHub didn't close this automatically (maybe because I have added a commit to your branch), so I am closing this manually. You appear as a contributor in the home page, anyway.

Labai ačiū!

Edit: fixed my bad attempt at Lithuanian!

Can you test the current master? I have merged this and fixed the issue with highlighting. For some reason, GitHub didn't close this automatically (maybe because I have added a commit to your branch), so I am closing this manually. You appear as a contributor in the home page, anyway. Labai ačiū! **Edit:** fixed my bad attempt at Lithuanian!
mgedmin commented 2020年10月03日 19:09:30 +02:00 (Migrated from github.com)
Copy link

Yep, works great. Folding and highlighting. Thank you for fixing up my amateurish attempts!

Yep, works great. Folding _and_ highlighting. Thank you for fixing up my amateurish attempts!
mgedmin commented 2020年10月03日 19:15:05 +02:00 (Migrated from github.com)
Copy link

For some reason, GitHub didn't close this automatically (maybe because I have added a commit to your branch), so I am closing this manually.

I think it's because I pushed a 2nd commit to this branch (updating src/pgpsql.sql), but you merged only the 1st one.

I see you fixed the highlighting issue by dropping the syn keyword create and changing the syn match on "create or replace" to "create" optionally followed by "or replace", and made it contained. Clever!

> For some reason, GitHub didn't close this automatically (maybe because I have added a commit to your branch), so I am closing this manually. I think it's because I pushed a 2nd commit to this branch (updating src/pgpsql.sql), but you merged only the 1st one. I see you fixed the highlighting issue by dropping the `syn keyword create` and changing the `syn match` on "create or replace" to "create" optionally followed by "or replace", and made it contained. Clever!
lifepillar commented 2020年10月03日 19:46:27 +02:00 (Migrated from github.com)
Copy link

Ah, sorry, I had totally missed that!

Ah, sorry, I had totally missed that!

Pull request closed

This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lifepillar/pgsql.vim!19
Reference in a new issue
lifepillar/pgsql.vim
No description provided.
Delete branch "folding"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?