mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-24 03:50:24 +10:00
Moving to Doom Emacs!
This commit is contained in:
55
.emacs.d/modules/lang/rest/README.org
Normal file
55
.emacs.d/modules/lang/rest/README.org
Normal file
@@ -0,0 +1,55 @@
|
||||
#+TITLE: :lang rest
|
||||
|
||||
This module adds [[https://en.wikipedia.org/wiki/Representational_state_transfer][REST]] support.
|
||||
|
||||
+ Code-completion (~company-restclient~)
|
||||
+ Code evaluation
|
||||
+ org-mode: babel support (~ob-restclient~)
|
||||
|
||||
#+begin_quote
|
||||
~restclient-mode~ is tremendously useful for testing REST APIs. My workflow is to open an ~org-mode~ buffer, create a restclient source block and hack away. ~restclient-mode~ and ~company-restclient~ power this arcane wizardry.
|
||||
#+end_quote
|
||||
|
||||
* Table of Contents :TOC:
|
||||
- [[#install][Install]]
|
||||
- [[#example][Example]]
|
||||
|
||||
* Install
|
||||
No additional setup required.
|
||||
|
||||
* Example
|
||||
#+BEGIN_SRC restclient
|
||||
GET https://jsonplaceholder.typicode.com/posts/1
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
#+RESULTS:
|
||||
#+BEGIN_SRC js
|
||||
{
|
||||
"userId": 1,
|
||||
"id": 1,
|
||||
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
|
||||
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
|
||||
}
|
||||
// GET https://jsonplaceholder.typicode.com/posts/1
|
||||
// HTTP/1.1 200 OK
|
||||
// Date: Thu, 25 May 2017 13:43:42 GMT
|
||||
// Content-Type: application/json; charset=utf-8
|
||||
// Content-Length: 292
|
||||
// Connection: keep-alive
|
||||
// Set-Cookie: __cfduid=d3484257c800700f9882305963fa9d5d91495719822; expires=Fri, 25-May-18 13:43:42 GMT; path=/; domain=.typicode.com; HttpOnly
|
||||
// X-Powered-By: Express
|
||||
// Vary: Origin, Accept-Encoding
|
||||
// Access-Control-Allow-Credentials: true
|
||||
// Cache-Control: public, max-age=14400
|
||||
// Pragma: no-cache
|
||||
// Expires: Thu, 25 May 2017 17:43:42 GMT
|
||||
// X-Content-Type-Options: nosniff
|
||||
// Etag: W/"124-yiKdLzqO5gfBrJFrcdJ8Yq0LGnU"
|
||||
// Via: 1.1 vegur
|
||||
// CF-Cache-Status: HIT
|
||||
// Server: cloudflare-nginx
|
||||
// CF-RAY: 3648ecd7ef833d0d-CPH
|
||||
// Request duration: 0.347179s
|
||||
#+END_SRC
|
||||
#+END_EXAMPLE
|
||||
28
.emacs.d/modules/lang/rest/autoload.el
Normal file
28
.emacs.d/modules/lang/rest/autoload.el
Normal file
@@ -0,0 +1,28 @@
|
||||
;;; lang/rest/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defun +rest-request-at-point-p (&optional pos)
|
||||
(save-excursion
|
||||
(if pos (goto-char pos))
|
||||
(beginning-of-line)
|
||||
(and (re-search-forward restclient-method-url-regexp
|
||||
(line-end-position) t)
|
||||
(not (nth 4 (syntax-ppss))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +rest/dwim-at-point ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(when (+rest-request-at-point-p)
|
||||
(restclient-http-send-current-stay-in-window)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +rest/fold-all ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(let ((last (point)))
|
||||
(while (and (restclient-jump-next)
|
||||
(not (= last (setq last (point)))))
|
||||
(unless (overlays-at (line-end-position))
|
||||
(restclient-toggle-body-visibility))))))
|
||||
36
.emacs.d/modules/lang/rest/config.el
Normal file
36
.emacs.d/modules/lang/rest/config.el
Normal file
@@ -0,0 +1,36 @@
|
||||
;;; lang/rest/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(use-package! restclient
|
||||
:mode ("\\.http\\'" . restclient-mode)
|
||||
:config
|
||||
(set-popup-rule! "^\\*HTTP Response" :size 0.4 :quit 'other)
|
||||
|
||||
;; line numbers aren't enabled by default in fundamental-mode-derived modes
|
||||
(add-hook 'restclient-mode-hook #'display-line-numbers-mode)
|
||||
|
||||
(setq-hook! 'restclient-mode-hook
|
||||
imenu-generic-expression '((nil "^[A-Z]+\s+.+" 0)))
|
||||
|
||||
(defadvice! +rest--permit-self-signed-ssl-a (orig-fn &rest args)
|
||||
"Forces underlying SSL verification to prompt for self-signed or invalid
|
||||
certs, rather than silently reject them."
|
||||
:around #'restclient-http-do
|
||||
(let (gnutls-verify-error tls-checktrust)
|
||||
(apply orig-fn args)))
|
||||
|
||||
(map! :map restclient-mode-map
|
||||
:n [return] #'+rest/dwim-at-point
|
||||
:n "za" #'restclient-toggle-body-visibility
|
||||
:n "zm" #'+rest/fold-all
|
||||
:n "zr" #'outline-show-all
|
||||
|
||||
:localleader
|
||||
"e" #'restclient-http-send-current
|
||||
"E" #'restclient-http-send-current-raw
|
||||
"c" #'restclient-copy-curl-command))
|
||||
|
||||
|
||||
(use-package! company-restclient
|
||||
:when (featurep! :completion company)
|
||||
:after restclient
|
||||
:config (set-company-backend! 'restclient-mode 'company-restclient))
|
||||
7
.emacs.d/modules/lang/rest/packages.el
Normal file
7
.emacs.d/modules/lang/rest/packages.el
Normal file
@@ -0,0 +1,7 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/rest/packages.el
|
||||
|
||||
(package! restclient)
|
||||
(when (featurep! :completion company)
|
||||
(package! company-restclient))
|
||||
|
||||
Reference in New Issue
Block a user