[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Completely hide properties drawer in 9.6
From: |
Ihor Radchenko |
Subject: |
Re: Completely hide properties drawer in 9.6 |
Date: |
Mon, 16 Jan 2023 14:16:49 +0000 |
Sterling Hooten <hooten@gmail.com> writes:
> In order to both have newly added properties automatically adopt the
> invisibility text-property the interior characters of the properties
> box needs to be sticky. But this conflicted with being able to type
> with the point before the hidden text. To satisfy both these
> requirements I applied =property-drawer-hidden-interior= as a folding
> spec which was sticky to all but the first two and last two characters
> of the property drawer. Then I applied =property-drawer-hidden-edges=
> to these two remaining chunks. In this way you can add in new
> properties and they'll be invisible, but typing at the edges appears
> visibly.
>
> Is there an alternative way of doing this without two separate folding
> specs? Maybe an additional key for ":interior-sticky" which is sticky
> on all characters sharing the same spec, but not sticky at the front
> and rear?
In theory, it is possible to add something like :interior-sticky.
However, it will be against how Emacs' sticky properties work.
An alternative approach you may use is hooking into font-lock.
Fontification will be re-applied upon editing, and you can hide only the
property drawer and nothing else. And you will not need to deal with
edge cases with inserting text.
> I couldn't quite figure out what the :fragile setting was.
:fragile makes sure that things are unfolded when a drawer is no longer
a drawer. Imagine:
<point>:drawer:<begin fold>
Some text.
:end:
<end fold>
Then, you delete ":":
drawer:
Some text.
:end:
:fragile defines rules allowing to auto-unfold the drawers (or anything
else) as needed.
We would not want the drawer above to remain folded as you would not be
able to use <TAB> to unfold any more - tab will no longer see a "drawer"
at point.
> #+begin_src emacs-lisp
> (defun org-fold-show-property-drawer (&optional arg)
> "Unhide property drawer in heading at point.
> With non-nil ARG show the entire subtree."
> (org-with-wide-buffer
> (org-back-to-heading)
> (let* ((beg (point))
> (end (if arg (org-element-property :end (org-element-at-point))
> (org-next-visible-heading 1)
> (1+ (point)))))
> (org-fold-region beg end nil
> 'property-drawer-hidden-edges)
> (org-fold-region beg end nil
> 'property-drawer-hidden-interior))))
>
> (defun org-fold-hide-property-drawer (&optional arg)
> "Completely hide the property drawer in heading at point.
> With non-nil ARG hide the entire subtree."
> (org-with-wide-buffer
> (org-back-to-heading)
> (let* ((beg (point))
> (end (if arg (org-element-property :end (org-element-at-point))
> (org-next-visible-heading 1)
> (1+ (point)))))
> (org-fold--hide-property-drawers beg end))))
> #+end_src
>
> Is there a faster or better way of getting the boundary points for a
> heading without the subheadings? I've wanted this feature in a few
> other situations but don't know a clean way to fetch it. I suppose you
> could also just have that the regex stop searching for the beginning
> of the property box after 2 lines past the heading, since the
> properties box needs to be in the first two lines.
You can use the following at or inside a drawer:
(org-element-lineage (org-element-at-point) '(section))
:begin and :end will contain current section boundaries. "section" is
all the text under the parent heading, up to the first child. The AST is:
(heading
(section
[(planning)]
[(property-drawer)]
[(paragraph1)]
...)
(subheading)
...)
> The default =org-end-of-meta-data= will go past any blank lines and
> only stop at a non-empty line. I would prefer for hitting <RETURN> on
> a headline to act as if the planning line and properties box were
> immutable, and just pass directly after them. For this I wrote a
> version that will stop after the logbooks or property drawer.
>
> Is there a better way to do this? I tried using the match-data but it
> seemed unreliable (if there's nothing but blank lines after the meta
> data it matches on the next heading).
You can just use `org-element-at-point'. At planning, `org-element-type'
will be 'planning. At property drawer - 'property-drawer. At drawer -
'drawer. :end property will include blank lines, but you can also check
:post-blank that will contain the number of blank lines at the end.
Check out `org--at-headline-data-p' implementation.
> I am also experiencing a weird (overlay?) problem with i-search. After
> implementing when I search for things it will make all of the windows
> greyed out, and then only show the matching characters. I can see the
> text again if I =mark-whole-buffer=. But I don't know what's causing
> this.
No idea here. Need more information.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Completely hide properties drawer in 9.6,
Ihor Radchenko <=