asdf as environment manager
so much faster
- tags
- asdf
This has been updated
This blog is basically my labnotes where I explore different parts of technology. Almost all of my coding related activity starts off in this repo, while I explore different things to see how they work. I have a lot of things in drafts, and I wanted to learn how to build a simple emacs interface to let me navigate around my file system.
I couldn't find any good documentation on how to do anything with
tabulated-list-mode
so I spend the evening poking around and seeing
how it works. Here you go.
The final file is blog.el
I have my repo checked out at ~/willschenk.com
, and I put all my work
in content/articles
and then the year. So this file is called
/home/wschenk/willschenk.com/content/articles/2021/emacs_blogging_mode/index.org
Sometimes the org
file is at the top level directory, and in the past
I wrote in md
files so I want to make sure that they come through as
well.
|
|
tabulated-list-mode
worksThe basic idea is that
tabulated-list-mode
tabulated-list-format
, and some
other stuffYou create a function that
tabluated-list-entries
, which is a list of lists, the first
element being the key and the following elements are the data(tabulated-list-print t)
which displays the datakey
is returned by tabulated-list-get-id
.One tricky thing to figure out is how to create the data. It looks like
|
|
Which you can create using (list key1 (vector col1 col2 col3))
if you
want to actually use the values that col1
points to rather than the
symbol col1
itself. Yay lisp!
Let's get started.
This function takes a file, and passes it through awk
to parse the
front matter. We will basically call this 4 times for each file to
pull out the title
, date
, draft
, and tags
.
|
|
Also, I'm removing any quotes around the results.
.org
fileThis takes a file, and pulls out the attributes. I'm assuming that the first ones it find is actually the top matter, we ignore all other matches other than the first.
|
|
|
|
md
fileDepending upon what sort of front matter you use, you may need to
adjust the regex. All my old markdown files are using yaml
and not
toml
, so your mileage may vary.
|
|
|
|
For short posts that don't have any tangling or other sub objects, my
org
files live in the year directory. For others, it's either going
to be index.md
or index.org
so if we get a directory lets see which
one is in there.
|
|
|
|
Given a file name or a directory, figure out which parse method knows how to make sense of it.
|
|
|
|
I'm again shelling out to the find
command with -maxdepth
of 2
to give
me a list of the files and/or directories that contain blog posts.
For each of the files, I'm parsing them to get the data in tab form
that the mode knows how to deal with.
dolist
was fun to figure out.
|
|
|
|
We create a derived mode called blog-mode
from tabulated-list-mode
.
In it we set the columns, padding, sort order (on date) and
explicitely tell it to use our mode map, blog-mode-map
defined below.
It's unclear why it doesn't pick it up automatically, but I needed to
call it out specifically.
We also create a blog-list
function which is our entry point. This
creates and opens a new buffer, switches it to blog-mode
, loads in our
data, and then tells it to display. tabulated-list-entries
is local
to the buffer, by the by, so you can have multiple modes using the
same variable.
|
|
Here I'm defining some functions that are specific to our mode.
? | Help |
o | Open the selected file |
r | Refresh lists |
d | Only show drafts |
p | Only show published posts |
a | Show all posts |
c | Create a new post |
s | Start the hugo process |
For fun I also created a transient
popup which shows all of this.
|
|
I set the key to be the filename, so (find-file
(tabulated-list-get-id))
opens the file.
|
|
These functions filter the blog-mode-entries
variable to filter what
is displayed. I'm not sure how I feel about calling
tabulated-list-print
each time but it seems to work.
|
|
I like my urls to be the same as the title, so the first function here normalizes the title to fit in the filesystem. I've forgotten where I copied this code from, by thank you internet.
I have two types of posts. "mini" which just means its a standalone
file, and a full post, which is in a directory. I also turn on
automatic org-babel-tangle
on save, which I set as a local org
variable.
|
|
This is probably too particular for my machine, since I run hugo
inside of a docker container so I need to start it with a script, but
this function starts hugo if it isn't running, then waits 5 seconds to
call xdg-open
to bring it up in the browser.
|
|
|
|
I couldn't find any good tutorials on how to write an emacs mode to interact with my system, so I thought I should write one. I think there's probably something on YouTube but it didn't show up in any search algorithms so hopefully this is helpful.
Previously
Next