alphapapa / burly.el

Save and restore frames and windows with their buffers in Emacs
GNU General Public License v3.0
301 stars 14 forks source link

Method for programatically generating a burly url #56

Closed pakelley closed 1 year ago

pakelley commented 1 year ago

It's likely I'm just missing something obvious/fundamental here, but I've looked through a lot of the burly source code and issues and what I'm looking for hasn't been clear to me. Apologies if this is a duplicate, or is documented somewhere I missed.

I can create a burly bookmark for a view that I have open in emacs, but it there a way to generate that bookmark from elisp? For example: a couple of things I've tried to set up create two org-ql views side-by-side. I'd like to have an elisp function that accepts two org-ql queries as parameters, and generates a burly bookmark url for a side-by-side view of them (so I can store it in bookmark-alist).

I figure I could do something like save-excursion, then open the two views side-by-side and save the bookmark from there, but is there a direct way to generate the url? I've been iterating on a hacky version of this, but haven't gotten anything that works consistently. If you have any tips for doing this and it sounds useful, I'd be happy to work on something to contribute to burly too.

Lastly, thanks for burly and all of your other useful packages. :)

alphapapa commented 1 year ago

Hi,

Generally these are the relevant functions: burly-buffer-url, burly-windows-url, burly-frames-url. If you, e.g. set up the buffers and windows you want, you can then use burly-windows-url to get the window configuration's URL, which you can then open with burly-open-url. Or you could call burly-bookmark-windows to have it store the bookmark directly.

By the way, I'm guessing you'll be interested in this, which might obviate some of this Burly-based hackery: https://github.com/alphapapa/org-ql/issues/331

Thanks for the kind words. I'm glad they're useful to you.

pakelley commented 1 year ago

Gotcha, I take it there's no clever way to generate the url without actually opening the window configuration then? (Not that it's a huge deal to open everything and save from there) For reference, my current version of trying to make the url directly looks like this:

(defun gen-burly-split-screen-from-orgql-views (view-name-left view-name-right)
    (let* ((left-frame `(leaf (total-width . 126)
                            (total-height . 66)
                            (parameters
                             (burly-url . ,(burly--bookmark-record-url (bookmark-get-bookmark (format "Org QL View: %s" view-name-left)))))
                            (buffer (format "*Org QL View: %s*" view-name-left))))
           (right-frame `(leaf (last . t)
                             (parameters
                              (burly-url . ,(burly--bookmark-record-url (bookmark-get-bookmark (format "Org QL View: %s" view-name-right)))))
                             ;; TODO would be nice to remove these props, since I don't understand what they do exactly (and would make this more similar to the previous frame's definition)
                             (buffer (format "*Org QL View: %s*" view-name-right) (hscroll . 0) (fringes 8 8 nil nil) (scroll-bars nil 0 t nil 0 t nil) (vscroll . 0) (point . 1))))
           (window `(nil hc (total-width . 253) (total-height . 66) ,left-frame ,right-frame))
           (window-filename (concat "?" (url-hexify-string (prin1-to-string window))))
           (window-url (url-recreate-url (url-parse-make-urlobj "emacs+burly+windows" nil nil nil nil window-filename))))
      `((url . ,window-url) (handler . burly-bookmark-handler))))

Clearly this is pretty rough, and I was hoping for some way to just build the url in a sort of declarative way like this. If that's really not feasible, I don't mind so much building the view in the background and saving from there.

Amazing, I've been looking forward to the taxy stuff getting merged into org-ql 🙂 I'll have to find some time to test it out.

alphapapa commented 1 year ago

The chief problem is that Emacs's window configurations are basically internal objects that aren't meant to be maniuplated, AFAICT. But if you carefully examine the code, you could probably figure out how to construct a basic window configuration for two side-by-side windows. Then you could look at org-ql's bookmark-related code to learn how to make a bookmark that loads a certain view with a certain query, and then you could keep following the relevant code to construct a Burly bookmark for said buffers.

But I wouldn't generally recommend it. It would be hacky, complicated, and likely fragile. Instead, it would only take a few lines of code to manipulate the window configuration with normal commands, call org-ql-search, and then burly-bookmark-windows or burly-windows-url. It would be similar to what I do in Yequake to arrange an Emacs frame before displaying it: https://github.com/alphapapa/yequake

pakelley commented 1 year ago

Makes sense, thanks for the patient explanations 🙂