A text editor that auto-folds parentheses?

2019-04-15 07:13发布

I have some big messy SQL procedures that I'm debugging, and they tend to have a lot of heavily nested parentheses:

SELECT * FROM (SELECT F1,F2 FROM TABLE1 AS X LEFT JOIN 
(SELECT F9,F8 FROM (SELECT F13,F14 FROM TABLE4) AS J INNER JOIN TABLE3 ON...) AS B 
ON X.F1=B.F9) AS X1

I'm looking for an editor that can automatically mark and optionally collapse/fold each parentheses set to ease reading, e.g.

SELECT * FROM ... AS X1

SELECT * FROM (SELECT F1,F2 FROM TABLE1 AS X LEFT JOIN ... AS B ON X.F1=B.F9) AS X1

I can do this in Visual Studio by repeatedly hitting ctrl-shift-] to select a set, and then ctrl-mh to collapse it. But some of these things are hundreds of lines long and it would be nice if I had an editor that could mark up the whole document automatically.

Any suggestions?

4条回答
狗以群分
2楼-- · 2019-04-15 07:30

I don't think it'll do your folding, but if you're using SQL Server I'd highly recommend SQL Prompt which includes a command to reformat SQL. I've found this to be a massive help when debugging/understanding huge and unwieldy stored procedures.

查看更多
趁早两清
3楼-- · 2019-04-15 07:42

Edit: Nevermind, it doesn't work. ) isn't being treated as close. Leaving the answer so nobody else wastes their time trying it.

If you're willing to split the lines so there's only one open or close parenthesis on a line, you can use the User Define Language in Notepad++ and make ( and )the folder open and close, respectively. You can also define the SQL keywords and comment delimiters so they get colored. Notepad++ has SQL built in of course, but the built in definition doesn't fold on parentheses.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-04-15 07:44

I have a need to do a similar thing. I posted a request for comments and suggests (an RFC you could say). The link to it is here: Stack Overflow. I'm surprised its not a standard feature in most editors.. I guess the issue is that it's harder than it looks to parse delimited blocks of text out of a stream of characters. Maybe XML and CSS will make it easier to do thins type of thing in the future.

查看更多
Evening l夕情丶
5楼-- · 2019-04-15 07:51

See HideShow mode for emacs, which does exactly what you want in lisp-mode.

查看更多
登录 后发表回答