dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 3aa58e31b923f7a1492538870e1313133479e886
parent c720993976d8cdbd9c2384aa7d63c0b5c4d5e86f
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Thu,  6 Jul 2023 22:37:33 +0300

Add README.org to README.html to sourcehut code. Also:

Turn on rainbow-delimiters by default.

Diffstat:
Mconfig/emacs/init.el | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+), 0 deletions(-)

diff --git a/config/emacs/init.el b/config/emacs/init.el @@ -9,7 +9,9 @@ ("C-c n i" . org-roam-node-insert)) ;;:config (org-roam-setup) ) + (show-paren-mode) +(rainbow-delimiters-mode) (org-babel-do-load-languages 'org-babel-load-languages @@ -47,6 +49,108 @@ (kakafarm/set-key-bindings)) + +(progn + (defun kakafarm/call-process-with-string-as-input (program &optional input-string &rest args) + (with-temp-buffer + (let ((our-output-buffer (current-buffer))) + (if input-string + (with-temp-buffer + (let ((our-input-buffer (current-buffer))) + (progn + (erase-buffer) + (insert input-string) + (apply 'call-process-region + (buffer-end -1) + (buffer-end 1) + program + nil + our-output-buffer + nil + args)))) + (apply 'call-process + program + nil + our-output-buffer + nil + args))) + (buffer-string))) + + (list (kakafarm/call-process-with-string-as-input "cat" + "cat says moo") + (kakafarm/call-process-with-string-as-input "echo" + nil + "-n" + "echo echo echo"))) + + +(progn + ;; Uploading README.html from README.org stuff. + + (defun kakafarm/srht-repo-id (repository-name) + "Returns the unique numerical I Dentification associated with +every sourcehut repository. + +https://www.tomsdiner.org/blog/post_0003_sourcehut_readme_org_export.html" + + (interactive "sRepo name: ") + (let* ((srht (netrc-machine (netrc-parse "~/.netrc.gpg") + "repo.git.sr.ht")) + (srht-token (netrc-get srht + "password")) + (our-response (with-temp-buffer + (call-process "curl" + nil + (list (current-buffer) nil) + nil + "--oauth2-bearer" srht-token + "-G" + "--data-urlencode" + (concat "query=query { me { repository(name: \"" + repository-name + "\") { id } } }") + "https://git.sr.ht/query") + (buffer-string))) + (repository-id (string-trim (kakafarm/call-process-with-string-as-input "jq" + our-response + ".data.me.repository.id")))) + (if (called-interactively-p) + (message "Repository ID: %S" repository-id) + repository-id))) + + (defun kakafarm/srht-set-readme (repository-id) + "Export the current file to HTML and set the result as README for +the sourcehut repo identified by ID. + +https://www.tomsdiner.org/blog/post_0003_sourcehut_readme_org_export.html" + + (interactive "sRepository ID: ") + (let* ((srht (netrc-machine (netrc-parse "~/.netrc.gpg") + "repo.git.sr.ht")) + (srht-token (netrc-get srht + "password")) + (readme.html (org-export-as (org-export-get-backend 'html) + nil + nil + t)) + (our-json-query (kakafarm/call-process-with-string-as-input + "jq" + readme.html + "-sR" + (concat " +{ \"query\": \"mutation UpdateRepo($id: Int!, $readme: String!) { updateRepository(id: $id, input: { readme: $readme }) { id } }\", + \"variables\": { + \"id\": " repository-id ", + \"readme\": . + } +}")))) + (kakafarm/call-process-with-string-as-input "curl" + our-json-query + "--oauth2-bearer" srht-token + "-H" "Content-Type: application/json" + "-d@-" + "https://git.sr.ht/query")))) + ;; Use another file for the ``customize'' customisations. (setq custom-file (locate-user-emacs-file "custom-variables.el")) (load custom-file 'noerror 'nomessage)