* Is there a save-outline-visibility excursion or so? @ 2013-05-22 9:13 Thorsten Jolitz 2013-05-22 9:18 ` Jambunathan K 2013-05-23 1:05 ` Stefan Monnier 0 siblings, 2 replies; 10+ messages in thread From: Thorsten Jolitz @ 2013-05-22 9:13 UTC (permalink / raw) To: help-gnu-emacs Hi List, I wonder if there is something like a 'save-excursion' for outline visibility around? A kind of 'save-outline-visibility' function/macro that would enable to change visibility state of an outlined buffer, do some actions that depend on that visibility state in a program, and go back to that exact state of folded and unfolded subtrees afterwards. I'm not talking about global visibility cycling, more about something similar to what window managers do - go from one complicated visibility state to another (maybe simple) state (like show-all or hide-all), but be able to go back to that complicated state with exactly the same subtrees folded or unfolded like before. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-22 9:13 Is there a save-outline-visibility excursion or so? Thorsten Jolitz @ 2013-05-22 9:18 ` Jambunathan K 2013-05-22 10:12 ` Thorsten Jolitz 2013-05-22 10:25 ` Thorsten Jolitz 2013-05-23 1:05 ` Stefan Monnier 1 sibling, 2 replies; 10+ messages in thread From: Jambunathan K @ 2013-05-22 9:18 UTC (permalink / raw) To: Thorsten Jolitz; +Cc: help-gnu-emacs C-h f save-restriction You will find plenty of examples in Orgmode codebase. Thorsten Jolitz <tjolitz@gmail.com> writes: > Hi List, > > I wonder if there is something like a 'save-excursion' for outline > visibility around? A kind of 'save-outline-visibility' function/macro > that would enable to change visibility state of an outlined buffer, do > some actions that depend on that visibility state in a program, and go > back to that exact state of folded and unfolded subtrees afterwards. > > I'm not talking about global visibility cycling, more about something > similar to what window managers do - go from one complicated visibility > state to another (maybe simple) state (like show-all or hide-all), but > be able to go back to that complicated state with exactly the same > subtrees folded or unfolded like before. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-22 9:18 ` Jambunathan K @ 2013-05-22 10:12 ` Thorsten Jolitz 2013-05-22 10:25 ` Thorsten Jolitz 1 sibling, 0 replies; 10+ messages in thread From: Thorsten Jolitz @ 2013-05-22 10:12 UTC (permalink / raw) To: help-gnu-emacs Jambunathan K <kjambunathan@gmail.com> writes: > C-h f save-restriction > > You will find plenty of examples in Orgmode codebase. Right, how could I forget about this one, I even used it ... thanks. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-22 9:18 ` Jambunathan K 2013-05-22 10:12 ` Thorsten Jolitz @ 2013-05-22 10:25 ` Thorsten Jolitz 2013-05-22 12:39 ` Jambunathan K 1 sibling, 1 reply; 10+ messages in thread From: Thorsten Jolitz @ 2013-05-22 10:25 UTC (permalink / raw) To: help-gnu-emacs Jambunathan K <kjambunathan@gmail.com> writes: > C-h f save-restriction > > You will find plenty of examples in Orgmode codebase. Well, I tried it out, and in this case it does not really reset the buffer to its original (partly folded) visibility state, but rather leaves it in show-all state. So I guess narrowing/widening and outline-visibility changes are, at least at this level, not the same. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-22 10:25 ` Thorsten Jolitz @ 2013-05-22 12:39 ` Jambunathan K 2013-05-22 13:41 ` Thorsten Jolitz 0 siblings, 1 reply; 10+ messages in thread From: Jambunathan K @ 2013-05-22 12:39 UTC (permalink / raw) To: Thorsten Jolitz; +Cc: help-gnu-emacs Thorsten Jolitz <tjolitz@gmail.com> writes: > Jambunathan K <kjambunathan@gmail.com> writes: > >> C-h f save-restriction >> >> You will find plenty of examples in Orgmode codebase. > > Well, I tried it out, and in this case it does not really reset the > buffer to its original (partly folded) visibility state, but rather > leaves it in show-all state. So I guess narrowing/widening and > outline-visibility changes are, at least at this level, not the same. Mmmm. Restriction apparently applies to (virtual) bounds of the buffer - beg and end positions and has nothing to do with invisibility. ---------------------------------------------------------------- You may find it easier to work with `make-indirect-buffer' and `clone-indirect-buffer' (See Elisp manual). (I think) In the first case, the indirect buffer starts with no overlays. In the second case, the indirect buffer starts with same *overlay values* as the first one. You can see that any visibility operation on the indirect buffer doesn't affect the visibility of the original buffer. ---------------------------------------------------------------- If you lookup the `org-export--generate-copy-script', towards the end of that defun you will see a snippet like this. ,---- | ;; Overlays with invisible property. | ,@(let (ov-set) | (mapc | (lambda (ov) | (let ((invis-prop (overlay-get ov 'invisible))) | (when invis-prop | (push `(overlay-put | (make-overlay ,(overlay-start ov) | ,(overlay-end ov)) | 'invisible (quote ,invis-prop)) | ov-set)))) | (overlays-in (point-min) (point-max))) | ov-set) `---- Visibility is controlled by `buffer-invisibility-spec'. This should be a good starting point. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-22 12:39 ` Jambunathan K @ 2013-05-22 13:41 ` Thorsten Jolitz 0 siblings, 0 replies; 10+ messages in thread From: Thorsten Jolitz @ 2013-05-22 13:41 UTC (permalink / raw) To: help-gnu-emacs Jambunathan K <kjambunathan@gmail.com> writes: > Thorsten Jolitz <tjolitz@gmail.com> writes: > >> Jambunathan K <kjambunathan@gmail.com> writes: > ---------------------------------------------------------------- > > You may find it easier to work with `make-indirect-buffer' and > `clone-indirect-buffer' (See Elisp manual). > > (I think) In the first case, the indirect buffer starts with no > overlays. In the second case, the indirect buffer starts with same > *overlay values* as the first one. > > You can see that any visibility operation on the indirect buffer doesn't > affect the visibility of the original buffer. > > ---------------------------------------------------------------- Thanks for the tip, indirect buffers are exactly what I needed for editing partly folded outshine buffers without changing visibility or point-position. I reimplemented the relevant outshine function and now it works as expected. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-22 9:13 Is there a save-outline-visibility excursion or so? Thorsten Jolitz 2013-05-22 9:18 ` Jambunathan K @ 2013-05-23 1:05 ` Stefan Monnier 2013-05-23 10:43 ` Thorsten Jolitz 1 sibling, 1 reply; 10+ messages in thread From: Stefan Monnier @ 2013-05-23 1:05 UTC (permalink / raw) To: help-gnu-emacs > I wonder if there is something like a 'save-excursion' for outline > visibility around? Most Elisp functions are unaffected by text's (in)visibility, so I'm curious about the kind of code you want to run within such save-outline-visibility. Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-23 1:05 ` Stefan Monnier @ 2013-05-23 10:43 ` Thorsten Jolitz 2013-05-23 13:09 ` Stefan Monnier 0 siblings, 1 reply; 10+ messages in thread From: Thorsten Jolitz @ 2013-05-23 10:43 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> I wonder if there is something like a 'save-excursion' for outline >> visibility around? > > Most Elisp functions are unaffected by text's (in)visibility, so I'm > curious about the kind of code you want to run within such > save-outline-visibility. I use it in 'org-hlc-hide-hidden-lines-cookies' from ,------------------------------------------------------- | https://github.com/tj64/org-hlc/blob/master/org-hlc.el `------------------------------------------------------- (works for org-mode and outline alike) A hidden-line-cookie is only written, if the headline is folded, and deleted if it is expanded. This is done by 'org-hlc-write-hidden-lines-cookies'. Thus to delete all cookies, I temporarily expand all subtrees, call the function, and then go back to the former visibility state and point position. ,------------------------------------------------------------ | (defun org-hlc-hide-hidden-lines-cookies () | "Delete all hidden-lines cookies." | (interactive) | (let* ((base-buf (point-marker)) | (indirect-buf-name | (generate-new-buffer-name | (buffer-name (marker-buffer base-buf))))) | (clone-indirect-buffer indirect-buf-name nil 'NORECORD) | (save-excursion | (switch-to-buffer indirect-buf-name) | (show-all) | (let ((indirect-buf (point-marker))) | (org-hlc-write-hidden-lines-cookies) | (switch-to-buffer (marker-buffer base-buf)) | (kill-buffer (marker-buffer indirect-buf)) | (set-marker indirect-buf nil)) | (set-marker base-buf nil))) | (setq org-hlc-hidden-lines-cookies-on-p nil)) `------------------------------------------------------------ PS A hidden-lines-cookie looks like this, showing the number of hidden lines: ,----------------- | *** Headline [#165] `----------------- -- cheers, Thorsten ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-23 10:43 ` Thorsten Jolitz @ 2013-05-23 13:09 ` Stefan Monnier 2013-05-24 14:06 ` Thorsten Jolitz 0 siblings, 1 reply; 10+ messages in thread From: Stefan Monnier @ 2013-05-23 13:09 UTC (permalink / raw) To: help-gnu-emacs > A hidden-line-cookie is only written, if the headline is folded, and > deleted if it is expanded. This is done by > 'org-hlc-write-hidden-lines-cookies'. Thus to delete all cookies, I > temporarily expand all subtrees, call the function, and then go back to > the former visibility state and point position. It would seem like it would be a lot simpler to write a loop that simply erases your "cookies" without paying attention to the visibility state. "do and then undo" is always a high-risk way to do nothing, so if you can really do nothing instead, it's always a major reliability gain. Your use of an indirect buffer luckily saves you from having to "do and undo". But indirect buffers suck. BTW, rather than "insert" your cookies in the text (which has lots of undesirable side effects, such as being visible in the saved file), why not use overlays (in which case org-hlc-hide-hidden-lines-cookies would just be a single call to remove-overlays). Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is there a save-outline-visibility excursion or so? 2013-05-23 13:09 ` Stefan Monnier @ 2013-05-24 14:06 ` Thorsten Jolitz 0 siblings, 0 replies; 10+ messages in thread From: Thorsten Jolitz @ 2013-05-24 14:06 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> A hidden-line-cookie is only written, if the headline is folded, and >> deleted if it is expanded. This is done by >> 'org-hlc-write-hidden-lines-cookies'. Thus to delete all cookies, I >> temporarily expand all subtrees, call the function, and then go back to >> the former visibility state and point position. > > It would seem like it would be a lot simpler to write a loop that simply > erases your "cookies" without paying attention to the visibility state. > > "do and then undo" is always a high-risk way to do nothing, so if you > can really do nothing instead, it's always a major reliability gain. > Your use of an indirect buffer luckily saves you from having to "do and > undo". But indirect buffers suck. > > BTW, rather than "insert" your cookies in the text (which has lots of > undesirable side effects, such as being visible in the saved file), why > not use overlays (in which case org-hlc-hide-hidden-lines-cookies would > just be a single call to remove-overlays). Thanks for the tips. I found out that a similar library already existed (org-weights.el by Francois Pinard) which is based of overlays. So I forked his code and merged my code/ideas into it. Its still a bit buggy, but here are a few examples of what this (extended) library can do now (I posted this already on the Org-mode list). Don't bother about the numbers, they are made up, since I cannot copy overlays: 1. Org-mode/subtree-weights: ,----------------------------------------------- | * Header 1 * 2 + 1... | ** Header 2a ** 1 | | text text text text text | text text text text text | | ** Header 2b ** 1 `----------------------------------------------- 2. Outshine Emacs Lisp/subtree-weights: ,-------------------------------------------------- | ;; * Header 1 * 2 + 1... | ;; ** Header 2a ** 1 | | text text text text text | text text text text text | | ;; ** Header 2b ** 1 | `-------------------------------------------------- 3. Conventional Emacs-Lisp/hidden-lines-cookies ,-------------------------------- | ;;; Header 1 [#1] | ;;;; Header 2a [#4] | | text text text text text | text text text text text | | ;;;; Header 2b [#2] | `-------------------------------- 4. Outshine PicoLisp/hidden-lines-cookies ,-------------------------------- | ## * Header 1 [#1] | ## ** Header 2a [#4] | | text text text text text | text text text text text | | ## ** Header 2b [#2] | `-------------------------------- The original repo is at: ,-------------------------------------- | https://github.com/pinard/org-weights `-------------------------------------- you can find my fork with the extended version here: ,------------------------------------ | https://github.com/tj64/org-weights `------------------------------------ -- cheers, Thorsten ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-05-24 14:06 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-05-22 9:13 Is there a save-outline-visibility excursion or so? Thorsten Jolitz 2013-05-22 9:18 ` Jambunathan K 2013-05-22 10:12 ` Thorsten Jolitz 2013-05-22 10:25 ` Thorsten Jolitz 2013-05-22 12:39 ` Jambunathan K 2013-05-22 13:41 ` Thorsten Jolitz 2013-05-23 1:05 ` Stefan Monnier 2013-05-23 10:43 ` Thorsten Jolitz 2013-05-23 13:09 ` Stefan Monnier 2013-05-24 14:06 ` Thorsten Jolitz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).