A text editor that auto-folds parentheses?

邮差的信 提交于 2019-12-22 01:41:02

问题


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?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/1687281/a-text-editor-that-auto-folds-parentheses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!