Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Fix typos and remove trailing whitespace #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ and supports a few additional keypresses:
- `C-c C-u`: copy query under the cursor as a curl command
- `C-c C-g`: start a [helm](https://emacs-helm.github.io/helm/) session with sources for variables and requests (if helm is available, of course)
- `C-c n n`: narrow to region of current request (including headers)
- `TAB`: hide/show current request body, only if
- `TAB`: hide/show current request body, only if
- `C-c C-a`: show all collapsed regions
- `C-c C-i`: show information on resclient variables at point
- `C-c C-i`: show information on restclient variables at point

The last two functions are implemented as `restclient-outline-mode` minor mode, which is activated by default via hook for major mode. Remove this hook using `(remove-hook 'restclient-mode-hook 'restclient-outline-mode)` if you don't wish to have this behaviour, or it clashes with any other binding for `TAB` like autocomplete.
The last two functions are implemented as `restclient-outline-mode` minor mode, which is activated by default via hook for major mode. Remove this hook using `(remove-hook 'restclient-mode-hook 'restclient-outline-mode)` if you don't wish to have this behaviour, or it clashes with any other binding for `TAB` like autocomplete.

Query file example:

Expand Down Expand Up @@ -130,7 +130,7 @@ and the body.
Content-Type: application/json
User-Agent: SomeApp/1.0
#

# Update a user's name

:user-id = 7
Expand All @@ -141,16 +141,16 @@ and the body.

{ "name": ":the-name" }

Varaibles can also be set based on the body of a response using the per-request hooks
Variables can also be set based on the body of a response using the per-request hooks

# set a variable :my-ip to the value of your ip address using elisp evaluated in the result buffer
GET http://httpbin.org/ip
-> run-hook (restclient-set-var ":my-ip" (cdr (assq 'origin (json-read))))

# same thing with jq if it's installed
GET http://httpbin.org/ip
GET http://httpbin.org/ip
-> jq-set-var :my-ip .origin

# set a variable :my-var using a more complex jq expression (requires jq-mode)
GET https://httpbin.org/json
-> jq-set-var :my-var .slideshow.slides[0].title
Expand All @@ -163,14 +163,14 @@ Restclient now allows to specify file path to use as a body, like this:
Content-type: text/plain

< /etc/passwd

### Caveats:

- Multiline variables can be used in headers or body. In URL too, but it doesn't make sense unless it was long elisp expression evaluating to simple value.
- Yet same variable cannot contain both headers and body, it must be split into two and separated by empty line as usual.
- Variables now can reference each other, substitution happens in several passes and stops when there's no more variables. Please avoid circular references. There's customizable safeguard of maximum 10 passes to prevent hanging in this case, but it will slow things down.
- Variable declaration only considered above request line.
- Be careful of what you put in that elisp. No security checks are done, so it can format your hardrive. If there's a parsing or evaluation error, it will tell you in the minibuffer.
- Be careful of what you put in that elisp. No security checks are done, so it can format your hard drive. If there's a parsing or evaluation error, it will tell you in the minibuffer.
- Elisp variables can evaluate to values containing other variable references, this will be substituted too. But you cannot substitute parts of elisp expressions.

# Customization
Expand Down
2 changes: 1 addition & 1 deletion restclient-jq.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

(defun restclient-jq-interactive-result ()
(interactive)
(flush-lines "^//.*") ;; jq doesnt like comments
(flush-lines "^//.*") ;; jq doesn't like comments
(jq-interactively (point-min) (restclient-jq-result-end-point)))


Expand Down
18 changes: 9 additions & 9 deletions restclient.el
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
(let ((json-special-chars (remq (assoc ?/ json-special-chars) json-special-chars))
;; Emacs 27 json.el uses `replace-buffer-contents' for
;; pretty-printing which is great because it keeps point and
;; markers intact but can be very slow with huge minimalized
;; markers intact but can be very slow with huge minimized
;; JSON. We don't need that here.
(json-pretty-print-max-secs 0))
(ignore-errors (json-pretty-print-buffer)))
Expand All @@ -329,7 +329,7 @@
(replace-match (char-to-string (decode-char 'ucs (string-to-number (match-string 1) 16))) t nil))))

(defun restclient-http-handle-response (status method url bufname raw stay-in-window)
"Switch to the buffer returned by `url-retreive'.
"Switch to the buffer returned by `url-retrieve'.
The buffer contains the raw HTTP response sent by the server."
(setq restclient-within-call nil)
(setq restclient-request-time-end (current-time))
Expand Down Expand Up @@ -360,7 +360,7 @@ The buffer contains the raw HTTP response sent by the server."
(intern (downcase (match-string 1)))
'utf-8)))
(if image?
;; Dont' attempt to decode. Instead, just switch to the raw HTTP response buffer and
;; Don't attempt to decode. Instead, just switch to the raw HTTP response buffer and
;; rename it to target-buffer-name.
(with-current-buffer raw-http-response-buffer
;; We have to kill the target buffer if it exists, or `rename-buffer'
Expand Down Expand Up @@ -500,7 +500,7 @@ The buffer contains the raw HTTP response sent by the server."
(defun restclient-single-request-function ()
(dolist (f restclient-curr-request-functions)
(ignore-errors
(funcall f)))
(funcall f)))
(setq restclient-curr-request-functions nil)
(remove-hook 'restclient-response-loaded-hook 'restclient-single-request-function))

Expand Down Expand Up @@ -625,7 +625,7 @@ Optional argument STAY-IN-WINDOW do not move focus to response buffer if t."
(backward-char 1)
(setq deactivate-mark nil))

(defun restclient-show-info ()
(defun restclient-show-info ()
;; restclient-info-buffer-name
(interactive)
(let ((vars-at-point (restclient-find-vars-before-point)))
Expand All @@ -643,13 +643,13 @@ Optional argument STAY-IN-WINDOW do not move focus to response buffer if t."
(insert (format "* %s \n|--|\n|Name|Value|\n|---|\n" table-name)))
(var-table-footer ()
(insert "|--|\n\n")))

(with-current-buffer (get-buffer-create restclient-info-buffer-name)
;; insert our info
(erase-buffer)

(insert "\Restclient Info\ \n\n")

(var-table "Dynamic Variables")
(dolist (dv restclient-var-overrides)
(var-row (car dv) (cdr dv)))
Expand Down Expand Up @@ -694,7 +694,7 @@ Optional argument STAY-IN-WINDOW do not move focus to response buffer if t."
(end-of-line)
;; If the overlays at this point have 'invisible set, toggling
;; must make the region visible. Else it must hide the region

;; This part of code is from org-hide-block-toggle method of
;; Org mode
(let ((overlays (overlays-at (point))))
Expand Down Expand Up @@ -738,7 +738,7 @@ Optional argument STAY-IN-WINDOW do not move focus to response buffer if t."
(define-key map (kbd "C-c C-.") 'restclient-mark-current)
(define-key map (kbd "C-c C-u") 'restclient-copy-curl-command)
(define-key map (kbd "C-c n n") 'restclient-narrow-to-current)
(define-key map (kbd "C-c C-i") 'restclient-show-info)
(define-key map (kbd "C-c C-i") 'restclient-show-info)
map)
"Keymap for restclient-mode.")

Expand Down