diff --git a/init.el b/init.el index 7b90d62..619af46 100644 --- a/init.el +++ b/init.el @@ -574,7 +574,6 @@ db/lookup-smime-key db/org-onenote-open db/org-outlook-open - db/org-rfc-open db/dired-from-shell-command db/system-open)) @@ -710,7 +709,8 @@ With given ARG, display files in `db/important-document-path’." db/org-timestamp-difference db/org-capture-code-snippet hydra-org-clock/body - db/make-org-capture-frame)) + db/make-org-capture-frame + db/org-rfc-open)) (use-package org :commands (org-store-link) diff --git a/site-lisp/db-customize.el b/site-lisp/db-customize.el index cca17de..21a322c 100644 --- a/site-lisp/db-customize.el +++ b/site-lisp/db-customize.el @@ -49,6 +49,12 @@ are assumed to be of the form *.crt." :type 'string :set #'db/update-cert-file-directory) +(defcustom db/rfc-cache-path nil + "Path where RFC documents are automatically downloaded to when opening rfc: links. +If this path is not set, i.e., is null, no automatic download will happen." + :group 'personal-settings + :type '(choice (const nil) file)) + (provide 'db-customize) ;;; db-customize ends here diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index a6d561e..846e7cf 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -8,6 +8,8 @@ ;;; Code: +(require 'db-customize) + ;;; Agenda Customization @@ -435,6 +437,36 @@ Current Task: %s(db/org-clock-current-task); " (format "hy %s" tempfile)) (delete-file tempfile)))) + +;;; Custom link handlers + +(defun db/org-rfc-open (number) + "Open browser to show RFC of given NUMBER. +If `db/rfc-cache-path' is defined, download the RFC in txt format +there and open it. If the RFC has already been downloaded +before, just open it. If `db/rfc-cache-path' is not defined, +open RFC in HTML format in the default browser." + (cond + ((not (string-match "[1-9][0-9]*" number)) + (user-error "Not a valid number for an RFC: %s" number)) + ((and db/rfc-cache-path + (file-name-absolute-p db/rfc-cache-path) + (file-writable-p db/rfc-cache-path)) + (let ((rfc-path (expand-file-name (format "rfc%s.txt" number) + db/rfc-cache-path))) + (cond + ((file-exists-p rfc-path) + (find-file rfc-path)) + (t + (with-temp-buffer + (url-insert-file-contents (format "https://tools.ietf.org/rfc/rfc%s.txt" + number)) + (write-file rfc-path)) + (find-file rfc-path))))) + (t + (warn "`db/rfc-cache-path' not defined or not an absolute writable path, opening RFC in browser.") + (browse-url (concat "https://tools.ietf.org/html/rfc" number))))) + ;;; End diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index 7328a09..01d8ded 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -504,12 +504,6 @@ This is done only if the value of this variable is not null." (user-error "Path for Outlook is not executable, please customize `db/path-to-outlook’.")) (w32-shell-execute "open" db/path-to-outlook (concat "/select outlook:" id))) -(defun db/org-rfc-open (number) - "Open browser to show RFC of given NUMBER." - (unless (string-match "[1-9][0-9]*" number) - (user-error "Not a valid number for an RFC: %s" number)) - (browse-url (concat "https://tools.ietf.org/html/rfc" number))) - ;;; Bookmarks