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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] scratch/rfc-mode 5cdf7172e3 11/52: Merge pull request #1 from r


From: Stefan Monnier
Subject: [nongnu] scratch/rfc-mode 5cdf7172e3 11/52: Merge pull request #1 from riscy/master
Date: Wed, 12 Oct 2022 16:29:18 -0400 (EDT)

branch: scratch/rfc-mode
commit 5cdf7172e307c0e23bb5342c61263d4439292ede
Merge: 3a7afa19e7 390659e19c
Author: Nicolas Martyanoff <khaelin@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #1 from riscy/master
    
    add repository url; automatically fetch some documents
---
 rfc-mode.el | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/rfc-mode.el b/rfc-mode.el
index a89f11538a..bfd9b7d8de 100644
--- a/rfc-mode.el
+++ b/rfc-mode.el
@@ -32,6 +32,7 @@
 (defgroup rfc-mode-group nil
   "Tools to browse and read RFC documents."
   :prefix "rfc-mode-"
+  :link '(url-link :tag "GitHub" "https://github.com/galdor/rfc-mode";)
   :group 'external)
 
 (defface rfc-mode-document-header-face
@@ -66,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
@@ -127,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)))
@@ -315,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)
@@ -322,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]