Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2663] Switch Grimoire over to ClojureDocs
This handles only the web views, as the data from the middleware needs further processing.
- Loading branch information
Showing
11 changed files
with
176 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
;;; cider-clojuredocs.el --- ClojureDocs integration -*- lexical-binding: t -*- | ||
|
||
;; Copyright © 2014-2019 Bozhidar Batsov and CIDER contributors | ||
;; | ||
;; Author: Bozhidar Batsov <bozhidar@batsov.com> | ||
|
||
;; This program is free software: you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation, either version 3 of the License, or | ||
;; (at your option) any later version. | ||
|
||
;; This program is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
|
||
;; You should have received a copy of the GNU General Public License | ||
;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
;; This file is not part of GNU Emacs. | ||
|
||
;;; Commentary: | ||
|
||
;; A few commands for ClojureDocs documentation lookup. | ||
|
||
;;; Code: | ||
|
||
(require 'cider-client) | ||
(require 'cider-common) | ||
(require 'subr-x) | ||
(require 'cider-compat) | ||
(require 'cider-popup) | ||
|
||
(require 'nrepl-dict) | ||
|
||
(require 'url-vars) | ||
|
||
(defconst cider-clojuredocs-url "https://clojuredocs.org/") | ||
|
||
(defconst cider-clojuredocs-buffer "*cider-clojuredocs*") | ||
|
||
(defun cider-sync-request:clojuredocs-lookup (ns sym) | ||
"Perform nREPL \"resource\" op with NS and SYM." | ||
(thread-first `("op" "clojuredocs-lookup" | ||
"ns" ,ns | ||
"symbol" ,sym) | ||
(cider-nrepl-send-sync-request) | ||
(nrepl-dict-get "clojuredocs"))) | ||
|
||
(defun cider-clojuredocs-replace-special (name) | ||
"Convert the dashes in NAME to a ClojureDocs friendly format. | ||
We need to handle \"?\", \".\", \"..\" and \"/\"." | ||
(thread-last name | ||
(replace-regexp-in-string "\\?" "_q") | ||
(replace-regexp-in-string "\\(\\.+\\)" "_\\1") | ||
(replace-regexp-in-string "/" "fs"))) | ||
|
||
(defun cider-clojuredocs-url (name ns) | ||
"Generate a ClojureDocs url from NAME and NS." | ||
(let ((base-url cider-clojuredocs-url)) | ||
(when (and name ns) | ||
(concat base-url ns "/" (cider-clojuredocs-replace-special name))))) | ||
|
||
(defun cider-clojuredocs-web-lookup (symbol) | ||
"Open the ClojureDocs documentation for SYMBOL in a web browser." | ||
(if-let* ((var-info (cider-var-info symbol))) | ||
(let ((name (nrepl-dict-get var-info "name")) | ||
(ns (nrepl-dict-get var-info "ns"))) | ||
(browse-url (cider-clojuredocs-url name ns))) | ||
(error "Symbol %s not resolved" symbol))) | ||
|
||
;;;###autoload | ||
(defun cider-clojuredocs-web (&optional arg) | ||
"Open ClojureDocs documentation in the default web browser. | ||
Prompts for the symbol to use, or uses the symbol at point, depending on | ||
the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the | ||
opposite of what that option dictates." | ||
(interactive "P") | ||
(funcall (cider-prompt-for-symbol-function arg) | ||
"ClojureDocs doc for" | ||
#'cider-clojuredocs-web-lookup)) | ||
|
||
(defun cider-create-clojuredocs-buffer (content) | ||
"Create a new ClojureDocs buffer with CONTENT." | ||
(with-current-buffer (cider-popup-buffer cider-clojuredocs-buffer t) | ||
(read-only-mode -1) | ||
(insert content) | ||
(cider-popup-buffer-mode 1) | ||
(view-mode 1) | ||
(goto-char (point-min)) | ||
(current-buffer))) | ||
|
||
(defun cider-clojuredocs--content (dict) | ||
"Generate a nice string from DICT." | ||
(with-temp-buffer | ||
(insert "= " (nrepl-dict-get dict "ns") "/" (nrepl-dict-get dict "name") "\n") | ||
(insert "== See Also\n") | ||
(insert "== Examples\n") | ||
(insert "== Notes\n") | ||
(buffer-string))) | ||
|
||
(defun cider-clojuredocs-lookup (symbol) | ||
"Look up the ClojureDocs documentation for SYMBOL. | ||
If SYMBOL is a special form, the clojure.core ns is used, as is | ||
ClojureDocs's convention." | ||
(if-let* ((var-info (cider-var-info symbol))) | ||
(let* ((name (nrepl-dict-get var-info "name")) | ||
(ns (nrepl-dict-get var-info "ns" "clojure.core")) | ||
(docs (cider-sync-request:clojuredocs-lookup ns name))) | ||
(pop-to-buffer (cider-create-clojuredocs-buffer (cider-clojuredocs--content docs)))) | ||
(error "Symbol %s not resolved" symbol))) | ||
|
||
;;;###autoload | ||
(defun cider-clojuredocs (&optional arg) | ||
"Open ClojureDocs documentation in a popup buffer. | ||
Prompts for the symbol to use, or uses the symbol at point, depending on | ||
the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the | ||
opposite of what that option dictates." | ||
(interactive "P") | ||
(when (derived-mode-p 'clojurescript-mode) | ||
(user-error "`cider-clojuredocs' doesn't support ClojureScript")) | ||
(funcall (cider-prompt-for-symbol-function arg) | ||
"ClojureDocs doc for" | ||
#'cider-clojuredocs-lookup)) | ||
|
||
(provide 'cider-clojuredocs) | ||
|
||
;;; cider-clojuredocs.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
31f83df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll also have to update
cider-hydra
: https://github.com/clojure-emacs/cider-hydra/blob/master/cider-hydra.el#L67.31f83df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I had completely forgotten about it.