Emacs systemd service

Since upgrading to Ubuntu 15.04, I’ve been living with systemd. I’ve been a Debian user mainly and was wary of the doom-and-gloom comments about systemd but actually, I’ve been a bit impressed with it so far. One thing that is undeniably easier with systemd is writing what System V init sytems called init scripts. In systemd they are known as service files.

Anyway, I usually run emacs as daemon and I had the idea that emacs could run as a systemd service! Immediately I fell into the trap that Umberto Eco describes:

there are two laws no human being can escape: the first idea that comes into a person’s mind will be the most obvious one; and, having had an obvious idea, nobody ever thinks that others may have had the same idea before.

So yes, there plenty of systmed emacs service files out there, but this one is mine.

[Unit]
Description=Emacs daemon
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
Restart=always
Environment=SSH_AUTH_SOCK=/run/user/1000/keyring/ssh GPG_AGENT_INFO=/run/user/1000/keyring/gpg:0:1
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

The main difference from my config is that I’ve added the GPG_AGENT_INFO data so that emacs can uses GPG agent. I run keychain so my ssh-agent and gpg-agent are launched at login. There are probably nicer ways to pass the environment variables. This only works if you user ID is 1000, which it most likely will be if you are the first user. Just check the output of id -u and change the 1000 to whatever it says and it will probably work.

Lastly, I run this service as a user so I put the file in ~/.config/systemd/user/emacs.service and then did:

systemctl --user enable emacs.service   
systemctl --user start emacs.service

I use emacsclient to connect to the server, which I’ve aliased to just e, so I’ll type e -nc to open a new instance for example.

Back in (BeagleBone) Black

After a short hiatus, I’ve dusted off my BeagleBone Black (BBB) and started tinkering again.  This time I replaced Angstrom with Ubuntu 13.04.  Angstrom is a good distribution for the truly embedded projects, i.e. ones that require a small footprint and low-level IO, but for more application-level play, I think Ubuntu is a bit more user friendly.

Continue reading “Back in (BeagleBone) Black”

Slight enhancement to fortune.el

The fortune utility remains one of my favorite programs (after all, it’s the name of this blog 🙂 ).  The random quotes are a refreshing reminder not to take myself too seriously.  But since I’ve been using byobu and GNU Screen, I rarely see the fortune cookie when my shell starts.

But then I realized what I really wanted was to see fortunes in Emacs.  Fortunately, there is a package, fortune.el, included in Emacs which provides a front-end to the fortune program.  When invoked with M-x fortune it throws the cookie into a new buffer and makes the new buffer active, which is slightly annoying.

What would be better would be to display the fortune in the mini-buffer.  Well, with the following code in your .emacs (or personal directory in prelude 😉 ), M-x fortune-message will do just that.  I’m considering submitting a patch, but there appears to be a bit of a procedure that I must review first.

(require 'fortune)
;; Be sure to set the following to your specific fortune files
(setq fortune-dir "~/.fortunes"
fortune-file "~/.fortunes/fortunes")
(defun fortune-message (&optional file)
"Display a fortune cookie to the mini-buffer.
If called with a prefix, it has the same behavior as `fortune'.
Optional FILE is a fortune file from which a cookie will be selected."
(interactive (list (if current-prefix-arg
(fortune-ask-file)
fortune-file)))
(message (fortune-generate)))
(defun fortune-generate (&optional file)
"Generate a new fortune and return it as a string.
Without an optional FILE argument it will use the value of `fortune-file'."
(save-excursion
(progn (fortune-in-buffer t file)
(with-current-buffer fortune-buffer-name
(buffer-string)))))

view raw
fortune-message.el
hosted with ❤ by GitHub

Although, to get fortune.el to work I had to create a new writable fortune file as it was not satisfied using the read-only fortunes included with my distribution.  And now I have cookies on demand (om nom nom…)

emacs_om_nom_nom
Yeah sorry… I couldn’t resist 🙂

 

Byobu: Fancy window dressings on GNU Screen

As I’m working more on the command line now, I’ve been trying to incorporate GNU Screen into my workflow. Some might argue it’s a bit redundant when using a window manager and a terminal that supports tabbed sessions, but I prefer not to deal with the tabs and it’s nice to attach to a screen and pick up where I left off.

And I was quite happy with GNU Screen. The only issue is that I had to change the default escape key \C-a to \C-\ since I heavily use \C-a in both Emacs, GNU readline and zsh to go to the beginning of the line. (Actually, I use prelude’s smarter-move-beginning-of-line in Emacs.) Anyway, I quickly changed the escape to C-\ with this line in the .screenrc: escape ^\\\.

But then I stumbled onto Byobu, which provides a set of “window-dressings” for GNU Screen (and Tmux if you prefer). The default backend is Tmux but it can be easily changed to GNU Screen. All of the normal screen commands work as you’d expect but I like the extra mode lines on the bottom of the terminal. The bottom lines are bit flashy if you prefer the simplicity of GNU Screen, but the notifications can be customized for a slew of options including an option to add your own.  So far I’m liking it 🙂

 

Byobu screenshot
Byobu’s man page while running byobu

A better Emacs configuration

I finally gave in and forked Bozhidar Batsov’s Emacs bundle, Prelude.  Initially I resisted using an out-of-the-box setup and tried to roll my own, but as I added more customizations I realized that I was slowly incorporating all of Prelude.  Then I recognized that Prelude’s organization is much cleaner than my approach.  It’s also very easy to fork the repo and add in personal touches as I’ve done here.

I’m working through some growing pains in the switch to Prelude from my spaghetti framework, but Bozhidar provided one line install scripts and I also like how all external packages are auto-downloaded from the package manager.  If you are new to Emacs or you want to use a customization that 409 other forkers are using, try Prelude (must have Emacs 24 btw).

oh-my-zsh and fun with fonts

After viewing this slideshare on the Z shell (zsh), I decided to give it a spin.  As recommended in the presentation, I went ahead and setup oh-my-zsh as well.  At first, it was a bit awkward moving around, I mean the cd completions happen under the prompt!  But then I cd‘d to a git directory and I don’t think I’m switching back.  The git plugin has really nice command completion and the prompt itself shows the branch name. Continue reading “oh-my-zsh and fun with fonts”

Emacs on the Beaglebone

I’ve been playing around with my BeagleBone (BB) lately and it’s felt a bit, incomplete. It’s not because it has a faster and cheaper brother out there now either (BeagleBone Black (BBB)). It’s because it didn’t have Emacs installed! 🙂

emacs_on_all_the_things

Unfortunately, Emacs is not even in the Angstrom package browser. I did find a post which claimed at one point it was listed, but alas, no more. So, to the source we go. Continue reading “Emacs on the Beaglebone”

ShareLaTeX: Collaborative LaTeX editing with style

For anyone who is a fan of \LaTeX, there is a great site, ShareLaTeX, that allows editing of LaTeX files via the browser. Never used \LaTeX? Well, it’s a rich typesetting system that among other things, allows for pretty printing of mathematics, like this: P(A|B) = \frac{P(B|A)P(A)}{P(B)}. (Bayes’ theorem has been on my mind a lot lately…).

Ok, that looks cool, but why would one anyone use this? Well, you might have to if you are a grad student. 😉 The \LaTeX learning curve can be quite steep, since it’s a completely different philosophy to editing documents than the “Microsoft Word” way. It is not a WYSIWYG system. Similar to how one compiles source code, \LaTeX documents are compiled into pdfs, dvis, etc…

ShareLaTeX closes the write / compile / view loop and has a nice side-by-side edit and view display. In the spirit of Bret Victor’s life principle that creator’s need an immediate connection, ShareLaTeX allows for instant feedback with the typesetting process.

Lastly, they just incorporated some pretty advanced features. Their blog has the latest news, but latexdiff looks especially cool.

latexdiff in action
Wow! Let’s see Word do this! :p

If you are an Emacs/ AUCTeX user there is still a good use case for shareLaTeX.  Until you get Emacs on your Chromebook, you’ll need an online \LaTeX editor. 😉  And they even support Emacs key bindings! (and also cough vi cough)

 

Ich liebe Freie Software

Today’s title is a tip of the hat to the Free Software Foundation Europe (FSFE), which celebrates “I love Free Software Day” each Valentine’s Day.

I love Free Software!
…and everybody loves ASCII art 🙂

Much of the software I use on a daily basis is free software, including Emacs which I’m using to compose this post and WordPress, the software running this blog. Free software lives on as a result of dedicated volunteers all over the world. Without them, I would not be enjoying Emacs on my Chromebook!

Lots of other people love free software too. So show your support for free software today. But if you have spouse, partner, significant other, or whatever, you may want to wish them Happy Valentine’s Day first. Don’t worry, free software will understand…

My personal emacs doctor was not as supportive as I would have thought.  Maybe she's just maintaining a professional boundary...
My personal emacs doctor was not as supportive as I would have thought. Maybe she’s just maintaining a professional boundary…

Emacs24 in ChrUbuntu on Samsung ARM Chromebook

All good things happen while procrastinating… In this case I now have emacs24 running in ChrUbuntu on my Chromebook!

Emacs 24 on the ARM chromebook
Emacs 24 on the ARM chromebook under ChrUbuntu

Here’s what I did:

  1. Make sure to run apt-get update and refresh all of your packages.
  2. I used the update manager gui to update a ton of packages.
  3. Download the emacs 24 source: emacs-24.2.tar.gz
  4. There are a few other packages missing, which I learned through multiple configure grumblings. But this line should get you all the required dependencies: sudo apt-get install libgtk2.0-dev libjpeg-dev libxpm-dev libgif-dev libtiff-dev libncurses-dev
  5. Then fire off the normal build steps of: configure; make; sudo make install

Enjoy 🙂

The first configure error I ran into
The first configure error I ran into