~louis77/sourcehut.el

078834d6ba106b683a72c6ec4d6542232ee8d306 — Louis Brauer 3 months ago 8c64ad2
Update documentation
1 files changed, 18 insertions(+), 9 deletions(-)

M sourcehut.el
M sourcehut.el => sourcehut.el +18 -9
@@ 32,13 32,13 @@


(defcustom sourcehut-personal-access-token ""
  "Personal Access Token for Sourcehut instance"
  "Personal Access Token for Sourcehut instance."
  :type 'string
  :group 'sourcehut)


(defcustom sourcehut-instance-url "https://paste.sr.ht"
  "URL of the paste service. Overwrite if you host your own"
  "URL of the paste service.  Overwrite if you host your own."
  :type 'string
  :group 'sourcehut)



@@ 53,19 53,25 @@


(defun sourcehut-initialize (token)
  "Ask user for initial values, specifically for the Sourcehut Personal Access Token"
  "Ask user for initial values, specifically for the Sourcehut Personal Access TOKEN."
  (interactive "sSourcehut Personal Access Token: ")
  (customize-save-variable 'sourcehut-personal-access-token token))


(defun srht-paste-make-body (visibility filename content)
  "Create JSON payload for the paste from given parameters"
  "Create JSON payload for the paste from given parameters.
Argument VISIBILITY one of private, unlisted or public.
Argument FILENAME the filename of the paste.
Argument CONTENT the paste content."
  (json-encode `(("visibility" . ,visibility)
		 ("files" . ((("filename" . ,filename)
			      ("contents" . ,content)))))))


(defun srht-paste-callback () ;n(status &rest args)
;; (status &rest args)
;; Callback is called with these args, however we don't use them for now.hec
(defun srht-paste-callback ()
  "Is called after the request to sourcehut is completed.
The current buffer is the response of the request, which we parse here."
  (zap-up-to-char 1 ?{)
  (let* ((obj (json-parse-buffer))
	 (user-obj (gethash "user" obj))


@@ 79,19 85,22 @@


(defun sourcehut-get-content ()
  "Extract the content we want to paste.
Either the active region or, if no region is active (i.e. text selected)
the whole buffer."
  (if (use-region-p)
      (buffer-substring-no-properties (region-beginning) (region-end))
    (buffer-string)))


(defun sourcehut-paste-region (visibility filename)
  "Paste region or buffer to paste.sr.ht"
  (interactive 
  "Paste region or buffer to sourcehut under FILENAME with VISIBILITY."
  (interactive
   (list (completing-read "Visibility: "
			  '("private" "public" "unlisted") nil t)
	 (read-string (format "Filename (default: %s): " (buffer-name))
		      nil nil (buffer-name))))
  (unless (sourcehut-customized-p) (call-interactively 'sourcehut-initialize)) 
  (unless (sourcehut-customized-p) (call-interactively 'sourcehut-initialize))
  (let* ((content (sourcehut-get-content))
	 (url-request-method "POST")
	 (url-request-extra-headers