alphapapa / org-sidebar

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

Examples are obsolete #28

Open maxsutton opened 4 years ago

maxsutton commented 4 years ago

I tried the first example from example.org my/org-sidebar, but I get this error: Symbol's definition is void: make-org-sidebar

Is there an unspecified dependency for that macro/function?

org-sidebar version 20200501.1215 org version 9.2.6 Emacs version 26.3

alphapapa commented 4 years ago

The package was refactored and the examples need to be updated. You could look at the current code to see how to make your own sidebar now, or you could use the 0.3 branch until the examples are updated.

maxsutton commented 4 years ago

PS. Thanks for all your hard work creating this package!

jkitchin commented 3 years ago

I am trying to make my own sidebar. This is close, but I can't figure out how to set the title of the gray bar for the section.

I thought it would be header-line-format, but this doesn't seem to do anything in this code. Am I missing some simple thing? I couldn't figure out how this is done through org-ql. Thanks, this looks like a great way to provide information about a buffer!

(defun my-summary (src-buffer)
  (let ((db (generate-new-buffer (format "summary")))
    (nwords (count-words (point-min) (point-max)))
    (nlines (count-lines (point-min) (point-max))))
    (with-current-buffer db
      (insert (format "%s words
%s lines"

              nwords nlines))

      (setf header-line-format "Buffer statistics"))
    db))

(setq org-sidebar-default-fns '(org-sidebar--todo-items my-summary))
alphapapa commented 3 years ago

Hi John,

The code is not currently designed for arbitrary buffers to be displayed as org-sidebar buffers, but it won't stop you from trying, so you may encounter issues like this. The problem is that the --prepare-buffer function sets header-line-format in the buffer after you do: https://github.com/alphapapa/org-sidebar/blob/67fe1b5c6c879e14d34c34eec2190e9719046b6c/org-sidebar.el#L318

I've tried to make the code flexible, but this isn't a use case I accounted for in the design. For this simple case, you might opt to bypass org-sidebar and just display-buffer-in-side-window yourself, using a slot that doesn't conflict with one used by org-sidebar. That would probably be simpler than hacking around the resetting of header-line-format. But I can imagine various other solutions as well, using, e.g. advice or hooks, to set header-line-format back after --prepare-buffers changes it.

What do you think? Thanks.

jkitchin commented 3 years ago

hm. I am not sure what the best approach is. Here is a clumsy way to do it, I am not sure if there is an easier way to return an empty search (so it doesn't take a lot of time).

(defun my-summary (src-buffer)
  (let ((db (generate-new-buffer (format "summary")))
    (nchars (length (buffer-string)))
    (nwords (count-words (point-min) (point-max)))
    (nlines (count-lines (point-min) (point-max))))
    (save-window-excursion
      (org-ql-search src-buffer '()
    :buffer db
    :title " Buffer statistics"))
    (with-current-buffer db
      (erase-buffer)
      (setf org-sidebar-source-buffer src-buffer)
      (insert (format "%s characters
%s words
%s lines"

              nchars nwords nlines)))
    db))

(setq org-sidebar-default-fns '(org-sidebar--todo-items my-summary))

I can think of lots of reasons to have an arbitrary buffer for sidebars, but it isn't critical for it to use org-sidebar as you suggest. It wasn't obvious from the docs here that you need an org-ql-search type buffer, which is why I thought to just try it :)

I guess there is a good reason for that line 318 you mention. so far I have not succeeded at getting a header-line-format by just setting it in the buffers themselves. Maybe you could read a buffer local variable to set it there though. It seems like the functions called in org-sidebar should be all that is needed.

alphapapa commented 3 years ago

Maybe this context will help understand the design: Originally, org-sidebar buffers had bespoke display code that formatted items from org-ql searches. That was redundant, since org-ql-view buffers did the same thing in a better way, so I replaced that by displaying org-ql-view buffers directly in the sidebar buffers, which simplified the implementation.

Of course, the design could be made to accommodate arbitrary buffers (or, more specifically, arbitrary functions that take the source buffer as an argument and return a buffer to be displayed).

The header line is set again because the org-ql-view header is less suitable for displaying in a sidebar (the query and filename would run past the edge of the window).

jkitchin commented 3 years ago

That makes sense. Maybe a package name like org-ql-sidebar would make more sense, or describe it as a package for displaying org-ql view buffers on the side. When I first saw this package, I guessed the org-ql buffers were just examples, not the expected kind of buffers. It is not a big deal, I like the idea, and was thinking of a sidebar that shows backlinks, or related documents, for example.

alphapapa commented 3 years ago

This package doesn't only use org-ql-view buffers. It also includes org-sidebar-tree. And it has the command org-sidebar-backlinks (which is implemented using org-ql). If there are other kinds of sidebar buffers that would be useful, I'm open to including them as well.

jkitchin commented 3 years ago

Here is a way I finally more or less solved this. It doesn't work from org-sidebar like the hackier solution above does, but does what I want (at least for this example).

(defun my-summary ()
  (interactive)
  (let ((db (generate-new-buffer (format "summary")))
    (nwords (count-words (point-min) (point-max)))
    (nlines (count-lines (point-min) (point-max))))
    (with-current-buffer db
      (use-local-map org-sidebar-tree-map)
      (setf mode-line-format nil
            header-line-format "Statistics")
      (insert (format "%s words
%s lines"
              nwords nlines)))
    (org-sidebar--display-buffers (list (org-sidebar--todo-items (current-buffer))
                    db))))

I think it is probably ok to close this issue. There is no end to the kinds of things one could imagine for sidebar buffers, I don't have specific suggestions now for additional ones.

alphapapa commented 3 years ago

Cool, I'm glad you were able to work that out. Maybe I should rename org-sidebar--display-buffers to a non-double-dashed function and show an example of it being used like that.