[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] scratch/rfc-mode 390659e19c 10/52: automatically download indic
From: |
Stefan Monnier |
Subject: |
[nongnu] scratch/rfc-mode 390659e19c 10/52: automatically download indices and documents if they don't exist |
Date: |
Wed, 12 Oct 2022 16:29:18 -0400 (EDT) |
branch: scratch/rfc-mode
commit 390659e19c82233fdde8c83b57cdd19d2e85c56d
Author: riscy <riscy@users.noreply.github.com>
Commit: riscy <riscy@users.noreply.github.com>
automatically download indices and documents if they don't exist
---
rfc-mode.el | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/rfc-mode.el b/rfc-mode.el
index 60d2d81005..bfd9b7d8de 100644
--- a/rfc-mode.el
+++ b/rfc-mode.el
@@ -67,6 +67,13 @@
:type 'directory
:group 'rfc-mode)
+(defcustom rfc-mode-document-url
+ "https://www.rfc-editor.org/rfc/rfc%s.txt"
+ "A `format'able URL for fetching arbitrary RFC documents.
+Assume RFC documents are named as e.g. rfc21.txt, rfc-index.txt."
+ :type 'string
+ :group 'rfc-mode)
+
(defcustom rfc-mode-browser-entry-title-width 60
"The width of the column containing RFC titles in the browser."
:type 'integer
@@ -128,6 +135,7 @@
(defun rfc-mode-browse ()
"Browse through all RFC documents referenced in the index using Helm."
(interactive)
+ (rfc-mode--fetch-document "-index" rfc-mode-index-path)
(unless rfc-mode-index-entries
(setq rfc-mode-index-entries
(rfc-mode-read-index-file rfc-mode-index-path)))
@@ -316,6 +324,7 @@ ENTRY is a RFC index entry in the browser."
The buffer is created if it does not exist."
(let* ((buffer-name (rfc-mode--document-buffer-name number))
(document-path (rfc-mode--document-path number)))
+ (rfc-mode--fetch-document number document-path)
(find-file document-path)
(rename-buffer buffer-name)
(rfc-mode)
@@ -323,6 +332,19 @@ The buffer is created if it does not exist."
;;; Misc utils
+(defun rfc-mode--fetch-document (suffix document-path)
+ "Ensure an RFC document with SUFFIX exists at DOCUMENT-PATH.
+If no such file exists, fetch it from `rfc-document-url'."
+ (rfc-mode--check-directory)
+ (unless (file-exists-p document-path)
+ (url-copy-file (format rfc-mode-document-url suffix) document-path)))
+
+(defun rfc-mode--check-directory ()
+ "Check that `rfc-mode-directory' exists -- create if not."
+ (when (and (not (file-exists-p rfc-mode-directory))
+ (y-or-n-p (format "Create directory %s? " rfc-mode-directory)))
+ (make-directory rfc-mode-directory t)))
+
(defun rfc-mode--parse-rfc-ref (string)
"Parse a reference to a RFC document from STRING.
- [nongnu] scratch/rfc-mode dc1a3a978f 02/52: improve the readme, (continued)
- [nongnu] scratch/rfc-mode dc1a3a978f 02/52: improve the readme, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 3719b9ce9f 20/52: derive rfc-mode from text-mode, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 821a039ae6 18/52: autoload rfc-mode-read, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 355f25ee2a 31/52: Add commands to move to the previous/next RFC section, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode a3a58e9883 15/52: better section title detection, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 55c0c24f9b 28/52: Make rfc-mode inherit from special-mode, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode e037a7ce5c 33/52: Add Tab and S-Tab to navigate through RFC button links, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 02d8dfeb70 16/52: do not fail if helm is not available, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 7819cb64b9 25/52: add a changelog, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode e2608adbac 36/52: Make hyperlinks clickable with the mouse too, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 390659e19c 10/52: automatically download indices and documents if they don't exist,
Stefan Monnier <=
- [nongnu] scratch/rfc-mode e7d9e2f4cb 12/52: add melpa badges to readme, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 55d28321b4 26/52: 1.2.0, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode e34df2b983 46/52: Free rfc-mode-browse of the dependency on Helm, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 408bd186c8 49/52: Use closures instead of quoted lambda lists, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode a734721104 52/52: rfc-mode: Simplify the code by fetching&reading more lazily, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 8fbf469c9b 19/52: improve function name and docstring, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode d4ca95b973 37/52: Add changelog entries for the next version, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode ec4269cc91 38/52: fix backtab key name, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 02546beecf 39/52: v1.3.0, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode bec092989b 30/52: Add imenu support for rfc-mode, Stefan Monnier, 2022/10/12