šŸ’¾ Archived View for apintandaparma.club ā€ŗ ~ajc ā€ŗ log ā€ŗ 2020-08-14.gmi captured on 2024-05-26 at 14:45:23. Gemini links have been rewritten to link to archived content

View Raw

More Information

ā¬…ļø Previous capture (2020-09-24)

-=-=-=-=-=-=-

2020-08-14 - emacs and gemini urls

Iā€™ve loved Emacs ever since the early 90s when I got some work over the Christmas break during university. Iā€™d been madly hoovering up everything I could learn about Unix at the time, and when I first met a few of the people in the company they asked me which editor I used. I quickly replied ā€œemacs!ā€ and things continued from there. In the early 2000s I moved to using a Mac - my first laptop, and it really was the best Unix one you could get at the time. I tried embracing the possibilities afforded by the converged desktop environment, leaving behind a bunch of Emacs-based services. I tried VoodooPad for storing notes. I switched from Gnus to Apple Mail.

I couldnā€™t quite let go, though. Emacs still hung around for minor tasks, mainly as a mere text editor. I tried TextMate like all the cool Mac kids, but it just wasnā€™t the same. Eventually I left VoodooPad behind for EmacsWiki, planner, muse (though I forget the order for these three!), and eventually org-mode which remains my primary use of Emacs - keeping a log of my work day. Orgā€™s agenda functionaility never quite stuck, I use it just a little. Some day Iā€™ll try and get around to org-roam.

All of that is a long way of explaining that while Iā€™ve been in lockdown and spending a bit more spare time back on my home server, especially in a terminal rather than at a full desktop, Iā€™ve been spending lots of time polishing my Emacs config, and so when I started playing with Gemini it seemed natural to do it via Elpher.

I happened to see wgreenhouse ask in #gemini about teaching ā€˜browse-urlā€™ to open gemini links, so with a day off work and a spare hour or two this morning I gave it a shot. Hereā€™s my initial attempt, which does a bunch of useful stuff for me relating to gemini / gopher URLs:

(setq browse-url-browser-function
      '(("^\\(gemini\\|gopher\\):" . ajc/elpher-browse-url)
        ("." . ajc/browser-function)))

(defun ajc/elpher-browse-url (url &rest args)
  (elpher-go url))

(defun ajc/browser-function (url &rest args)
  (interactive (browse-url-interactive-arg "URL: "))
  (if (display-graphic-p)
      (browse-url-default-browser url args)
    (eww-browse-url url args)))

(add-to-list 'thing-at-point-uri-schemes "gemini://")

(defun ajc/follow-org-gemini-link (link)
  (elpher-go (concat "gemini:" link)))

(defun ajc/follow-org-gopher-link (link)
  (elpher-go (concat "gopher:" link)))

(org-link-set-parameters "gemini"
                         :follow 'ajc/follow-org-gemini-link)
(org-link-set-parameters "gopher"
                         :follow 'ajc/follow-org-gopher-link)

I hope itā€™s useful - Iā€™ll continue tweaking, of course.

I also noticed acdw asking a little later on about screwing elpher into xdg-open so we can open gemini URLs in it from outside Emacs. I noticed this piece of news via Sacha Chuaā€™s weekly emacs updates:

https://git.savannah.gnu.org/cgit/emacs.git/commit/etc/NEWS?id=0aede2d8bfbf04b6c2be12c124f0feda998c2e53

ā€¦which I suspect will provide some hints, as will this, which Iā€™d been fiddling with a weekend or two ago:

https://github.com/sprig/org-capture-extension

but Iā€™ll give this one a go laterā€¦

Update: looks like I was a bit too late!

gemini://gemlog.blue/users/acdw/1597354552.gmi

still, that doesnā€™t look too different to what I worked out on my own, so Iā€™m happy.

Another update: hereā€™s a first go at ā€˜org-store-linkā€™ support - it only fetches the page URL, not the title, though

(org-link-set-parameters "gemini"
                         :follow 'ajc/follow-org-gemini-link
                         :store #'org-elpher-store-link)
(org-link-set-parameters "gopher"
                         :follow 'ajc/follow-org-gopher-link
                         :store #'org-elpher-store-link)

(defun ajc/elpher-get-page-url (page)
  "Return the URL representation of address of PAGE."
  (let ((address (elpher-page-address page)))
    (if (elpher-address-special-p address)
        (error (format "Cannot represent %s as URL" (elpher-page-display-string page)))
      (elpher-address-to-url address))))

(defun ajc/elpher-get-link-url ()
  "Return the URL of item at point."
  (interactive)
  (let ((button (button-at (point))))
    (if button
        (ajc/elpher-get-page-url (button-get button 'elpher-page))
      (error "No item selected"))))

(defun ajc/elpher-get-current-url ()
  "Return the URL of the current page."
  (interactive)
  (ajc/elpher-get-page-url elpher-current-page))

(defun org-elpher-store-link ()
  "Store a link to a gemini page."
  (when (memq major-mode '(elpher-mode))
    (let* ((link (ajc/elpher-get-current-url))
           (type (url-type (elpher-address-from-url link)))
           (description (format "%s page %s" type link)))
      (org-link-store-props
       :type type
       :link link
       :description description))))

Obviously some of this stuff could/should fold back into the elpher source instead. Iā€™ll look into how best to do that, and see if I can work with Tim Vaughan to make it so. The latter stuff might make a good patch or addon for org-mode.