Menu

Category Archives: emacs

Org mode is wonderful for managing todo lists. Usually to add a task, I would run org-capture using the default C-c c and then select my todo template by hitting t. I do this so often that I wanted a shorter shortcut, so I defined a function to call org-capture with the specific template I wanted and bound this to a simple shortcut (I used C-9 after removing numeric prefixes):

This is not exactly an Emacs post, but some users of the mighty mu4e might find it useful. I don’t like big alerts to new emails that distract me from what I am doing, but I also don’t want to keep switching to my mu4e buffer to see if new emails have arrived. My solution is to have a small notification item in my Mac status bar to tell me how many emails I have.

It looks like this (the bit underlined in red):

The text @ 1/3/0/0 tells me that I have, respectively,

1 unread email in my inbox.

3 total emails in my inbox (i.e. 3 too many!).

0 emails in my drafts folder. This is useful to keep an eye on in case I save a draft and then forget about it.

0 emails in my outbox. This is my postfix email outbox and is useful to keep an eye on in case emails sent when I’m offline don’t get automatically sent when I reconnect.

To set this up I use shellwrangler which is a small app that embeds the output of a script in the status bar. This then calls the following perl script which generates the text. Shellwrangler updates at a specified interval so that is all there is to it.

Sometimes in my research I need to extract tabular data from a pdf paper. I can copy and paste the table into an Emacs buffer but the data is generally not formatted in a usable way. Luckily Emacs has a wealth of tools to reformat this sort of data.

Here is an animated gif illustrating some tools I use to do this (of course there are lots of other ways to do the same thing).

In the animation I use the following tools

C-x h to select the whole buffer.

C-c | to run org-table-create-or-convert-from-region to convert the region to an org table. This doesn’t get me all the way to where I want to be, but I find it helpful to see the data clearly.

M-S-<left> to delete some unwanted columns

mc/mark-next-like-this from multiple cursors to give me a cursor on each line (I bind this to M-.)

The wonderful ivy library provides a command ivy-view which allows you to quickly bookmark the current arrangement of windows in your Emacs frame. The nice thing is that once you do this, the bookmarked arrangement then appears in your ivy-powered buffer switching list so changing back to the arrangement you had is as easy as switching buffers. This make a lightweight alternative to other mathods for managing window layouts.

To use this, just run ivy-push-view to store the current view, and optionally give it a name (a useful default we be offered). This will then be offered when you switch buffer using ivy-switch-buffer (which you are using automatically if you use ivy-mode). To make these ivy-views appear in your buffer list, you might need to set the option

To set up lists of multiple email multiple recipients with mu4e, you can make use of mail aliases. To do this, add lists to a file with the following format, with the word “alias” followed by the name you want for the list, followed by a space-separated list of email addresses:

The minibuffer is the area at the bottom of your Emacs frame where you interact with Emacs prompts, or type commands. It also doubles up as the echo area, where Emacs tells you useful things. However sometimes when Emacs is prompting me for an answer in the minibuffer, the prompt is hidden by a message so I can’t see what I’m being asked any more.

When this happens, I found it is almost always a message about a buffer being reverted or a file being auto-saved. These messages can be prevented from appearing in the echo area as follows.

The revert messages are easy to silence with the following setting:

;; turn off auto revert messages(setq auto-revert-verbose nil)

For the auto-save messages, it is a bit trickier. Some solutions suggest advising do-auto-save which is the function that does the actual job of auto-saving (e.g. this stackexchange question). However, this doesn’t work for Emacs 24.4 and newer since the call to do-auto-save bypasses the advice, for technical reasons I don’t fully understand!

A work around is to switch off the built-in auto-save, and replace it with our own silent version:

;; custom autosave to suppress messages;;;; For some reason `do-auto-save' doesn't work if called manually;; after switching off the default autosave altogether. Instead set;; to a long timeout so it is not called.(setq auto-save-timeout 99999);; Set up my timer(defvarbjm/auto-save-timer nil
"Timer to run `bjm/auto-save-silent'");; Auto-save every 5 seconds of idle time(defvarbjm/auto-save-interval 5
"How often in seconds of idle time to auto-save with `bjm/auto-save-silent'");; Function to auto save files silently(defunbjm/auto-save-silent()"Auto-save all buffers silently"(interactive)(do-auto-save t));; Start new timer(setq bjm/auto-save-timer
(run-with-idle-timer 0 bjm/auto-save-interval 'bjm/auto-save-silent))

Note that I found some strange behaviour that do-auto-save does not work if the built-in auto-save is switched off altogether using (setq auto-save-default nil), so instead I had to set it for a long timeout to prevent it from running.

The package dired-quick-sort gives you a pop-up menu with lots of useful options to sort your dired view by name, time, size and extension, and optionally group all of the directories together at the top of the listing. This can be a bit fiddly and dired-quick-sort makes it really easy.

However, I wanted to generate a separate pdf file for each candidate that I could circulate to interviewers (since each interviewer was only interviewing a subset of applicants).

I came across this stackexchange answer that demonstrated how to build a function to export top level headlines to separate files. There are a few variations on that page, and I put together the slightly tweaked version below. All of the credit goes to stackexchange user itsjeyd for a very detailed answer. In my version I hard code it to export to pdf, save the file first, and apply the export options from the parent file to each of the new files that are created. The new files have a name taken from the headline, with spaces replaced by underscores, unless the :EXPORT_FILE_NAME: property is set for a headline.

I’ve written before about the wonderful multiple-cursors package. Usually I use it by hitting M-. (defined using the setup below) to fire off multiple cursors on successive lines or on successive occurrences of the current string (if some text is selected). I also use M-, if I want to remove some of those cursors. This covers 99% of my use of multiple cursors.

However, occasionally, the best way to get the cursors where you want them is with the mouse. With the following code, C-S-<left mouse click> adds a new cursor.