Ihor Radchenko <[email protected]> writes:
> "J.D. Smith" <[email protected]> writes:
>
>> The approach:
>>
>> 1. Apply `rear-nonsticky=(... invisible)' to both the front and back
>> hidden markers.
>
>> 2. Change cursor (from box to bar), when edits would occur /inside/ the
>> markers of the emphasized text. This requires placing cursor sensor
>> functions on the entire emphasized text (save the leftmost marker).
>>
>> The `rear-nonsticky' property causes the display engine to place point
>> on the RHS/LHS of the hidden markers depending on what side they are
>> /approached from/ (from outside direction: stay out; from inside
>> direction: stay in). The video linked below should make this clearer.
>>
>> This could potentially be a minor-mode — `org-hidden-cursor-mode' or so
>> — which could allow customizing the "inside" cursor type/color, etc. It
>> could apply to keywords, links, etc. as well. It would need to turn on
>> `cursor-sensor-mode'.
>>
>> Find more details, the several lines of code implementing this for
>> emphasized text, and a video demo, here:
>>
>> https://gist.github.com/jdtsmith/87ce361830466dd9ab2e304d17ddc2e4
>>
>> Happy to contribute some code for this if you think it could be a good
>> fit for Org.
>
> Sounds interesting.
> I have been thinking to incorporate org-appear approach itself (maybe
> with an option to reveal the whole line at point), but I can see how
> your approach can be less distracting.
I find org-appear somewhat distracting, since I use visual lines and it
can cause words to wrap. So far the change of cursor has been damned
intuitive.
> Maybe it can also be a basis to have multiple ways to handle
> invisible boundaries - cursor change, org-appear-like reveal of the link
> at point, relealing the whole line.
I think that would be possible. How stable is org's font-locking code?
I don't know how org-appear works, but this new cursor-sensor approach
has the advantage of just requiring another property to be added during
font-locking — no live property edits required.
Presumably an alternate cursor-sensor function could instead temporarily
remove/restore the invisible properties at point when you enter/exit,
but when you make edits, font lock will come calling again...
Actually there is one trick I thought of to make an edit-free "appear"
flavor that would work in the same way:
1. Hide entity/link/keyword/etc. markers using a custom `invisible'
symbol, e.g. `org-hide', which is on the `buffer-invisibility-spec'.
2. When entering text flanked by hidden boundaries, apply an overlay
which specifies another bogus `invisible' symbol, like `org-nada',
one that is /not/ on the `buffer-invisibility-spec' list.
Since overlays outrank text properties, the text under the overlay will
magically become visible: no property edits required.
I think that would work pretty nicely. In fact, you could have one, the
other, or both features (cursor change + unhide). I can work something
up soon. Is there a release version I should be targeting?
Simple demo with both features:
(setq-local buffer-invisibility-spec '(org-hide)
my/ov (make-overlay 0 0 nil nil t))
(overlay-put my/ov 'invisible 'org-nada)
(cursor-sensor-mode 1)
(defun my/appear-sensor (_win _pos type)
(if (eq type 'entered)
(let ((beg (1- (previous-single-property-change (1+ (point))
'cursor-sensor-functions)))
(end (next-single-property-change (1- (point))
'cursor-sensor-functions)))
(move-overlay my/ov beg end)
(setq cursor-type 'bar))
(setq cursor-type 'box)
(move-overlay my/ov 0 0)))
(let* ((star (propertize "*" 'invisible 'org-hide 'rear-nonsticky
'(invisible)))
(ent (propertize (concat "FOO" star) 'cursor-sensor-functions
'(my/appear-sensor))))
(dotimes (_ 3) (insert "\n" "Some " star ent " or another")))