From c566908deb79a12c6f1ed7e7574b2c11f85200c8 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sun, 19 Jan 2020 17:17:47 +0100 Subject: [PATCH] Let the org mode RFC link handler cache its documents RFC documents do not change over time. The custom org mode link handler `db/org-rfc-open' now makes use of this by downloading RFC documents to `db/rfc-cache-path' (if defined) and opening the files locally. If `db/rfc-cache-path' is not defined, the RFC is opened in an external browser as before. This allows to keep a selection of used RFC documents locally on the filesystem for future reference, without the need to retrieve them again from the IETF. Since this is all org mode related, the handler now also resides in `db-org' instead of `db-utils'. --- init.el | 4 ++-- site-lisp/db-customize.el | 6 ++++++ site-lisp/db-org.el | 32 ++++++++++++++++++++++++++++++++ site-lisp/db-utils.el | 6 ------ 4 files changed, 40 insertions(+), 8 deletions(-) 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