Add Better code folding
Better code folding
By default, sublime text use "%(fold)" and "%...(end)" marks and "tabs" to identify code folding sections in latex source files.
This feature supplies a better code folding behavior. It can recognize "%(fold)" and "%...(end)" mark pairs, if you forget to use this mark, it all OK too. If the marks of "%(fold)" and "%...(end)" are not used, it will auto pair the code folding sections to the next same level's "section start mark" or "parents' start marks". For example, for the code bellow:
\section{hello} % (fold)
hello world, hello world.
hello world, hello world.
hello world, hello world.
hello world, hello world.
% section hello (end)
\section{hello too} %(fold)
hello world, too
hello world, too
hello world, too
hello world, too
hello world, too
\section{hello again?}
hello again? I am tired.
wil be folded to
\section{hello} % (fold)...
% section hello (end)
\section{hello too} %(fold)...
\section{hello again?}...
shortcut for code folding
Better code folding can ONLY be used by shortcuts! By default, all of the shortcut bellow can be used.
"Alt+Super+[", "Super+k, Super+1", "Super+k, Super+2", "Super+k, Super+3", ... "Super+k, Super+7" are now can be used in latex source file even there are no "tab" used in source files.
And there are three special shortcuts, which are: "Super+k, Super+o": unfold current foding. I don't know why set this command to the shortcut of "Alt+Super+]" does not work for me, so I set it to "Super+k, Super+o" as alternative.
"Super+k, Super+9": fold whole buffer to "Table of Content", which is called "fold to toc".
"Super+k, Super+0": fold whole buffer to TOC but keep the current editing section unfold.
About fold_to_toc command
Example of fold to toc(Super+k, Super+9) is like this:
If source cod is :
\chapter{chapter1}
Content before section of hello.
\section{hello} % (fold)
hello world, hello world.
hello world, hello world.
hello world, hello world.
hello world, hello world.
% section hello (end)
\section{hello too} %(fold)
hello world, too
hello world, too
hello world, too
\subsection{hell subsection}
hello world, too
hello world, too
\section{hello again?}
hello again? I am tired.
will be fold to
\chapter{chapter1}...
\section{hello} % (fold)...
\section{hello too} %(fold)...
\subsection{hell subsection}...
\section{hello again?}...
if "Super+k, Super+0" is triggered, it will be folded to
\chapter{chapter1}...
\section{hello} % (fold)...
\section{hello too} %(fold)...
\subsection{hell subsection}
hello world, too
hello world, too
\section{hello again?}...
it can be seen that the in the fold to toc command, fold marks of "%(fold)" and "%...(end)" are ignored.
"fold_toc_depth" options
There is a "fold_toc_depth" option, which controls the depth of fold_to_toc command fold the buffer. When "fold_toc_depth" is not set, 4 will be used as default value. If option is set to
"fold_toc_depth": 2
in LaTeXtools config files, and the code like
\chapter{chapter1}
Content before section of hello.
\section{hello} % (fold)
hello world, hello world.
hello world, hello world.
hello world, hello world.
hello world, hello world.
% section hello (end)
\section{hello too} %(fold)
hello world, too
hello world, too
hello world, too
\subsection{hell subsection}
hello world, too
hello world, too
\section{hello again?}
hello again? I am tired.
will be folded to
\chapter{chapter1}...
\section{hello} % (fold)...
\section{hello too} %(fold)...
\section{hello again?}...
which means \subsection, \subsubsection and others will be folded into \subsection
About extreme fold
These is another fold mode called extreme fold. When extreme fold is used, all fold marks of "%(fold)" and "%...(end)" will be ignored. extreme fold is used only in "fold to toc" by default, but it can be set to other scopes by change the "extreme_fold" option in "laTeXTools.sublime-settings". Detailed description can be found in "laTeXTools.sublime-settings" file.
Thank you for these patches! Now I really have no excuse not to pull them in! On Sep 19, 2014 12:04 AM, "btstream" [email protected] wrote:
Better code folding
By default, sublime text use "%(fold)" and "%...(end)" marks and "tabs" to identify code folding sections in latex source files.
This feature supplies a better code folding behavior. It can recognize "%(fold)" and "%...(end)" mark pairs, if you forget to use this mark, it all OK too. If the marks of "%(fold)" and "%...(end)" are not used, it will auto pair the code folding sections to the next same level's "section start mark" or "parents' start marks". For example, for the code bellow:
\section{hello} % (fold) hello world, hello world. hello world, hello world. hello world, hello world. hello world, hello world. % section hello (end) \section{hello too} %(fold) hello world, too hello world, too hello world, too hello world, too hello world, too \section{hello again?} hello again? I am tired.
wil be folded to
\section{hello} % (fold)...% section hello (end) \section{hello too} %(fold)...\section{hello again?}...
shortcut for code folding
Better code folding can ONLY be used by shortcuts! By default, all of the shortcut bellow can be used.
"Alt+Super+[", "Super+k, Super+1", "Super+k, Super+2", "Super+k, Super+3", ... "Super+k, Super+7" are now can be used in latex source file even there are no "tab" used in source files.
And there are three special shortcuts, which are: "Super+k, Super+o": unfold current foding. I don't know why set this command to the shortcut of "Alt+Super+]" does not work for me, so I set it to "Super+k, Super+o" as alternative.
"Super+k, Super+9": fold whole buffer to "Table of Content", which is called "fold to toc".
"Super+k, Super+0": fold whole buffer to TOC but keep the current editing section unfold. About fold_to_toc command
Example of fold to toc(Super+k, Super+9) is like this:
If source cod is :
\chapter{chapter1}
Content before section of hello. \section{hello} % (fold) hello world, hello world. hello world, hello world. hello world, hello world. hello world, hello world. % section hello (end) \section{hello too} %(fold) hello world, too hello world, too hello world, too \subsection{hell subsection}
hello world, too hello world, too \section{hello again?} hello again? I am tired.
will be fold to
\chapter{chapter1}...\section{hello} % (fold)...\section{hello too} %(fold)...\subsection{hell subsection}...\section{hello again?}...
if "Super+k, Super+0" is triggered, it will be folded to
\chapter{chapter1}...\section{hello} % (fold)...\section{hello too} %(fold)...\subsection{hell subsection}
hello world, too hello world, too \section{hello again?}...
it can be seen that the in the fold to toc command, fold marks of "%(fold)" and "%...(end)" are ignored. "fold_toc_depth" options
There is a "fold_toc_depth" option, which controls the depth of fold_to_toc command fold the buffer. When "fold_toc_depth" is not set, 4 will be used as default value. If option is set to
"fold_toc_depth": 2
in LaTeXtools config files, and the code like
\chapter{chapter1}
Content before section of hello. \section{hello} % (fold) hello world, hello world. hello world, hello world. hello world, hello world. hello world, hello world. % section hello (end) \section{hello too} %(fold) hello world, too hello world, too hello world, too \subsection{hell subsection}
hello world, too hello world, too \section{hello again?} hello again? I am tired.
will be folded to
\chapter{chapter1}...\section{hello} % (fold)...\section{hello too} %(fold)...\section{hello again?}...
which means \subsection, \subsubsection and others will be folded into \subsection About extreme fold
These is another fold mode called extreme fold. When extreme fold is used, all fold marks of "%(fold)" and "%...(end)" will be ignored. extreme fold is used only in "fold to toc" by default, but it can be set to other scopes by change the "extreme_fold" option in "laTeXTools.sublime-settings".
Detailed description can be found in "laTeXTools.sublime-settings" file.
You can merge this Pull Request by running
git pull https://github.com/btstream/LaTeXTools BetterCodeFolding
Or view, comment on, or merge it at:
https://github.com/SublimeText/LaTeXTools/pull/433 Commit Summary
- Add LaTeX-cwl auto-completion support
- Revert "Revert 517c5a3..bcc745f"
- Add Better Fold Sections
File Changes
- M Default (Linux).sublime-keymap https://github.com/SublimeText/LaTeXTools/pull/433/files#diff-0 (68)
- M Default (OSX).sublime-keymap https://github.com/SublimeText/LaTeXTools/pull/433/files#diff-1 (80)
- M Default (Windows).sublime-keymap https://github.com/SublimeText/LaTeXTools/pull/433/files#diff-2 (68)
- A latexFoldSection.py https://github.com/SublimeText/LaTeXTools/pull/433/files#diff-3 (354)
Patch Links:
- https://github.com/SublimeText/LaTeXTools/pull/433.patch
- https://github.com/SublimeText/LaTeXTools/pull/433.diff
— Reply to this email directly or view it on GitHub https://github.com/SublimeText/LaTeXTools/pull/433.
Is the patch in effect in the latest LaTeXTools?
The shortcuts does not work even when there are %(fold) and %...(end) pairs. I have to indent each line to make folding work.
Thank you.
Not yet... Sorry! I do plan on pulling it as soon as I have some time this summer. On Aug 5, 2015 10:37 AM, "Zack" [email protected] wrote:
Is the patch in effect in the latest LaTeXTools?
The shortcuts does not work even when there are %(fold) and %...(end) pairs. I have to indent each line to make folding work.
Thank you.
— Reply to this email directly or view it on GitHub https://github.com/SublimeText/LaTeXTools/pull/433#issuecomment-127915445 .
This sounds like a great feature! Hopefully it gets pulled in!