emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sébastien Lerique" <sl@eauchat.org>
To: emacs-orgmode@gnu.org
Subject: An org-follow-mode following org/org-roam links
Date: Mon, 21 Oct 2024 16:56:32 +0200	[thread overview]
Message-ID: <87a5ex1p3z.fsf@eauchat.org> (raw)

Hello all,

First of all thanks to everybody for org (file, agenda, and much more),
such an amazing tool!

I'm trying to add a minor "org-follow-mode" somewhere between
"org-agenda-follow-mode" and "org-roam-ui-follow-mode"
<https://github.com/org-roam/> (request also posted on
<https://org-roam.discourse.group/t/advice-for-an-org-follow-mode-following-org-org-roam-links/3631>).
My intuition so far was to start from a copy of "org-agenda-follow-mode"
(and subcommands), adapting it to an org file being the main window.

--8<---------------cut here---------------start------------->8---
(defvar org-follow-mode nil)

(defvar org-pre-follow-window-conf nil)

(defun org-marked-tree-to-indirect-buffer (arg)
  ;; TODO needed?
  ;; (interactive "P")
  ;; (org-agenda-check-no-diary)
  (let* ((marker
          ;;(or
          (org-get-at-bol 'org-marker)
	  ;; (org-agenda-error)
          ;; )
          )
	 (buffer (marker-buffer marker))
	 (pos (marker-position marker)))
    (with-current-buffer buffer
      (save-excursion
	(goto-char pos)
	(org-tree-to-indirect-buffer arg))))
  ;; TODO needed?
  ;; (setq org-agenda-last-indirect-buffer org-last-indirect-buffer)
  )

(defcustom org-follow-indirect nil
  "Non-nil means `org-follow-mode' displays only the current item's
tree, in an indirect buffer."
  :group 'org
  :version "29.4"
  :type 'boolean)

(defun org-do-context-action ()
  "Show outline path and, maybe, follow mode window."
  (let ((m (org-get-at-bol 'org-marker)))
    (when (and (markerp m) (marker-buffer m))
      (and org-follow-mode
           (if org-follow-indirect
               (let ((org-indirect-buffer-display 'other-window))
                 ;; TODO or org-marked-tree-to-indirect-buffer from above
                 (org-tree-to-indirect-buffer nil))
             ;; TODO needed?
             ;; (org-agenda-show)
             ;; TODO
             ;; (and org-agenda-show-outline-path
             ;;      (org-with-point-at m (org-display-outline-path org-agenda-show-outline-path)))
             )))))

(defun org-follow-mode ()
  "Toggle follow mode in a buffer."
  (interactive)
  (unless org-follow-mode
    (setq org-pre-follow-window-conf
	  (current-window-configuration)))
  (setq org-follow-mode (not org-follow-mode))
  (unless org-follow-mode
    (set-window-configuration org-pre-follow-window-conf))
  ;; TODO needed?
  ;; (org-set-mode-name)
  (org-do-context-action)
  (message "Follow mode is %s"
	   (if org-follow-mode "on" "off")))
--8<---------------cut here---------------end--------------->8---

Now this obviously doesn't work, primarily because I have no
`org-marker` defined as no agenda line is selected.

I then went over the "org-roam-ui-follow-mode" code, little of which I
could use for this as most of the follow-mode looks simpler, directly
using the network instead of having to manage windows.

Would anyone have some advice to set this up? How to replace the use of
`marker` and read the current org position instead?

Thanks again for reading, and best to y'all
-- 
Sébastien Lerique
https://slvh.fr/


                 reply	other threads:[~2024-10-21 15:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5ex1p3z.fsf@eauchat.org \
    --to=sl@eauchat.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).