Emacs as an advanced terminal multiplexer

I really enjoy using Tmux and I love zsh, but I am missing something like ace-jump-mode to quickly jump to a line in my terminal and I would like to have snippets for everyday tasks like a for loop so some day I thought why not try using zsh in Emacs? And voila here is the config that let you jump around in your terminal by pressing “jj” and a head character as well as write you Yasnippets.
To use it you have to install multi-term, ace-jump-mode, key-chord and yasnippet.

(require 'multi-term)
(require 'ace-jump-mode)
(require 'key-chord)
(require 'yasnippet)

(key-chord-mode 1)
(setq key-chord-one-key-delay 0.15)
(key-chord-define-global "jj" 'ace-jump-mode)

(add-hook 'term-mode-hook (lambda ()
(setq yas/dont-activate nil)
(add-to-list 'term-bind-key-alist '("C-c C-n" . multi-term-next))
(add-to-list 'term-bind-key-alist '("C-c C-p" . multi-term-prev))
(add-to-list 'term-bind-key-alist '("C-c C-j" . term-line-mode))
(add-to-list 'term-bind-key-alist '("C-c C-k" . term-char-mode))

(global-set-key (kbd "C-c t") 'multi-term-next)
(global-set-key (kbd "C-c T") 'multi-term)

Now you can open a new terminal by pressing C-c T, switch between them with C-c C-n and C-c C-p and if you would like to copy some text in the middle of your screen first press C-c C-j to enable line-mode than jj to jump. The same applies for yasnippets first switch from char to line-mode (it makes your terminal a normal emacs buffer), type your keyword and expand it with tab. Here’s an example

# key: for
# --
for X in $1; do $0; done

Diffing directories

Sometimes I would like to recursively compare the files in two directories to see if one is missing in the other. Sometimes I would even like to discover files which contents are different in two directories.
So let’s see how Emacs can support me to do the job.

By executing M-x ediff-directories and inserting the two directories in question (or 3 directories by using ediff-directories3) and an optionally regexp to only match certain files Emacs will open a new buffer that lists the top of both directories.

To recursively compare them and get the differences just press == followed by a D. This will show you all different files. Subdirectories with differences contents dont have the prefix = and can be displayed by pressing enter.

You could also mark different files and directories and get a patch file by executing P.

Another but not builtin diff tool with a nicer UI is Ztree.

After the installation run it with M-x ztree-diff. This opens a new buffer, where you can hide/show all equal files and directories by pressing h and to copy or delete differences with C or D. No need to enter subdirectories thus it will give you a tree view per default.

Encrypted work diary

About two months ago the blog abesto.net inspired me to start a work diary. Being an Emacs lover the normal way for me to do it is of course in Emacs using Org-mode. By now the work diary helped me to keep track of Python debugging sessions and to remember what the hell I am doing at work and how I fixed a damn *peep* problem three weeks ago that’s now unfortunately crying again.

Here’s how I configured Emacs to give me an encrypted diary by pressing f8.

(setq org-capture-templates (quote (
("D" "diary" entry (file "~/organize/diary.org.gpg") "* %T %?"))))
(global-set-key [f8] 'org-capture)

I define an org-capture template that inserts a new line into the file ~/organize/diary.org.gpg. The ending .gpg is enough to let Emacs know it should be encrypted with GnuPG. The %T automatically inserts the current timestamp and %? includes the message you wrote. Afterwards i binded the key f8 to the org-capture function and that’s really all it needs! 🙂