reddit / emacs

Function to fold all paragraphs in a text file?

LowCom · 2022-05-13 04:43
I have many text and code files where the first line of a paragraph is enough to know what the para does. So folding all paragraphs gives me a quick overview of the file.
grimman · 2022-05-13 05:22
Folding after the topic sentence is something I looked for a while back as well, to no avail. The worst part is I could have sworn I saw something like that long ago, but didn't think anything of it until I needed it myself.
[deleted] · 2022-05-13 05:42
[deleted]
Horrih · 2022-05-13 05:56
Well if you have a regexp to tell where the paragraph starts you can use outline mode. It provides folding by level. This was the basis of org mode. If you are editing code, hide-show mode can do that as well if i'm not mistaken, based on the brackets/indentation
globalcandyamnesia · 2022-05-13 06:04
Selective display may fit your needs: `M-2 C-x $` hides all lines indented by more than two spaces, and `C-x $` will reset it.
7890yuiop · 2022-05-13 06:57
Yes. There's nothing stopping you or anyone else from writing code which does this. Having a programmable editor doesn't mean that other people have already written all of the programs which you personally might want -- but it does mean that you can write those features yourself, if they don't exist yet. (Someone scratching an itch is generally how new features arise.)
notperm · 2022-05-13 06:58
If it’s so basic write some elisp to do it yourself.
LowCom · 2022-05-13 08:37
But my paragraphs are not indented at all. They are just separated by empty lines.
LowCom · 2022-05-13 08:39
The regexep would be new line plus empty line I guess. I don't the exact syntax for this.
ndamee · 2022-05-13 09:37
You could post an example file, so we can see exactly how it's structured. It's easier to help then.
_viz_ · 2022-05-13 09:57
How does setting outline-regexp to [ \\t]*$ and turning on outline-mode work for you? (outline-minor-mode should also work just fine.)
bdarcus · 2022-05-13 10:42
I asked this here a couple of years ago. [https://www.reddit.com/r/orgmode/comments/fc2zhs/show\_first\_line\_only\_option\_for\_displaying/](https://www.reddit.com/r/orgmode/comments/fc2zhs/show_first_line_only_option_for_displaying/) The solution that worked for me was origami mode. [https://github.com/gregsexton/origami.el](https://github.com/gregsexton/origami.el) However, this package doesn't appear to be maintained (though there's now a [fork](https://github.com/elp-revive/origami.el)). This is another alternative, with a slightly different result with paragraphs. [https://github.com/matsievskiysv/vimish-fold](https://github.com/matsievskiysv/vimish-fold) I was also hoping to figure out how to [integrate this paragraph folding into org visibility cycling](https://list.orgmode.org/87d085xlte.fsf@nicolasgoaziou.fr/T/), but never did. I need to take another look at that when I get time.
cazzipropri · 2022-05-13 12:54
yafolding-hide-all
MrTinyToes · 2022-05-13 14:01
It sounds like all you need is to write regexp that matches a single sentence (accepts all characters from beginning of line until a period, or something) at the beginning of a line. Play around with regexp-builder, setting outline-regexp, and seeing what happens in outline-(minor-)mode.
PawarShubham3007 · 2022-05-13 17:22
Look into hs-minor-mode
Salty_Influence_5113 · 2022-05-13 20:11
Emacs have narrow approach. It's better than folding.
LowCom · 2022-05-14 03:20
How do I set this variable, I am not familiar with this mode
LowCom · 2022-05-14 03:20
Any page with some paragraphgs. This is an example below. Horse racing has a long and distinguished history and has been practised in civilisations across the world since ancient times. Archaeological records indicate that horse racing occurred in Ancient Greece, Ancient Rome, Babylon, Syria, and Egypt.[5] It also plays an important part of myth and legend, such as the contest between the steeds of the god Odin and the giant Hrungnir in Norse mythology. Chariot racing was one of the most popular ancient Greek, Roman and Byzantine sports. Both chariot and mounted horse racing were events in the ancient Greek Olympics by 648 BC[6] and were important in the other Panhellenic Games. It continued although chariot racing was often dangerous to both driver and horse, which frequently suffered serious injury and even death. In the Roman Empire, chariot and mounted horse racing were major industries.[7] From the mid-fifteenth, spring carnival in Rome closed with a horse race. Fifteen to 20 riderless horses, originally imported from the Barbary Coast of North Africa, were set loose to run the length of the Via del Corso, a long, straight city street; their time was about 2+1⁄2 minutes. In later times, Thoroughbred racing became, and remains, popular with aristocrats and royalty of British society, earning it the title "Sport of Kings".[8] Historically, equestrians honed their skills through games and races. Equestrian sports provided entertainment for crowds and displayed the excellent horsemanship needed in battle. Horse racing of all types evolved from impromptu competitions between riders or drivers. The various forms of competition, requiring demanding and specialized skills from both horse and rider, resulted in the systematic development of specialized breeds and equipment for each sport. The popularity of equestrian sports through the centuries has resulted in the preservation of skills that would otherwise have vanished after horses stopped being used in combat.[9] In Britain, horse racing became well-established in the 18th century. It continued to grow in popularity throughout the 18th and beyond. King Charles II (reigned 1649 to 1685) was an avid sportsman who gave Newmarket its prominence. By 1750 the Jockey Club was formed to control the Newmarket races, set the rules of the game, prevent dishonesty, and making for a level field.[10] Epsom Derby began in 1780. The five classic races began with the St Leger Stakes in 1776. The system was complete in 1814 with five annual races.[11] Newmarket and the Jockey Club set the standards but most of the racing took place for small cash prizes and enormous local prestige in landowners’ fields and in the rising towns. The system of wagering was essential to the funding and the growth of the industry, and all classes participated from the poor to royalty. High society was in control, and they made a special effort to keep the riff-raff out and the criminal element away from the wagering. With real money at stake, the system needed skilled jockeys, trainers, grooms, and experts at breeding, thereby opening new prestigious careers for working-class rural men. Every young ambitious stable boy could dream of making it big.[12] Horse racing is one of the few sports that has continued during the 2020 COVID-19 crisis,[13] with Australian and Hong Kong the two main racing jurisdictions to carry on, albeit with no crowds. The USA, United Kingdom and France were some of the more prominent racing bodies to either postpone or cancel all events.
_viz_ · 2022-05-14 04:18
`(setq outline-regexp "[ \\t]*$")` is how you would normally do it. I will probably add a Local Variables: section at the end of file and set outline-regexp there using the add-file-local-variable command.