alphapapa / org-sidebar

A helpful sidebar for Org mode
GNU General Public License v3.0
527 stars 16 forks source link

Question on possibility that toggling Org-roam daily as a side-bar #37

Closed randomwangran closed 3 years ago

randomwangran commented 3 years ago

Thanks for writing this package. It provides a very good dash screen for my projects.

I am posting this issue to ask if it is possible to add a toggle to just show the content of the daily? The daily is provided by org-roam. The file system is below:

~/daily 2020-11-21.org 2020-11-19.org 2020-11-20.org …

I have achieved this by tweaking your elisp code in this project. It just checks the name of visable buffers in a frame and toggles accordingly.

I am afraid that this tweak is not stable, so it would be good for consulting the author to confirm its durability.

Followings are the code snippet that executing my request.

(defun check-has-daily-sidebar-buffer-p ()
  (check-has-daily-sidebar-buffer (mapcar #'wr/org-daily-check (mapcar #'prin1-to-string  (window-list)))))

(defun check-has-daily-sidebar-buffer (list)
  (some #'numberp list))

(defun wr/org-daily-check (arg)
  (string-match-p  (format "org-sidebar<%s>" (concat (format-time-string "%Y-%m-%d") ".org")) arg))

(defun wr/toggle-daily-as-sidebar ()
  (interactive)
  (if (check-has-daily-sidebar-buffer-p)
      (call-interactively #'wr/org-daily-sidebar-delete)
    (wr/org-daily-sidebar-toggle)))

(defun wr/org-daily-sidebar-delete ()
  (interactive)
  (let* ((source-buffer (current-buffer))
         (point-min (point-min))
         (sidebar-window (--first (window-parameter it 'org-sidebar-window)
                                  (window-at-side-list nil org-sidebar-side))))
    (mapc #'delete-window (--select (window-parameter it 'org-sidebar-window)
                                            (window-at-side-list nil org-sidebar-side)))))

(defun wr/org-daily-sidebar-toggle ()
  (interactive)
  (let* ((source-buffer (current-buffer))
         (point-min (point-min))
         (sidebar-window (--first (window-parameter it 'org-sidebar-window)
                                  (window-at-side-list nil org-sidebar-side)))
         )
    (if (and sidebar-window
             (with-current-buffer (window-buffer sidebar-window)
               (and (eq org-sidebar-source-buffer source-buffer)
                    (eq (window-parameter sidebar-window 'org-sidebar-source-buffer-point-min)
                        point-min))))
                (mapc #'delete-window (--select (window-parameter it 'org-sidebar-window)
                                        (window-at-side-list nil org-sidebar-side)))
      (progn (call-interactively #'t/org-sidebar) (previous-buffer))
      )))

(defun t/org-sidebar (fns)
  (interactive (list org-sidebar-default-fns))
  (when org-sidebar-sidebar-buffers
    (mapc #'kill-buffer org-sidebar-sidebar-buffers)
    (setf org-sidebar-sidebar-buffers nil))
  (let* ((source-buffer (progn (switch-to-buffer (concat (format-time-string "%Y-%m-%d") ".org"))
                               (current-buffer)
                               ))
         (fns (cl-etypecase fns
                (list fns)
                (atom (list fns))))
         (display-buffers (cl-loop for fn in fns
                                   collect (funcall fn source-buffer))))
    (when display-buffers
      (setf org-sidebar-sidebar-buffers display-buffers)
      (--each display-buffers
        (with-current-buffer it
          (org-sidebar--prepare-buffer)
          (setf org-sidebar-source-buffer source-buffer)))
      (org-sidebar--display-buffers display-buffers
        :window-parameters (list (cons 'org-sidebar-window t)
                                 (cons 'org-sidebar-source-buffer-point-min (point-min)))))))
alphapapa commented 3 years ago

I don't use org-roam, so I don't know what you mean. Anyway, you can customize the code as you seem to have done. You may also find burly useful for restoring buffers and window layouts.

randomwangran commented 3 years ago

No problem at all. I will try to make it clear.

Assuming the user Emacs interface is like this: Windows-A, which is just a usual frame layout.

    +---------------------------+
    |                           |
    |                           |
    |                           |
    |        Windows-A          |
    |                           |
    |                           |
    |                           |
    |                           |
    +---------------------------+

When users issue interactive commands (org-sidebar-toggle), the frame layout will be changed in between the following states.

    +---------------------------+-----+
    |                           |     |
    |                           |     |
    |                           |     |
    |                           |     |
    |        Windows-B          |  S  |
    |                           |     |
    |                           |     |
    |                           |     |
    +---------------------------+-----+

    +---------------------------+
    |                           |
    |                           |
    |                           |
    |                           |
    |        Windows-C          |
    |                           |
    |                           |
    |                           |
    +---------------------------+

The content of this buffer (S) is dynamically related to the condition how the Org-sidebar is triggered. If the user is in Buffer-1 that is in Org-mode, then Org-sidebar shows the content of Buffer-1. If the user switches to Buffer-2 that is in Org-mode, then sidebar shows the conent of Buffer-2. I think this is the design of Org-sidebar.

Org-roam-daily is about how users organize his/her file system. The content of Org-roam-daily is a lots of files whose name follow this convention: (concat (format-time-string "%Y-%m-%d") ".org").

This is what it looks like in from the Dired:

    $ ls directory-of-org-roam-daily
     2020-11-27.org
     2020-11-26.org
     2020-11-25.org
     2020-11-23.org
     2020-11-24.org
     …

The thing that I think will be benefited to Org-roam users is to fix the content of sidebar to today's content. For example, today is 2020-11-27, so no matter what buffer the user is visiting, the user always see the same content in the 2020-11-27.org file when the Org-sidebar is toggled on.

When I am drafting this issue, I find a better way than my first attempt. I believe the following code says much more than what I have written.

    (defun org-sidebar-toggle ()
      (interactive)
-  (let* ((source-buffer (current-buffer)) ...)))
+  (let* ((source-buffer (switch-to-buffer (concat (format-time-string "%Y-%m-%d") ".org")))) ...)

I think this can possibly be achieved by adding an optional argument to the interactive function org-sidebar-toggle, such that the content being shown on the sidebar will be one of the following options:

  1. hooks to (current-buffer)
  2. shows today's daily content

If there is anything that I am not making clear, please let me know.

Thank you,

Ran

randomwangran commented 3 years ago

Hi, alphapapa:

I think this feature is a very personal choice. It is not worthy to be pursing as a team work while adding unnecessary complexity to the this project, so I closed this issue.

alphapapa commented 3 years ago

Maybe what you're wanting is for the sidebar to automatically update when the other window displays a new Org buffer. That could be a useful feature.