💾 Archived View for gem.librehacker.com › gemlog › starlog › 20240605-0.gmi captured on 2024-06-20 at 11:50:38. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-06-16)
-=-=-=-=-=-=-
A while back, I wrote some code to pull a list of random gemini capsules using the Kennedy search engine:
Emacs: Pull Random Gemini Capsules
This has been helpful, but the main problem is the links still need to be parsed and then opened up in my gemini browser, Lagrange. I was doing this with a macro, which was not too bad, but had the idea that I should make something a little more general and convenient in elisp. During the lunchbreak I put this function together:
(defvar gemini-browser "lagrange") (defun open-gemini-links-from-buffer () "Finds all the gemini links in the current buffer and opens them with the program specified by the variable `gemini-browser'" (interactive) (save-excursion (beginning-of-buffer) (while (re-search-forward "^=> \\([[:graph:]]+\\) " nil t) (call-process gemini-browser nil nil nil (buffer-substring (match-beginning 1) (match-end 1))) (sleep-for 0 10))))
With this, then, I could pull the gemini links with the old function, switch to the buffer, and then execute this function. The additional plus side is that, in principle, it should work in any buffer that contains gemini links, assuming the links are absolute paths and can be processed by the browser.
This only works properly with browsers like Lagrange that can detect if they have a process open already, and I think the browser needs to be opened already before you call it. I added a 10 ms sleep in the loop because, if I don't, Lagrange freezes up. Something I didn't bother to look up was what kind of characters can actually be in the URL, and it does not do any other kind of validation. There are also a few things hard-coded in the function which maybe should be in separate variables. But it works for me.
Of course, as far as getting random gemini capsules, it makes sense to automatically launch the links in the browser rather than having to run another command for that. So I modified the original function accordingly:
(defun random-gemini-capsules (n) "Pulls random capsule links from Kennedy search engine and opens them with the program named by the `gemini-browser' variable, e.g., lagrange. With lagrange on Gnu/Linux, this will open all the URLs in the existing browser process, assuming that lagrange is already running. Specify the number of links with N, or interactively. Requires the following shell utilities: gmni, grep, sort, and tail." (interactive "NCount: ") (let ((nbuff (generate-new-buffer "*random-gemini-capsules*"))) (message "pulling data from gemini://kennedy.gemi.dev, standby...") (shell-command (concat "gmni -L -j always \ gemini://kennedy.gemi.dev/observatory/known-hosts \ | grep '^=>' | sort -R | tail -n " (number-to-string n)) nbuff) (save-excursion (switch-to-buffer nbuff) (open-gemini-links-from-buffer))))
I've found a lot of interesting capsules this way, though only about one in every forty or fifty links leads me to something that I want to subscribe to. Many of the others are interesting but haven't been updated for two or three years, so I don't bother subscribing to those ones.