Pastry though.
This commit is contained in:
parent
34c0e906a7
commit
87bb8233a4
1 changed files with 25 additions and 7 deletions
|
|
@ -77,16 +77,34 @@
|
||||||
;;; arc paste commands.
|
;;; arc paste commands.
|
||||||
(defun arc-paste (start end)
|
(defun arc-paste (start end)
|
||||||
"Pastes the specified region from START to END (or whole file) with arcanist.
|
"Pastes the specified region from START to END (or whole file) with arcanist.
|
||||||
The resulting URL is stored in the kill
|
|
||||||
ring and messaged in the minibuffer."
|
The resulting URL is stored in the kill ring and messaged in the minibuffer."
|
||||||
(interactive (if (use-region-p) `(,(region-beginning) ,(region-end))
|
(interactive (if (use-region-p) `(,(region-beginning) ,(region-end))
|
||||||
`(,(point-min) ,(point-max))))
|
`(,(point-min) ,(point-max))))
|
||||||
(let* ((extract-uri (lambda (output) (->> output (assoc 'uri) cdr))))
|
|
||||||
(->> (arc--call-conduit "paste.create"
|
|
||||||
`(:title ,(when (buffer-file-name) (file-name-nondirectory (buffer-file-name)))
|
|
||||||
:content ,(buffer-substring start end)))
|
|
||||||
(funcall extract-uri) message kill-new)))
|
|
||||||
|
|
||||||
|
(let ((title (when (buffer-file-name)
|
||||||
|
(list "--title" (file-name-nondirectory (buffer-file-name)))))
|
||||||
|
(content (buffer-substring start end)))
|
||||||
|
(with-temp-buffer
|
||||||
|
(let ((tmp-file (make-temp-file "arc-paste")))
|
||||||
|
(with-temp-file tmp-file (insert content))
|
||||||
|
(apply 'call-process "pastry" tmp-file `(,(current-buffer) nil) nil
|
||||||
|
"--json" title)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(let ((json-object-type 'alist)
|
||||||
|
(last-json))
|
||||||
|
(while (not (eobp)) ;; Pastry dumps *many* JSON objects.
|
||||||
|
(setq last-json (json-read))
|
||||||
|
(json-skip-whitespace))
|
||||||
|
(->> last-json ;; Starting with the last JSON object we got...
|
||||||
|
(assoc 'data) ;; ...grab the "data" element...
|
||||||
|
cdr ;; ...well, its value...
|
||||||
|
(assoc 'createdPaste) ;; ...then "createdPaste"...
|
||||||
|
cdr ;; ...(ugh)...
|
||||||
|
(assoc 'url) ;; ...then "url"...
|
||||||
|
cdr ;; ...(gosh darn it!)...
|
||||||
|
message ;; ...then show it to the user...
|
||||||
|
kill-new)))))) ;; ...and drop it into the kill ring. Easy!
|
||||||
|
|
||||||
;;; ----------------------------------------------------------------------------
|
;;; ----------------------------------------------------------------------------
|
||||||
;;; arc inlines commands
|
;;; arc inlines commands
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue