[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] scratch/rfc-mode e34df2b983 46/52: Free rfc-mode-browse of the
From: |
Stefan Monnier |
Subject: |
[nongnu] scratch/rfc-mode e34df2b983 46/52: Free rfc-mode-browse of the dependency on Helm |
Date: |
Wed, 12 Oct 2022 16:29:21 -0400 (EDT) |
branch: scratch/rfc-mode
commit e34df2b9835778ac5f69ccf57a7fd00730835567
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Nicolas Martyanoff <khaelin@gmail.com>
Free rfc-mode-browse of the dependency on Helm
Packages that are not intrinsically tied to some completion mode,
should not depend on such a package, to avoid forcing the authors
preference on innocent users.
This change shouldn't disturb existing users because we keep using
`helm' if it is available.
Usually optional `helm' support should be implemented in a separate
library, which should be distributed as a separate package, but since
here `helm' support consists of only two short functions, we can skip
that here.
---
rfc-mode.el | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 56 insertions(+), 6 deletions(-)
diff --git a/rfc-mode.el b/rfc-mode.el
index d031cb8144..d4556c0ff2 100644
--- a/rfc-mode.el
+++ b/rfc-mode.el
@@ -3,7 +3,7 @@
;; Author: Nicolas Martyanoff <khaelin@gmail.com>
;; URL: https://github.com/galdor/rfc-mode
;; Version: 1.3.0
-;; Package-Requires: ((emacs "25.1") (helm "3.2"))
+;; Package-Requires: ((emacs "25.1"))
;; Copyright 2019 Nicolas Martyanoff <khaelin@gmail.com>
;;
@@ -26,8 +26,12 @@
;;; Code:
(require 'helm nil t)
+(require 'pcase)
(require 'seq)
+(declare-function helm-build-sync-source "helm-source")
+(declare-function helm-make-actions "helm-lib")
+
;;; Configuration:
(defgroup rfc-mode-group nil
@@ -70,6 +74,23 @@
Assume RFC documents are named as e.g. rfc21.txt, rfc-index.txt."
:type 'string)
+(defcustom rfc-mode-browse-input-function
+ (if (require 'helm nil t) 'helm 'completing-read)
+ "Function used by `rfc-mode-browse' to read user input.
+
+Only `read-number', `completing-read' and `helm' are explicitly
+supported. Any other function is called with no arguments and
+must return an integer.
+
+Here `completion-read' works best if you use some completion
+mode that displays candidates \"vertically\" like `helm' does.
+`ivy-mode' is a popular choice. `fido-mode' in combination
+with `icomplete-vertical-mode' should also work well."
+ :type '(choice (const read-number)
+ (const completing-read)
+ (const helm)
+ function))
+
(defcustom rfc-mode-use-original-buffer-names nil
"Whether RFC document buffers should have the name of the document file.
If nil (the default) then use e.g. *rfc21*, otherwise use e.g. rfc21.txt."
@@ -212,14 +233,43 @@ Offer the number at point as default."
;;;###autoload
(defun rfc-mode-browse ()
- "Browse through all RFC documents referenced in the index using Helm."
+ "Browse through all RFC documents referenced in the index."
(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))))
- (helm :buffer "*helm rfc browser*"
- :sources (rfc-mode-browser-helm-sources rfc-mode-index-entries)))
+ (pcase rfc-mode-browse-input-function
+ ('read-number
+ (display-buffer (rfc-mode--document-buffer
+ (read-number "View RFC document: "
+ (rfc-mode--integer-at-point)))))
+ ('helm
+ (if (and (require 'helm nil t)
+ (fboundp 'helm))
+ (helm :buffer "*helm rfc browser*"
+ :sources (rfc-mode-browser-helm-sources
+ rfc-mode-index-entries))
+ (user-error "Helm has to be installed explicitly")))
+ ('completing-read
+ (let* ((default (rfc-mode--integer-at-point))
+ (choice (completing-read
+ "View RFC document: "
+ (mapcar #'rfc-mode-browser-format-candidate
+ rfc-mode-index-entries)
+ nil nil nil nil
+ (and default
+ (rfc-mode-browser-format-candidate default))))
+ (number (or (and (string-match "\\`RFC\\([0-9]+\\)" choice)
+ (string-to-number (match-string 1 choice)))
+ (ignore-errors (string-to-number choice)))))
+ (unless number
+ (user-error
+ "%s doesn't match a complication candidate and is not a number"
+ choice))
+ (display-buffer (rfc-mode--document-buffer number))))
+ (_ (display-buffer (rfc-mode--document-buffer
+ (funcall rfc-mode-browse-input-function))))))
;;;###autoload
(define-derived-mode rfc-mode special-mode "rfc-mode"
@@ -313,11 +363,11 @@ no next header is found."
ENTRIES is a list of RFC index entries in the browser."
(helm-build-sync-source "RFC documents"
- :candidates (mapcar #'rfc-mode-browser-helm-candidate entries)
+ :candidates (mapcar #'rfc-mode-browser-format-candidate entries)
:action (helm-make-actions
"Read" #'rfc-mode-browser-helm-entry-read)))
-(defun rfc-mode-browser-helm-candidate (entry)
+(defun rfc-mode-browser-format-candidate (entry)
"Create a Helm candidate for ENTRY.
ENTRY is a RFC index entry in the browser."
- [nongnu] scratch/rfc-mode 355f25ee2a 31/52: Add commands to move to the previous/next RFC section, (continued)
- [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, 2022/10/12
- [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 <=
- [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
- [nongnu] scratch/rfc-mode 918d38f901 24/52: compute the index path dynamically, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 4454af644e 13/52: update version tag, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 088d81002e 04/52: make checkdoc happy, Stefan Monnier, 2022/10/12