Org Tor Links

Table of Contents

1. Introduction

This code provides two features to Org-mode:

  1. Parsing code to interpret specific URL prefixed with tor-https: .
  2. A function to call Tor Browser with the proper URL: org-torlinks-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 completely (not partially from "https:"), and pressing C-c C-o (org-open-at-point) Emacs would try to open the Tor Browser with the URL at point.

2. Requirements

Org-mode should be on the system and loaded.

(require 'org)

3. Customisation

3.1. Customisation Group org-torlinks

(defgroup org-torlinks nil "Tor link support for Org-link."
  :group 'org-link)

3.2. org-torlinks-program-path

Emacs needs to know where is the Tor bundle installed.

(defcustom org-torlinks-program-path "~/Downloads/tor-browser_en-US/"
  "Where is the Tor dekstop file used to launch it."
  :group 'org-torlinks
  :type 'directory)

4. org-torlinks-program-exec-path

(defun org-torlinks-program-exec-path (&optional dirpath)
  "Return the path of the executable used by Tor."

  (concat (if dirpath
              dirpath
            org-torlinks-program-path)
          "/Browser/start-tor-browser"))

5. org-torlinks-switch-link-follow

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

(defun org-torlinks-switch-link-follow (url &rest _)
  (interactive "MURL?")
  (let ((execpath  (org-torlinks-program-exec-path org-torlinks-program-path))
        (basharg (format "date;cd %s;./Browser/start-tor-browser https:%s"
                               org-torlinks-program-path
                               url)))
    (if (file-executable-p execpath)
        (progn 
          (message "Running %s" basharg)
          (call-process "bash"
                        nil nil nil
                         "-c" basharg))
      (message "Tor program not found: %s" execpath))))

5.1. Just an example function

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

6. Add parameters to org-link

This code will enable tor-https prefix as a valid URL prefix.

(org-link-set-parameters "tor-https" :follow #'org-torlinks-switch-link-follow)

7. Provide package

(provide 'org-torlinks)

Date: 03 may 2022

Author: Christian Gimenez

Created: 2024-11-04 lun 01:31

Validate