So today I tried to write my first fully custom Emacs Lisp
code. Here are some things I learned (along with the code
Here is my final product, uploaded straight from Emacs.
The final script looks like this at the bottom of my
It is used by setting a mark
C-SPC, selecting a region
(arrow keys work to expand the region) then typing
M-x region-to-gist. The Function then runs and outputs
either an error message (hopefully not) or this to the
The most important part here is the
allows you to use
M-x region-to-gist to execute the
function. There are a couple different modes you can enable
region-active-p basically returns true if there’s a region
C-SPC and arrows stuff).
gist-test is a function I used to replace the
call so I could test whether or not the region was actually
being sent and resolve some formatting issues. This function
can be wholly deleted with no ramifications.
buffer-substring-no-properties returns undecorated strings
from your buffers. Use this is you’re trying to handle a
string (such as in JSON) and use
you’re trying to put something in the kill-ring, etc.
I’m using request.el
to make my request. It tries to use
curl if available.
The biggest part of the request code is the
function. In this case we grab the key
html_url from the
Gist API Response
The backtick here:
means we have to use the
,buf to get the value of
Oh, and also, this function should probably be called
gist-region as per other region functions. oops.