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-f to move forward by word
shrink-whitespace to remove whitespace (I bind this to
C-c - to run
org-table-insert-hline to add a nice horizontal line to my table
This restructures the data in the way I need, and I can now use
org-table-export to export to other useful formats.
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
(setq ivy-use-virtual-buffers t)
in you emacs config file.
Ivy author abo-abo gives an example on his blog post – take a look if this sounds useful.
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:
alias jsmiths "John Q. Smith <firstname.lastname@example.org>" "Jane Q. Smith <email@example.com>"
You can either save this file as
~/.mailrc or put it anywhere and tell Emacs where to find it using e.g.
;;mail aliases for lists (address lists)
(setq mail-personal-alias-file (expand-file-name "/homeb/bjm/docs/mail-aliases"))
Now, when composing an email you can type the alias (“jsmiths” in our example) and hit space, and it will expand to the list of email addresses.
If you are using my improved address completion, then you can add those aliases to your
bjm/contact-file to have them appear in your completion lists.
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
(defvar bjm/auto-save-timer nil
"Timer to run `bjm/auto-save-silent'")
;; Auto-save every 5 seconds of idle time
(defvar bjm/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
(defun bjm/auto-save-silent ()
"Auto-save all buffers silently"
;; Start new 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.
If you want Emacs to automatically update a buffer if a file changes on disk, then add the following to your emacs config file
;; auto revert mode
Of course, if your buffer has unsaved changes when the file changes on disk, then Emacs will prompt you and your changes won’t be lost.
This mode only applies to buffers associated with files on the disk, but I like to have my
dired view updated if the contents of a directory change. This is accomplished with the following code:
;; auto refresh dired when file changes
(add-hook 'dired-mode-hook 'auto-revert-mode)
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.
Install the package with
and then hit
S in a dired buffer to bring up the sorting menu. Your sorting choice is then remembered for new dired buffers.
I was recently managing a set of interviews and I had my notes on all of the candidates in a single org file, with each candidate under their own top-level headline:
* J Kepler
- Nice work on orbits
* I Newton
- Hard to work with
* C Sagan
- Good communication skills
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.
;; export headlines to separate files
(defun org-export-headlines-to-pdf ()
"Export all subtrees that are *not* tagged with :noexport: to
Subtrees that do not have the :EXPORT_FILE_NAME: property set
are exported to a filename derived from the headline text."
(let ((modifiedp (buffer-modified-p)))
(goto-char (re-search-forward "^*"))
(let ((export-file (org-entry-get (point) "EXPORT_FILE_NAME")))
(replace-regexp-in-string " " "_" (nth 4 (org-heading-components)))))
(org-latex-export-to-pdf nil t)
(unless export-file (org-delete-property "EXPORT_FILE_NAME"))
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.
:bind (("M-." . mc/mark-next-like-this)
("M-," . mc/unmark-next-like-this)
("C-S-<mouse-1>" . mc/add-cursor-on-click)))
I wrote recently about setting up a custom key map, and there are a couple of shortcuts for mu4e functions that I use very often with that key map.
With the following code I define
c in my key map to compose a new email. Since I previously set
C-1 to be the prefix for my map, then
C-1 c is the full keybinding. This works globally so I can start a new email from anywhere in Emacs with
I then supercharge the keybinding by using it to add a CC to an email if I am already composing one. This is done by binding
C-1 c in the
message-goto-cc. So now
C-1 c starts a new email unless I am already writing an email in which case it adds a CC instead.
While I am at it, I also add
s to my keymap for
mu4e-headers-search so I can use
C-1 s to launch a search of my emails from anywhere in Emacs.
;; bjm-map is already bound to the prefix C-1
;; use C-1 c to compose a new email
(define-key bjm-map (kbd "c") 'mu4e-compose-new)
;; use C-1 c for add cc if already in composition mode
(define-key mu4e-compose-mode-map (kbd "C-1 c") 'message-goto-cc)
;; add search
(define-key bjm-map (kbd "s") 'mu4e-headers-search)
To add or remove a tag from multiple headlines in an org-mode file, select a region containing multiple headlines and then run
M-x org-change-tag-in-region. You’ll be prompted for a tag and asked if you want to add or remove it from the selected headlines.