Blogging about blogging01 Feb 2015
In Emacs, of course. As I mentioned before, this blog is run using Jekyll and a fork of the lanyon theme.
It started out pretty convenient: thanks to
jekyll serve I would see
the live updates at
http://localhost:4000/ as I was editing the
markdown. But after a few posts, I've experienced a drastic decrease
in refresh time: it went from under a second to 15 seconds. Below, I'll show how I've managed
to speed it back up.
No posts - no problem
(require 'dired-x) I can jump from the current post to the
posts directory with C-x C-j. It even puts the point on the current file. Now:
- m to mark to current file
- t to invert the mark, making the current file unmarked and all others marked
- D to delete all marked files. No need to worry, since
they are all version-controlled (except the original one, which isn't
diredeven asks you for confirmation, so I hit y.
Now, that there is only one post in the whole blog,
jekyll serve is
much faster at refreshing.
Which brings me to the next point. Since I'm calling it so much, might as well wrap it in some Elisp. Elisp is like frosting - it makes everything better:
(defun jekyll-serve () (interactive) (let* ((default-directory (if (string-match "_posts/$" default-directory) (directory-parent default-directory) default-directory)) (buffer (if (get-buffer "*jekyll*") (switch-to-buffer "*jekyll*") (ansi-term "/bin/bash" "jekyll"))) (proc (get-buffer-process buffer))) (term-send-string proc "jekyll serve\n") (sit-for 3) (browse-url "localhost:4000")))
This function, when called from the current post or the current blog, will:
- open a new
- issue a
jekyll servecommand to it
- wait for 3 seconds for Jekyll to start
One post isn't a blog
Here's how to quickly bring back the deleted posts.
- Fire up magit; I have
magit-statusbound to μm.
- Stage the current post with s (
- Start the commit with C (
magit-commit-add-log). I'm using my own modification of
magit-commit-add-logthat arranges the whitespace in a nice way, when aimed at a file instead of a hunk.
- I get
_posts/2015-02-01-blogging-about-blogging.md:string auto-generated by C.
- I just amend it to look like
_posts/2015-02-01-blogging-about-blogging.md: addand finalize the commit with C-c C-c (
- Now I have around 40 files marked as deleted, but not staged. I create a stash with zz and name it
fooor something. Then delete the stash with
magit-discard-item, which I like to bind to d to be similar to
dired. Now it's as if these files were never deleted.
Whoa, now that I look at it, it's a lot of steps. But somehow
magit are very similar to
Super Mario Bros: it
takes long to explain what you're doing, but as you play it, it's very
simple and natural.