universal-ctags / citre

A superior code reading & auto-completion tool with pluggable backends.
GNU General Public License v3.0
320 stars 26 forks source link

Jump to TAG in org-mode #136

Closed Pierre-Andre closed 3 months ago

Pierre-Andre commented 1 year ago

If the org-mode file is folded, jump to TAG go to the tag but the file remain folded (and the point is not visible). A normal behavior would be making the point visible.

For instance in citre-goto-tag function

(goto-char (citre-locate-tag tag))
 (if (string-equal major-mode "org-mode")
          (org-fold-show-context 'isearch))
 (run-hooks 'citre-after-jump-hook)

instead of

(goto-char (citre-locate-tag tag))
(run-hooks 'citre-after-jump-hook)

could fix the issue, at least for jumping using citre-goto-tag, (I don't know if there are other ways to do that)

Thanks for all your work on citre !!

AmaiKinono commented 1 year ago

I'm not sure on this. There are many packages for folding things in Emacs, we couldn't deal with all of them.

Also, org-fold-show-context is not defined in Emacs 28.2 (I guess it's added in Emacs 29). org-show-context should be used instead.

How about letting the user put their own "unfold" function in citre-after-jump-hook?

Pierre-Andre commented 1 year ago

1) About "letting the user put their own "unfold" function in citre-after-jump-hook ": Yes, but for end-user (like me) an example could be given as a use case of citre-after-jump-hook

2) org-show-context and org-fold-show-context: I didn't pay attention but as I use doom-emacs, org version is (more than) 9.6. In emacs 28.1, org version is 9.5.2. From 9.6 and beyond org-show-context is replaced by org-fold-show-context. This is another argument to make citre-after-jump-hook the solution…

AmaiKinono commented 1 year ago

Try this:

(add-hook 'citre-after-jump-hook
          (defun citre-org-unfold ()
            (when (derived-mode-p 'org-mode)
              (org-fold-show-context 'isearch))))
Pierre-Andre commented 1 year ago

Just in case, the following config for doom-emacs is can be used (to unfold after jump an org file):

AmaiKinono commented 1 year ago

I am reopening this as I've learnt a general unfolding technique that should apply to any folding implemented using overlay.

This technique comes from reveal.el, which is built-in.

(defun invisible-prop-effective-p (prop)
  "If PROP actually means invisible in current buffer, return non-nil.
PROP is the `invisible' property of an overlay."
  (pcase buffer-invisibility-spec
    ('t prop)
    (_ (let ((atoms (mapcar (lambda (e) (if (consp e) (car e) e))
                            buffer-invisibility-spec)))
         (if (listp prop)
             (cl-intersection prop atoms :test #'eq)
           (memq prop atoms))))))

(defun reveal-if-invisible (pt)
  "If PT is folded, reveal it."
  (let ((ols (overlays-at pt)))
    (dolist (ol ols)
      (when (invisible-prop-effective-p (overlay-get ol 'invisible))
        (delete-overlay ol)))))

A simple test of reveal-if-invisible in an org file works well. I should test this more and add it to citre-after-jump-hook by default.

AmaiKinono commented 3 months ago

Unfortunately reveal-mode doesn't work now in org-mode, maybe due to the changes in org-mode. So I've added an example in user documentation.