Skip to content

Commit 60951fb

Browse files
committed
Add a command to view official reference sections
1 parent 7783ad9 commit 60951fb

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* New interactive command `clojure-mode-report-bug`.
88
* New interactive command `clojure-view-guide`.
9+
* New interactive command `clojure-view-reference-section`.
910

1011
## 5.5.2 (2016-08-03)
1112

clojure-mode.el

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ Out-of-the box clojure-mode understands lein, boot and gradle."
249249
["Fully unwind a threading macro" clojure-unwind-all])
250250
"--"
251251
["View a Clojure guide" clojure-view-guide]
252+
["View a Clojure reference section" clojure-view-reference-section]
252253
"--"
253254
["Report a clojure-mode bug" clojure-mode-report-bug]
254255
["Clojure-mode version" clojure-mode-display-version]))
@@ -314,6 +315,46 @@ The command will prompt you to select one of the available guides."
314315
(let ((guide-url (concat clojure-guides-base-url (cdr (assoc guide clojure-guides)))))
315316
(browse-url guide-url)))))
316317

318+
(defconst clojure-reference-base-url "https://clojure.org/reference/"
319+
"The base URL for the official Clojure reference.")
320+
321+
(defconst clojure-reference-sections '(("The Reader" . "reader")
322+
("The REPL and main" . "repl_and_main")
323+
("Evaluation" . "evaluation")
324+
("Special Forms" . "special_forms")
325+
("Macros" . "macros")
326+
("Other Functions" . "other_functions")
327+
("Data Structures" . "data_structures")
328+
("Datatypes" . "datatypes")
329+
("Sequences" . "sequences")
330+
("Transients" . "transients")
331+
("Transducers" . "transducers")
332+
("Multimethods and Hierarchies" . "multimethods")
333+
("Protocols" . "protocols")
334+
("Metadata" . "metadata")
335+
("Namespaces" . "namespaces")
336+
("Libs" . "libs")
337+
("Vars and Environments" . "vars")
338+
("Refs and Transactions" . "refs")
339+
("Agents" . "agents")
340+
("Atoms" . "atoms")
341+
("Reducers" . "reducers")
342+
("Java Interop" . "java_interop")
343+
("Compilation and Class Generation" . "compilation")
344+
("Other Libraries" . "other_libraries")
345+
("Differences with Lisps" . "lisps")))
346+
347+
(defun clojure-view-reference-section ()
348+
"Open a Clojure reference section in your default browser.
349+
350+
The command will prompt you to select one of the available sections."
351+
(interactive)
352+
(let ((section (completing-read "Select a reference section: " (mapcar #'car clojure-reference-sections))))
353+
(when section
354+
(let ((section-url (concat clojure-reference-base-url (cdr (assoc section clojure-reference-sections)))))
355+
(browse-url section-url)))))
356+
357+
317358
(defun clojure-space-for-delimiter-p (endp delim)
318359
"Prevent paredit from inserting useless spaces.
319360
See `paredit-space-for-delimiter-predicates' for the meaning of
@@ -1033,9 +1074,9 @@ When called from lisp code align everything between BEG and END."
10331074
(dotimes (_ count)
10341075
(align-region (point) sexp-end nil
10351076
'((clojure-align (regexp . clojure--search-whitespace-after-next-sexp)
1036-
(group . 1)
1037-
(separate . "^ *$")
1038-
(repeat . t)))
1077+
(group . 1)
1078+
(separate . "^ *$")
1079+
(repeat . t)))
10391080
nil))
10401081
;; Reindent after aligning because of #360.
10411082
(indent-region (point) sexp-end)))))

0 commit comments

Comments
 (0)