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'.
This commit is contained in:
Daniel - 2020-01-19 17:17:47 +01:00
parent bc6b1acde4
commit c566908deb
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
4 changed files with 40 additions and 8 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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