Org Gemini Links

Table of Contents

1. Introduction

This code provides two features to Org-mode:

  1. Parsing code to interpret specific URL prefixed with gemini: .
  2. A function to call Gemini Browser with the proper URL: org-geminilinks-switch-link-follow .

Also, the package associates the function call to the C-c C-o action in Org-mode to open the link porperly. For instance, an URL like //startpage.org would be identified, and pressing C-c C-o (org-open-at-point) Emacs would try to open elpher with the URL at point (it will use browse-url).

1.1. Elpher

Elpher package is a Gopher and Gemini browser inside Emacs. It configures browse-url to recognise any gemini URL and open the elpher browser.

If you intend to use another browser, like Lagrange, you should see Section Configure other browser instead of elpher below. The code there would change the browser to lagrange, but any other program could be used.

2. Requirements

Org-mode should be on the system and loaded.

(require 'org)

3. Configure other browser instead of elpher

Why don't we use Lagrange as default browser too?

This section has a header propety to disable tangling. Org-mode would not export the code inside this section. To enable it, use M-x org-set-property header-args :tangle org-geminilinks.el. Tangling can also be enabled by delenting :header-args: :tangle no line below the section title.

3.1. Custom variables

(defcustom lagrange-program "lagrange"
  "The program path to Lagrange.")
(defcustom lagrange-arguments nil
  "Extra arguments for Lagrange.")

3.2. lagrange-browse-url-lagrange

(defun lagrange-browse-url-lagrange (url &rest _)
  "Open Lagrange to browse the given URL."
  (interactive (browse-url-interactive-arg "URL: "))
  (setq url (browse-url-encode-url url))
  (let* ((process-environment (browse-url-process-environment)))
    (apply #'start-process
           (concat "lagrange " url) nil
           lagrange-program
           (append
            lagrange-arguments            
            (list url)))))

3.3. Add the function to browse-url

(with-eval-after-load 'browse-url
  (add-to-list 'browse-url-handlers 
               (cons "^\\(gopher\\|finger\\|gemini\\)://" 
                     #'lagrange-browse-url-lagrange)))

4. org-geminilinks-switch-link-follow

This function is the main entry point to call Gemini browser with an URL.

(defun org-geminilinks-switch-link-follow (url &optional arg)
    "Open a Gemini Link by using `browse-url' properly.
This function is intended for `org-link-parameters' and
`org-link-set-parameters'.  Use `browse-url-at-point' or `browse-url' to open
a gemini URL with elpher or other browser."
    (browse-url (concat "gemini:" url) arg))

4.1. Just an example function

(defun org-geminilinks-switch-link-follow (url &optional args)
  (interactive "MURL?")
  (message "Yay! Gemini would open: URL: https:%s | args: %s" url args))

5. Add parameters to org-link

This code will enable gemini prefix as a valid URL prefix.

(org-link-set-parameters "gemini" :follow #'org-geminilinks-switch-link-follow)

6. Provide package

(provide 'org-geminilinks)

Date: 03 may 2022

Author: Christian Gimenez

Created: 2024-11-04 lun 01:30

Validate