-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsupermegadoc.el
120 lines (101 loc) · 4.31 KB
/
supermegadoc.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
;;; supermegadoc.el --- launcher for erlang html documentation
;; Copyright (C) 2009 Aliaksey Kandratsenka
;; Author: Aliaksey Kandratsenka <[email protected]>
;; Keywords: convenience, docs
;; 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/>.
;;; Commentary:
;;
;;; Code:
(require 'ffap)
(defvar *supermegadoc-index-dir* (expand-file-name "~/.supermegadoc"))
(defvar *supermegadoc-bin-in-script-dir* (expand-file-name "supermegadoc" (file-name-directory (file-truename load-file-name))))
(defvar *supermegadoc-bin* nil)
(defvar *supermegadoc-errors-log* (expand-file-name "~/supermegadoc-errors.log"))
(defvar *supermegadoc-browse-url-function* 'w3m-browse-url)
(defun supermegadoc-grab-stdout (&rest call-process-args)
(with-temp-buffer
(unwind-protect (let ((status (apply #'call-process
(car call-process-args)
nil
(list (current-buffer) *supermegadoc-errors-log*)
nil
(cdr call-process-args))))
(if (eql status 0)
(buffer-string)
(message "%s exited with status %s" (car call-process-args) status)
(save-excursion
(set-buffer "*Messages*")
(goto-char (point-max))
(insert-file-contents *supermegadoc-errors-log*))
nil))
(condition-case nil
(delete-file *supermegadoc-errors-log*)
(error nil)))))
(defun supermegadoc-find-bin ()
;; first we consider variable if it's non-nil
(or *supermegadoc-bin*
;; then we consider script adjacent to .el
(let ((it *supermegadoc-bin-in-script-dir*))
(when (file-exists-p it)
it))
;; and if it doesn't exist we use PATH
"supermegadoc"))
(defun supermegadoc-run (cdb-path &optional init-filter)
(setq cdb-path (expand-file-name cdb-path *supermegadoc-index-dir*))
(let ((rv (supermegadoc-grab-stdout (supermegadoc-find-bin)
"--for-emacs"
(concat "--init-filter=" (or init-filter (ffap-string-at-point)))
cdb-path)))
(and (not (string-equal rv ""))
rv)))
(defun supermegadoc-html (cdb-path &optional init-filter)
(let ((url (supermegadoc-run cdb-path init-filter)))
(when url
(let ((code `(,*supermegadoc-browse-url-function* ',url)))
(eval code)))))
(defun supermegadoc-erlang ()
(interactive)
(let ((init-string (ffap-string-at-point)))
(setq init-string (replace-regexp-in-string ":" "/" init-string))
(supermegadoc-html "erdoc.cdb" init-string)))
(defun supermegadoc-ri ()
(interactive)
(let ((url (supermegadoc-run "ri.cdb")))
(when url
;; eat initial "ri:"
(let ((arg (substring url 3)))
(if (ignore-errors (symbol-function 'yari))
(yari arg)
(ri arg))))))
(defun supermegadoc-devhelp ()
(interactive)
(supermegadoc-html "devhelp.cdb"))
(defun superwoman ()
(interactive)
(require 'woman)
(let ((url (supermegadoc-run "man.cdb")))
(when url
;; eat initial "man:"
(let* ((man-path (substring url 4))
(path (split-string man-path "/"))
(man-args (concat (car path) " " (cadr path))))
(man man-args)))))
(defun supergo ()
(interactive)
(let ((init-string (ffap-string-at-point)))
(setq init-string (replace-regexp-in-string "\\." "/" init-string))
(let ((value (supermegadoc-run "go.cdb" init-string)))
(when value
(godoc value)))
))
(provide 'supermegadoc)
;;; supermegadoc.el ends here