rtwyyn · 2022-02-17 16:14
Hello everyone!
I am using [following code](https://emacs.stackexchange.com/a/58791) to make org- tables collapsible. Works great appart from styling - in hidden state tables occupies 2 lines with 3 dots below:
#+NAME: mytbl
...
How to make dots appear one same line right after table name?
0lMon · 2022-02-17 16:47
Hej Hej,
Change following line:
(start (org-element-property :contents-begin par))
to
(start (- (org-element-property :contents-begin par) 1))
Cheers,
OlMon
rtwyyn · 2022-02-17 19:07
magic :), works! thank you!
rtwyyn · 2022-02-19 14:18
OlMon, would you also know how to make +NAME block folded by default (on start up)?
I tried setting
(setq org-hide-block-startup t)
it makes Begin src and Begin example blocks folded by default, but not org-table (NAME block).
0lMon · 2022-02-19 15:19
Hej Hej,
I took a quick look at it and tested it just a couple times, so I am not 100% all use cases will work....
You need three parts:
A. A function to map (apply a function) to every named-paragraph
(defun org-named-paragraph-map (function &optional start end)
"Call FUNCTION at the head of all named paragraphs in the current buffer.
Optional arguments START and END can be used to limit the range."
(let ((start (or start (point-min)))
(end (or end (point-max))))
(save-excursion
(goto-char start)
(while (and (< (point) end) (re-search-forward "^[[:blank:]]*#\\+NAME:[[:blank:]]*\\([^[:space:]]+\\)?" end t))
(save-excursion
(save-match-data
(goto-char (match-beginning 0))
(funcall function)))))))
B. A function to display all paragraphs and then use the above map function to hide them. org-show-all '(blocks) is correct in this case because it is the same face attribute that needs to be changed.
(defun org-hide-named-paragraph-all ()
"Fold all named paragraphs in the current buffer."
(interactive)
(org-show-all '(blocks))
(org-named-paragraph-map 'org+-hide-named-paragraph-toggle))
C. An advice needs to be added, so this will go hand in hand with blocks. It would be possible to create separate variables to toggle this behavior, but this is something for an other day.
(advice-add 'org-hide-block-all :after 'org-hide-named-paragraph-all)
To make this clearer:
(setq org-hide-block-startup t)
Will also hide named paragraphs at startup.
Don't worry, if you think I wrote so much code for you. 90% of the code is just the original code from org.el to handle blocks. I just switched some stuff. :P
That would be also my advice on how to learn to use elisp/emacs. Take some code, try to understand it and change parts for your needs.
Cheers,
OlMon
rtwyyn · 2022-02-19 19:19
thanks so much!!! it would take me days to figure it out (and no guarantee i would :))
it works now, only thing src block stopped hidding on start up
+BEGIN_SRC
not sure why, function to map does re-search-forward on only NAME, so it's not the cause
and as i understand adviced applied after org hide block (not instead)...
but it's not that important, i have few of src blocks..
One more time thanks so much!!!
0lMon · 2022-02-19 19:30
No no no, we don't like when there is something not working.... So we fix it!
Right now I don't have that much time, but I will get back to it. A quick and dirty solution is to remove the following line:
(org-show-all '(blocks))
From the `org-hide-named-paragraph-all ` function. Because the function we added the advice will already do this for us.
Could you check this out and get back to me? Thanks!
Cheers,
OlMon
rtwyyn · 2022-02-19 20:37
ha! now it works perfect! thank you OlMon!
"Because the function we added the advice will already do this for us."
got it, (setq org-hide-block-startup t) was hiding blocks, but after that we showed them all again, but hide back only NAMEs.
Really appreciate your help! You won't imagine how much time it would take lisp newbie (me) to figure it out :)