Open alphapapa opened 3 years ago
Doesn't setting an invisible face via text properties/font lock mean the face will apply to both buffers? That's what is happening when I try it. If I active this and then type in the body of a heading in the org buffer, it will hide that text automatically.
Use a cloned indirect buffer.
It seems that indirect buffers cannot have different font-locking from the base buffer. (According to this discussion).
Perhaps overlays can work instead?
Calling this in the tree-buffer seems to have the desired effects, more or less.
(defun org-sidebar-tree-hide-entries ()
(interactive)
(remove-overlays (point-min) (point-max) 'tree 't)
(let* ((heading-regexp (concat "^\\(?:"
org-outline-regexp
"\\)")))
(goto-char (point-min))
(while (re-search-forward heading-regexp nil t)
(save-excursion
(let* ((beg (line-end-position))
(end (progn
(re-search-forward heading-regexp nil t)
(forward-line -1)
(line-end-position)))
(ol (make-overlay beg end nil t t)))
(overlay-put ol 'invisible t)
(overlay-put ol 'tree t))))))
See https://github.com/alphapapa/org-sidebar/blob/master/notes.org#maybe-a-use-font-locking-to-hide-non-heading-text-in-tree-buffer
Here's a function that modifies the font-lock keywords to attempt this. It almost works, although it doesn't seem to take effect in an Org buffer unless I use
font-lock-studio
, then the keywords are applied again. (Even(font-lock-flush)
doesn't seem to force it.) Also, typing more text afterward does not make the new text invisible, even though it should. So maybe this could be a starting point, but it doesn't seem as easy as I hoped, and it seems like a lot of trial-and-error is required.