├── .projectile ├── doc └── helm-clojuredocs.gif ├── README.md └── helm-clojuredocs.el /.projectile: -------------------------------------------------------------------------------- 1 | -/.git 2 | -/.repl 3 | -/TAGS 4 | -/*.log 5 | -------------------------------------------------------------------------------- /doc/helm-clojuredocs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuczko/helm-clojuredocs/HEAD/doc/helm-clojuredocs.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # helm-clojuredocs 2 | 3 | For people addicted both to Emacs and [clojuredocs](http://clojuredocs.org) 4 | 5 | ![animation](doc/helm-clojuredocs.gif "animation") 6 | 7 | 8 | ## How to install 9 | 10 | Relax. ~~Soon in Melpa~~. It's on [Melpa](http://melpa.org/) now. 11 | 12 | ```package-install helm-clojuredocs``` 13 | 14 | ## How to use 15 | 16 | Two function are exposed: 17 | 18 | - ```helm-clojuredocs```: opens helm session with no initial pattern. searching starts with minimal 3 characters entered. 19 | - ```helm-clojuredocs-at-point```: opens helm session with initial pattern guessed from thing under current cursor position. 20 | -------------------------------------------------------------------------------- /helm-clojuredocs.el: -------------------------------------------------------------------------------- 1 | ;;; helm-clojuredocs.el --- search for help in clojuredocs.org 2 | 3 | ;; Author: Michal Buczko 4 | ;; URL: https://github.com/mbuczko/helm-clojuredocs 5 | ;; Package-Requires: ((edn "1.1.2") (helm "1.5.7")) 6 | ;; Version: 0.3 7 | ;; Keywords: helm, clojure 8 | 9 | ;; Copyright (C) 2016 Michal Buczko 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Code: 25 | 26 | (require 'url) 27 | (require 'edn) 28 | (require 'browse-url) 29 | (require 'helm) 30 | 31 | (defgroup helm-clojuredocs nil 32 | "Net related applications and libraries for Helm." 33 | :group 'helm) 34 | 35 | (defcustom helm-clojuredocs-suggest-url 36 | "http://clojuredocs.org/ac-search?query=" 37 | "Url used for looking up Clojuredocs suggestions." 38 | :type 'string 39 | :group 'helm-clojuredocs) 40 | 41 | (defface helm-clojuredocs-package 42 | '((default (:foreground "green"))) "Face used to describe package") 43 | 44 | (defface helm-clojuredocs-type 45 | '((default (:foreground "grey50"))) "Face used to describe type") 46 | 47 | (defun helm-net--url-retrieve-sync (request parser) 48 | (with-current-buffer (url-retrieve-synchronously request) 49 | (funcall parser))) 50 | 51 | (defun helm-clojuredocs--parse-suggestion (suggestion) 52 | (let ((cd-namespace (or (gethash ':ns suggestion) "")) 53 | (cd-type (or (gethash ':type suggestion) "")) 54 | (cd-suggestion (gethash ':name suggestion))) 55 | (cons 56 | (format "%s %s %s" 57 | (propertize cd-namespace 'face 'helm-clojuredocs-package) 58 | cd-suggestion 59 | (propertize (concat "<" cd-type ">") 'face 'helm-clojuredocs-type)) 60 | (gethash :href suggestion)))) 61 | 62 | (defun helm-clojuredocs--parse-buffer () 63 | (goto-char (point-min)) 64 | (when (re-search-forward "\\(({.+})\\)" nil t) 65 | (cl-loop for i in (edn-read (match-string 0)) 66 | collect (helm-clojuredocs--parse-suggestion i) into result 67 | finally return result))) 68 | 69 | (defun helm-clojuredocs-fetch (pattern request-prefix) 70 | "Fetch Clojuredocs suggestions and return them as a list." 71 | (let ((request (concat helm-clojuredocs-suggest-url 72 | (url-hexify-string (or (and request-prefix 73 | (concat request-prefix " " pattern)) 74 | pattern))))) 75 | (puthash pattern (helm-net--url-retrieve-sync 76 | request #'helm-clojuredocs--parse-buffer) helm-clojuredocs-cache))) 77 | 78 | (defun helm-clojuredocs-set-candidates (&optional request-prefix) 79 | "Set candidates with result and number of clojuredocs results found." 80 | (let ((suggestions (or (gethash helm-pattern helm-clojuredocs-cache) 81 | (helm-clojuredocs-fetch helm-pattern request-prefix)))) 82 | (if (member helm-pattern suggestions) 83 | suggestions 84 | (append 85 | suggestions 86 | (list (cons (format "Search for '%s' on clojuredocs.org" helm-input) 87 | (concat "/search?q=" helm-input))))))) 88 | 89 | (defvar helm-clojuredocs-cache (make-hash-table :test 'equal)) 90 | (defvar helm-source-clojuredocs 91 | (helm-build-sync-source "clojuredocs.org suggest" 92 | :candidates #'helm-clojuredocs-set-candidates 93 | :cleanup (lambda () (clrhash helm-clojuredocs-cache)) 94 | :action '(("Go to clojuredocs.org" . (lambda (candidate) 95 | (browse-url (concat "http://clojuredocs.org" candidate))))) 96 | :volatile t 97 | :requires-pattern 3)) 98 | 99 | 100 | (defun helm-clojuredocs-invoke (&optional init-value) 101 | (let ((helm-input-idle-delay 0.38) 102 | (debug-on-error t)) 103 | (helm :sources 'helm-source-clojuredocs 104 | :buffer "*helm-clojuredocs*" 105 | :prompt "Doc for: " 106 | :input init-value))) 107 | 108 | (defun helm-clojuredocs-thing-at-point (thing) 109 | (when thing 110 | (first (last (split-string thing "/"))))) 111 | 112 | ;;;###autoload 113 | (defun helm-clojuredocs () 114 | "Preconfigured `helm' for searching in clojuredocs.org" 115 | (interactive) 116 | (helm-clojuredocs-invoke)) 117 | 118 | ;;;###autoload 119 | (defun helm-clojuredocs-at-point () 120 | "Preconfigured `helm' for searching in clojuredocs.org with symbol at point" 121 | (interactive) 122 | (helm-clojuredocs-invoke (helm-clojuredocs-thing-at-point 123 | (thing-at-point 'symbol)))) 124 | 125 | (provide 'helm-clojuredocs) 126 | 127 | ;; Local Variables: 128 | ;; coding: utf-8 129 | ;; End: 130 | 131 | ;;; helm-clojuredocs.el ends here 132 | --------------------------------------------------------------------------------