emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* An org-follow-mode following org/org-roam links
@ 2024-10-21 14:56 Sébastien Lerique
  0 siblings, 0 replies; only message in thread
From: Sébastien Lerique @ 2024-10-21 14:56 UTC (permalink / raw)
  To: emacs-orgmode

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/


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-10-21 15:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-21 14:56 An org-follow-mode following org/org-roam links Sébastien Lerique

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