emacs-elpa-diffs
[Top][All Lists]
Advanced

[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.
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]