-
Notifications
You must be signed in to change notification settings - Fork 0
/
ractionary-ivy.el
74 lines (65 loc) · 2.33 KB
/
ractionary-ivy.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;;; ractionary-ivy.el --- Ivy command for opening Racket docs
;; -*- lexical-binding: t; -*-
;;; Commentary:
;;
;; A Ivy-based command for selecting a Racket definition (by name) for
;; which to view documentation. To use this feature, add its directory
;; to your `load-path', and set up an `autoload' for the
;; `ractionary-ivy-open-racket-docs' command:
;;
;; (autoload 'ractionary-ivy-racket-docs "ractionary-ivy" nil t)
;;
;; Perhaps also bind the command to some key.
;;; Code:
(require 'ivy)
(require 'ractionary-urls)
(defun ractionary-docs-search-query-url (term)
"Return an URL for searching for the string TERM.
The returned search URL is for the installed Racket docs."
(concat
"file://"
ractionary-racket-doc-dir
"/search/index.html?q=" (url-hexify-string term)))
(defconst ractionary-ivy-candidates
(apply
'append
(mapcar
(lambda (x)
(let ((name (symbol-name (car x))))
(mapcar
(lambda (mp-url)
(let ((s (concat name " [" (car mp-url) "]"))
(url (cadr mp-url)))
(list s name url)))
(cadr x))))
ractionary-url-lookup-table))
"Candidate strings for `ractionary-ivy-racket-docs'.")
(defun ractionary-ivy-open-racket-docs-for-term (candidate)
"Open documentation for CANDIDATE.
Use `browse-url' for opening the documentation if CANDIDATE
appears in `ractionary-ivy-candidates'."
(let* ((entry (assoc candidate ractionary-ivy-candidates)))
(if entry
(progn
(message "Opening documentation for %s" (cadr entry))
(browse-url (caddr entry)))
(message "Opening a search for \"%s\"" candidate)
(browse-url (ractionary-docs-search-query-url candidate)))))
;;;###autoload
(defun ractionary-ivy-racket-docs ()
"Open documentation for a Racket symbol.
Query for a Racket symbol choice with `ivy-read', offering all
symbols in installed Racket documentation. Allow a free-form
search term to be entered also, in which case open a Racket
documentation search rather than opening specific documentation
directly. To select an entered string rather than a highlighted
match, use `\\<ivy-minibuffer-map>\\[ivy-immediate-done]'."
(interactive)
(let ((term
(ivy-read "Racket search term (of %d): "
ractionary-ivy-candidates
:require-match nil)))
(when term
(ractionary-ivy-open-racket-docs-for-term term))))
(provide 'ractionary-ivy)
;;; ractionary-ivy.el ends here