Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Collapse/fold code blocks? #128
Comments
|
I think this is a good idea. And no, markdown wont' be able to handle those chunks because they are out of its reach once you are in a chunk. It should be a key available in the whole buffer on polymode |
brendan-r
commented
May 24, 2017
•
|
Thought about taking a run at a PR for this, but I'm afraid my elisp fu is non-existent. Still, the following links might be useful; the built-in |
marcbrouard
commented
May 24, 2017
|
This would be incredibly useful for me. I have found polymode to be very useful for writing academic papers, but if I was able to collapse code blocks it would make life a great deal easier. Unfortunately my elisp is rudimentary at best, but willing to help if I can |
brendan-r
commented
Aug 24, 2017
•
|
Okay, yet to be thoroughly tested, but I think I've hacked together a solution using the It's in my dotemacs here, and below: (defun rmd-fold-block ()
"Fold the contents of the current R block, in an Rmarkdown file (can be undone
with fold-this-unfold-at-point)"
(interactive)
(and (eq (oref pm/chunkmode :mode) 'r-mode)
(pm-with-narrowed-to-span nil
(goto-char (point-min))
(forward-line)
(fold-this (point) (point-max)))))
(defun rmd-fold-all-blocks (arg)
"Fold all R blocks in an Rmarkdown file (can be undone with
fold-this-unfold-all)"
;; Interactive, with a prefix argument
(interactive "P")
(save-restriction
(widen)
(save-excursion
(pm-map-over-spans
'rmd-fold-block (point-min)
;; adjust this point to fold prior regions
(if arg (point) (point-max))))))It was cobbled together without much understanding, based on a stack-overflow answer about evaluating polymode regions. I'm sure there may be a sleeker solution, but it seems to work at the moment! So, I'm personally sorted (and happy to close the issue if you like), though I still think this would make a great 'native' feature for polymode. |
brendan-r commentedMar 7, 2017
•
edited
Hello there,
First, thanks for polymode!
Is it possible to collapse/fold code-blocks, like
markdown-modeallows with headings? Rstudio currently does this, for a reference implementation.The use-case is that it can get very hairy to proof-read or even to navigate Rmd documents which have a lot of code in them. It's a very useful feature in Rstudio.
P.S. do let me know if this is best asked in
markdown-mode.Best,
Brendan