Blogging with Emacs Org-Mode

Blogging with Emacs Org-Mode
Thanks to the many plug-ins for Emacs, you can write to your blog from inside your favourite editor. This is useful for people that use their favourite editor most of the day. To post to your WordPress blog, you can use Org2blog. It is easy to setup and has a nice user-interface to boot.

For other platforms you have other packages, the standard term for plug-ins, in Emacs. If you use Googles Blogger, you need to install bpe. There are several other packages that support Jekyll and other parsing systems.

There is also a package for those of you who uses the Tinkerer blogging engine. More on that in another post.

The Org2blog package

The org2blog package calls the WordPress site and sends your blogs there. This works on both self-hosted and the free WordPress.com website. The package is available from MELPA or Github. If you take it from GitHub, you need to add it to your path, on your own. This is useful if you want to follow updates or even contribute. You will have to make sure the dependencies are installed though. The package depends on:

xml-rpc metaweblog.el htmlize

You can add these from MELPA, using ‘package’.

$ ‘M-x install-package xml-rpc metaweblog htmlize

The code to include the package if you have copied it in, add the following code to your .emacs file or directory.

(setq load-path (cons "~/.emacs.d/org2blog/" load-path))
(require ‘org2blog-autoloads)

Defining your credentials and platforms.

Before you can do anything, you need to define what and where you are about to publish to. This requires more code in your .emacs file or directory. To define your credentials add this to your .emacs file.

(setq org2blog/wp-blog-alist
‘(("my-blog"
:url "https://example.com/xmlrpc.php"
:default-title "How To "
:username "admin")
("My-other-blog"
:url "https://other.example.com/xmlrpc.php"
:default-title "My new recipe "
:username "Johnny")
))

Note that this is a list, if you have many blogs, add them to the list. Be careful with the parenthesis, they are key to LISP. You set the username to your own, of course. The password comes later, just below here. You also have more settings than this, default-categories is one option. When you want to send a post, first, you have to be logged in. Logging in is done with:

‘M-x org2blog/wp-login’

The minibuffer will ask you which blog you want to post to. If you have put the same code as above you can only choose ‘my-blog’. What you call it, is up to you. You can also create one entry for each blog you have, if you have many. A warning, as of this writing, the setting below while needed, is not set by default. You may need to set this in your .emacs.d files(s).

(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")

Now, you have logged in, you can start creating.

Drafting, previewing and publishing.

To create a new post, you have the option to call ‘M-x org2blog/wp-new-entry’ or use the Hydra page. On the Hydra page, you have a list of options including to add a new entry. You will have a new buffer with default values set. You can set those default values your self. Those settings are set the same way any Org-mode documents have their settings. In general, the values control how an export works. They also contain the tags, category and other values. While you are writing a post you can set these in the top of the document. It is not strictly necessary to have it in the top but it makes it easy to find for long posts. The format has a ‘#+’ and then the value you want to set.

#+TITLE How to blog on the command line
#+OPTIONS toc:nil num:nil todo:nil pri:nil tags:nil ^:nil
#+TAGS Geeks, bash, emacs
#+CATEGORY Linux, MacOS
#+DESCRIPTION This post covers all manners of blogging to command line
#+DATE <2019-07-28 Sun>

The values are all optional but it is great to have it set for your post. The tags are the tags on the blogs, categories are the ones you already have or you can put a new one. Org2blog will ask you if it should create the new category later when you post. Once you have written your post, you can create a draft and view it with the below command.

‘M-x org2blog/wp-post-buffer’ or ‘M-x org2blog/wp-post-buffer-and-publish’

The first will create a draft for you to check over and the second will publish it to your blog. You can also change an existing post, all you need is the post-id which is created when you post your post. The value is at the top of your local copy of your post.

Conclusion

Using Emacs to blog is an excellent way to get your message out. You will need to get used to a new way of creating your post if you are using the web based editor until now. However, if you are considering to do this, you are probably in your editor most of the time which makes the transition simpler.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *