├── .gitignore ├── README.md └── dash-at-point.el /.gitignore: -------------------------------------------------------------------------------- 1 | /dash-at-point.elc 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | dash-at-point.el --- Search the word at point with Dash 4 | 5 | [Dash](http://kapeli.com/) is an API Documentation Browser and Code Snippet Manager. dash-at-point make it easy to search the word at point with Dash. 6 | 7 | # Usage 8 | 9 | If you choose not to use one of the convenient packages in 10 | [Melpa][melpa], you will need to add the directory containing 11 | `dash-at-point.el` to your `load-path`, and then add the following to 12 | your .emacs: 13 | 14 | ```lisp 15 | (add-to-list 'load-path "/path/to/dash-at-point") 16 | (autoload 'dash-at-point "dash-at-point" 17 | "Search the word at point with Dash." t nil) 18 | (global-set-key "\C-cd" 'dash-at-point) 19 | (global-set-key "\C-ce" 'dash-at-point-with-docset) 20 | ``` 21 | 22 | Run `dash-at-point` to search the word at point, then Dash is launched and search the word. Use prefix argument `C-u` to edit the search string first. 23 | 24 | Dash queries can be narrowed down with a docset prefix. You can customize the relations between docsets and major modes. 25 | 26 | ```lisp 27 | (add-to-list 'dash-at-point-mode-alist '(perl-mode . "perl")) 28 | ``` 29 | 30 | To choose docsets before call Dash, run `dash-at-point-with-docset`. The docset options are suggested from the variable 31 | 32 | Additionally, the buffer-local variable `dash-at-point-docset` can 33 | be set in a specific mode hook (or file/directory local variables) 34 | to programmatically override the guessed docset. For example: 35 | 36 | ```lisp 37 | (add-hook 'rinari-minor-mode-hook 38 | (lambda () (setq dash-at-point-docset "rails"))) 39 | ``` 40 | 41 | Dash 1.9.3 introduces a new way to call Dash with keywords (`dash-plugin://`), but if you want to use the legacy way (`dash://`), set non-nil to `dash-at-point-legacy-mode`. 42 | 43 | ```lisp 44 | (custom-set-variables '(dash-at-point-legacy-mode t)) 45 | ``` 46 | 47 | [melpa]: http://melpa.milkbox.net 48 | 49 | # Copyright 50 | 51 | Copyright (C) 2013 Shinji Tanaka 52 | 53 | # Licence 54 | 55 | This file is NOT part of GNU Emacs. 56 | 57 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 58 | 59 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 60 | 61 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 62 | -------------------------------------------------------------------------------- /dash-at-point.el: -------------------------------------------------------------------------------- 1 | ;;; dash-at-point.el --- Search the word at point with Dash 2 | 3 | ;; Copyright (C) 2013 Shinji Tanaka 4 | ;; Author: Shinji Tanaka 5 | ;; Created: 17 Feb 2013 6 | ;; Version: 0.0.5 7 | ;; URL: https://github.com/stanaka/dash-at-point 8 | ;; 9 | ;; This file is NOT part of GNU Emacs. 10 | ;; 11 | ;; Permission is hereby granted, free of charge, to any person obtaining a copy of 12 | ;; this software and associated documentation files (the "Software"), to deal in 13 | ;; the Software without restriction, including without limitation the rights to 14 | ;; use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 15 | ;; of the Software, and to permit persons to whom the Software is furnished to do 16 | ;; so, subject to the following conditions: 17 | ;; 18 | ;; The above copyright notice and this permission notice shall be included in all 19 | ;; copies or substantial portions of the Software. 20 | ;; 21 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | ;; SOFTWARE. 28 | ;; 29 | ;;; Commentary: 30 | ;; 31 | ;; Dash ( http://kapeli.com/ ) is an API Documentation Browser and 32 | ;; Code Snippet Manager. dash-at-point make it easy to search the word 33 | ;; at point with Dash. 34 | ;; 35 | ;; Add the following to your .emacs: 36 | ;; 37 | ;; (add-to-list 'load-path "/path/to/dash-at-point") 38 | ;; (autoload 'dash-at-point "dash-at-point" 39 | ;; "Search the word at point with Dash." t nil) 40 | ;; (global-set-key "\C-cd" 'dash-at-point) 41 | ;; 42 | ;; Run `dash-at-point' to search the word at point, then Dash is 43 | ;; launched and search the word. To edit the search term first, 44 | ;; use C-u to set the prefix argument for `dash-at-point'. 45 | ;; 46 | ;; Dash queries can be narrowed down with a docset prefix. You can 47 | ;; customize the relations between docsets and major modes. 48 | ;; 49 | ;; (add-to-list 'dash-at-point-mode-alist '(perl-mode . "perl")) 50 | ;; 51 | ;; Additionally, the buffer-local variable `dash-at-point-docset' can 52 | ;; be set in a specific mode hook (or file/directory local variables) 53 | ;; to programmatically override the guessed docset. For example: 54 | ;; 55 | ;; (add-hook 'rinari-minor-mode-hook 56 | ;; (lambda () (setq dash-at-point-docset "rails"))) 57 | 58 | ;;; Code: 59 | 60 | ;;;###autoload 61 | (defgroup dash-at-point nil 62 | "Searching in Dash for text at point." 63 | :prefix "dash-at-point-" 64 | :group 'external) 65 | 66 | ;;;###autoload 67 | (defcustom dash-at-point-legacy-mode nil 68 | "Non-nil means use the legacy mode ('dash://') to invoke Dash. 69 | Nil means use the modern mode ('dash-plugin://'). 70 | (This mode may remove in the future.)" 71 | :type 'boolean 72 | :group 'dash-at-point) 73 | 74 | ;;;###autoload 75 | (defcustom dash-at-point-mode-alist 76 | '((actionscript-mode . "actionscript") 77 | (arduino-mode . "arduino") 78 | (c++-mode . "cpp,net,boost,qt,cvcpp,cocos2dx,c,manpages") 79 | (c-mode . "c,glib,gl2,gl3,gl4,manpages") 80 | (caml-mode . "ocaml") 81 | (clojure-mode . "clojure") 82 | (coffee-mode . "coffee") 83 | (common-lisp-mode . "lisp") 84 | (cperl-mode . "perl") 85 | (css-mode . "css,bootstrap,foundation,less,awesome,cordova,phonegap") 86 | (dart-mode . "dartlang,polymerdart,angulardart") 87 | (elixir-mode . "elixir") 88 | (emacs-lisp-mode . "elisp") 89 | (enh-ruby-mode . "ruby") 90 | (erlang-mode . "erlang") 91 | (gfm-mode . "markdown") 92 | (go-mode . "go,godoc") 93 | (groovy-mode . "groovy") 94 | (haml-mode . "haml") 95 | (haskell-mode . "haskell") 96 | (html-mode . "html,svg,css,bootstrap,foundation,awesome,javascript,jquery,jqueryui,jquerym,angularjs,backbone,marionette,meteor,moo,prototype,ember,lodash,underscore,sencha,extjs,knockout,zepto,cordova,phonegap,yui") 97 | (jade-mode . "jade") 98 | (java-mode . "java,javafx,grails,groovy,playjava,spring,cvj,processing,javadoc") 99 | (js2-mode . "javascript,backbone,angularjs") 100 | (js3-mode . "nodejs") 101 | (latex-mode . "latex") 102 | (less-css-mode . "less") 103 | (lua-mode . "lua,corona") 104 | (markdown-mode . "markdown") 105 | (nginx-mode . "nginx") 106 | (objc-mode . "cpp,iphoneos,macosx,appledoc,cocoapods,cocos2dx,cocos2d,cocos3d,kobold2d,sparrow,c,manpages") 107 | (perl-mode . "perl,manpages") 108 | (php-mode . "php,wordpress,drupal,zend,laravel,yii,joomla,ee,codeigniter,cakephp,phpunit,symfony,typo3,twig,smarty,phpp,html,mysql,sqlite,mongodb,psql,redis") 109 | (processing-mode . "processing") 110 | (puppet-mode . "puppet") 111 | (python-mode . "python3,django,twisted,sphinx,flask,tornado,sqlalchemy,numpy,scipy,saltcvp") 112 | (ruby-mode . "ruby,rubygems,rails") 113 | (rust-mode . "rust") 114 | (sass-mode . "sass,compass,bourbon,neat,css") 115 | (scala-mode . "scala,akka,playscala,scaladoc") 116 | (sql-mode . "psql,mysql,sqlite,postgis") 117 | (stylus-mode . "stylus") 118 | (swift-mode . "cpp,iphoneos,macosx,appledoc,cocoapods,cocos2dx,cocos2d,cocos3d,kobold2d,sparrow,c,manpages") 119 | (tcl-mode . "tcl") 120 | (tuareg-mode . "ocaml") 121 | (twig-mode . "twig") 122 | (vim-mode . "vim") 123 | (yaml-mode . "chef,ansible")) 124 | "Alist which maps major modes to Dash docset tags. 125 | Each entry is of the form (MAJOR-MODE . DOCSET-TAG) where 126 | MAJOR-MODE is a symbol and DOCSET-TAG is corresponding tags 127 | for one or more docsets in Dash." 128 | :type '(repeat (cons (symbol :tag "Major mode name") 129 | (string :tag "Docset tags"))) 130 | :group 'dash-at-point) 131 | 132 | ;;;###autoload 133 | (defcustom dash-at-point-mode-alist-legacy 134 | '((actionscript-mode . "actionscript") 135 | (arduino-mode . "arduino") 136 | (c++-mode . "cpp") 137 | (c-mode . "c") 138 | (caml-mode . "ocaml") 139 | (clojure-mode . "clojure") 140 | (coffee-mode . "coffee") 141 | (common-lisp-mode . "lisp") 142 | (cperl-mode . "perl") 143 | (css-mode . "css") 144 | (elixir-mode . "elixir") 145 | (emacs-lisp-mode . "elisp") 146 | (enh-ruby-mode . "ruby") 147 | (erlang-mode . "erlang") 148 | (gfm-mode . "markdown") 149 | (go-mode . "go") 150 | (groovy-mode . "groovy") 151 | (haml-mode . "haml") 152 | (haskell-mode . "haskell") 153 | (html-mode . "html") 154 | (jade-mode . "jade") 155 | (java-mode . "java") 156 | (js2-mode . "javascript") 157 | (js3-mode . "nodejs") 158 | (latex-mode . "latex") 159 | (less-css-mode . "less") 160 | (lua-mode . "lua") 161 | (markdown-mode . "markdown") 162 | (nginx-mode . "nginx") 163 | (objc-mode . "iphoneos") 164 | (perl-mode . "perl") 165 | (php-mode . "php") 166 | (processing-mode . "processing") 167 | (puppet-mode . "puppet") 168 | (python-mode . "python3") 169 | (ruby-mode . "ruby") 170 | (rust-mode . "rust") 171 | (sass-mode . "sass") 172 | (scala-mode . "scala") 173 | (stylus-mode . "stylus") 174 | (tcl-mode . "tcl") 175 | (tuareg-mode . "ocaml") 176 | (twig-mode . "twig") 177 | (vim-mode . "vim") 178 | (yaml-mode . "chef")) 179 | "Alist which maps major modes to Dash docset tags. 180 | Each entry is of the form (MAJOR-MODE . DOCSET-TAG) where 181 | MAJOR-MODE is a symbol and DOCSET-TAG is a corresponding tag 182 | for one or more docsets in Dash." 183 | :type '(repeat (cons (symbol :tag "Major mode name") 184 | (string :tag "Docset tag"))) 185 | :group 'dash-at-point) 186 | 187 | ;;;###autoload 188 | (defvar dash-at-point-docsets (mapcar #'cdr dash-at-point-mode-alist) 189 | "Variable used to store all known Dash docsets. The default value 190 | is a collection of all the values from `dash-at-point-mode-alist'. 191 | 192 | Setting or appending this variable can be used to add completion 193 | options to `dash-at-point-with-docset'.") 194 | 195 | ;;;###autoload 196 | (defvar dash-at-point-docset nil 197 | "Variable used to specify the docset for the current buffer. 198 | Users can set this to override the default guess made using 199 | `dash-at-point-mode-alist', allowing the docset to be determined 200 | programatically. 201 | 202 | For example, Ruby on Rails programmers might add an \"allruby\" 203 | tag to the Rails, Ruby and Rubygems docsets in Dash, and then add 204 | code to `rinari-minor-mode-hook' or `ruby-on-rails-mode-hook' 205 | which sets this variable to \"allruby\" so that Dash will search 206 | the combined docset.") 207 | (make-variable-buffer-local 'dash-at-point-docset) 208 | 209 | (defun dash-at-point-guess-docset () 210 | "Guess which docset suit to the current major mode." 211 | (cdr (assoc major-mode 212 | (if dash-at-point-legacy-mode 213 | dash-at-point-mode-alist-legacy 214 | dash-at-point-mode-alist)))) 215 | 216 | (defun dash-at-point-run-search (search-string &optional docset) 217 | "Directly execute search for SEARCH-STRING in Dash." 218 | (start-process "Dash" nil "open" "-g" 219 | (if dash-at-point-legacy-mode 220 | (concat "dash://" 221 | (when docset 222 | (concat docset ":")) 223 | search-string) 224 | (concat "dash-plugin://" 225 | (when docset 226 | (concat "keys=" docset "&")) 227 | "query=" (url-hexify-string search-string))))) 228 | 229 | ;;;###autoload 230 | (defun dash-at-point (&optional edit-search) 231 | "Search for the word at point in Dash. 232 | If the optional prefix argument EDIT-SEARCH is specified, 233 | the user will be prompted to edit the search string first." 234 | (interactive "P") 235 | (let* ((thing (thing-at-point 'symbol)) 236 | (docset (or dash-at-point-docset (dash-at-point-guess-docset)))) 237 | (dash-at-point-run-search 238 | (if (or edit-search (null thing)) 239 | (read-string "Dash search: " thing) 240 | thing) 241 | docset))) 242 | 243 | ;;;###autoload 244 | (defun dash-at-point-with-docset (&optional edit-search) 245 | "Search for the word at point in Dash with a chosen docset. 246 | The docset options are suggested from the variable 247 | `dash-at-point-docsets'. 248 | 249 | If the optional prefix argument EDIT-SEARCH is specified, 250 | the user will be prompted to edit the search string after 251 | choosing the docset." 252 | (interactive "P") 253 | (let* ((thing (thing-at-point 'symbol)) 254 | (docset (completing-read "Dash docset: " dash-at-point-docsets 255 | nil nil nil 'minibuffer-history (dash-at-point-guess-docset))) 256 | (search (if (or edit-search (null thing)) 257 | (read-from-minibuffer (concat "Dash search (" docset "): ")) 258 | thing))) 259 | (dash-at-point-run-search search docset))) 260 | 261 | (provide 'dash-at-point) 262 | 263 | ;;; dash-at-point.el ends here 264 | --------------------------------------------------------------------------------