forked from pashky/restclient.el
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestclient-helm.el
73 lines (59 loc) · 2.12 KB
/
restclient-helm.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
;;; restclient-helm.el --- helm interface for restclient.el
;;
;; Public domain.
;; Author: Pavel Kurnosov <[email protected]>
;; Maintainer: Pavel Kurnosov <[email protected]>
;; Created: 01 Apr 2016
;; Keywords: http helm
;; Package-Requires: ((restclient "0") (helm "1.9.4"))
;; This file is not part of GNU Emacs.
;; This file is public domain software. Do what you want.
;;; Commentary:
;;
;; This is a companion to restclient.el to add helm sources for requests and variables in current restclient-mode buffer.
;;; Code:
;;
(require 'helm)
(require 'helm-utils)
(require 'restclient)
(defun restclient-helm-find-candidates-matching (regexp process)
(let ((result '()))
(with-helm-current-buffer
(if (fboundp 'font-lock-ensure)
(font-lock-ensure)
(with-no-warnings
(font-lock-fontify-buffer)))
(save-excursion
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(setq result (cons (cons (funcall process) (line-number-at-pos)) result))))
result)))
(defun restclient-helm-find-requests ()
(restclient-helm-find-candidates-matching
restclient-method-url-regexp
'(lambda () (match-string 0))))
(defun restclient-helm-find-variables ()
(restclient-helm-find-candidates-matching
restclient-var-regexp
'(lambda () (match-string 1))))
(defun restclient-helm-goto (candidate)
(switch-to-buffer helm-current-buffer)
(helm-goto-line candidate))
(defconst restclient-helm-requests-source
(helm-build-sync-source "Variables"
:action '(("Go to declaration" . restclient-helm-goto))
:candidates 'restclient-helm-find-variables))
(defconst restclient-helm-variables-source
(helm-build-sync-source "Requests"
:action '(("Go to" . restclient-helm-goto))
:candidates 'restclient-helm-find-requests))
;;;###autoload
(defun helm-restclient ()
"Helm for Restclient."
(interactive)
(helm :sources '(restclient-helm-requests-source restclient-helm-variables-source)))
(provide 'restclient-helm)
(eval-after-load 'restclient
'(progn
(define-key restclient-mode-map (kbd "C-c C-g") #'helm-restclient)))
;;; restclient-helm.el ends here