*scratch* buffer is useful for dumping temporary bits of text, or trying out bits of lisp code. By default the contents are not saved, but it can be handy to have the scratch buffer saved and restored when you start a new Emacs session. This is easy with the persistent-scratch package, just add the following to your emacs config file:
This post was originally titled “Prevent Emacs wiping the system clipboard”, which was a rubbish description of what this tip actually covers, so I renamed it! Apologies if you see it twice in your RSS reader.
I wrote previously about adding mouse selections in Emacs to the system clipboard, and here is another tip to integrate the system clipboard more nicely with Emacs. This comes from the fantastic Emacs operating system set of configuration files, which are full of gems like this (thanks to Irreal for pointing me to EOS).
By default, if you copy something to the system clipboard (e.g. some text in firefox) and then copy or kill some text in Emacs, then the text from firefox is lost. If you set the option below in your emacs config file then copying or killing text in Emacs will add the system clipboard text to the kill-ring so that you can find it when you cycle through your clipboard history in Emacs.
;; Save whatever’s in the current (system) clipboard before
;; replacing it with the Emacs’ text.
(setq save-interprogram-paste-before-kill t)
I’ve written before about managing files in Emacs using dired. The package dired-ranger provides a useful extension to dired, allowing you to copy and paste files much like you can do in traditional GUI file explorers.
dired-ranger with something like the following
:bind (:map dired-mode-map
("W" . dired-ranger-copy)
("X" . dired-ranger-move)
("Y" . dired-ranger-paste)))
This also sets up some useful keybindings. Now in a dired buffer, you can mark multiple files and then hit
W to copy them (really they are added to a copy ring). You could then optionally go to another directory and mark more files and hit
C-u W to add those to the same entry in the copy ring as the previous files. This builds up a virtual collection of files that you can then copy or move. Now go to the target directory and hit
X to move the copied files to that directory (i.e. they are deleted from their original location) or
Y to copy the files to the target directory (the originals remain where they were).
You can achieve similar results using
dired-dwim-target or Sunrise Commander, but this method clicks with me and is the one that I use.
I’ve been playing around with some different fonts to see how they look in Emacs. For a long time I’ve been using DejaVu Sans Mono, but I felt like a change. It’s easy to switch the font for the current frame, just use
M-x set-frame-font and enter the name of an installed font, or put a line like this
(set-frame-font "DejaVu Sans Mono-14" nil t)
in your scratch buffer and put the cursor at the end of the line, and use
C-x C-e to run
eval-last-sexp which evaluates that bit of code. This will instantly change the appearance of the current frame.
Here are some of the fonts I’ve been trying out (I installed them using the Font Book on my Mac):
(set-frame-font "DejaVu Sans Mono-14" nil t)
(set-frame-font "Fantasque Sans Mono-16" nil t)
(set-frame-font "Source Code Pro-14" nil t)
(set-frame-font "Monaco-14" nil t)
(set-frame-font "Cousine-14" nil t)
I’ve decided to go with Google’s Cousine font at the moment, so I add the following to my emacs config file to make the choice permanent:
(setq default-frame-alist '((font . "Cousine-14")))
A while ago I wrote
mu4e-delay, a package (based heavily on gnus-delay), to add a customisable delay to outgoing mail so that a sent email could be “undone” before the delay period had passed. This was spectacularly useful for me, but now Benny Andresen has put together the superior mu4e-send-delay, which improves on my package in several ways.
The key features of
mu4e-send-delay are (from the github page):
- mu4e context support
- Saves scheduled mails to mu4e-drafts-folder
- Uses an emacs timer to check Drafts if a mail is scheduled to be sent now
- Allows easy edit of the X-Delay header in mu4e-compose-mode
- Displays scheduled time in mu4e-view
- Doesn’t send if mail is currently being edited
- Works with attachments
The last four points are all improvements over the original
mu4e-delay, with the last two being the most important. I’d encourage any
mu4e-delay users to switch over to
mu4e-send-delay. I have, and I’ve not looked back!
I recently needed to transpose a table in org-mode and spent a few minutes trying to come up with a keyboard macro to do it before it occurred to me that there might be a command to do this already. And of course there was:
M-x org-table-transpose-table-at-point. Here it is in action:
It’s great when there’s a command that does exactly what you want!
I’ve mentioned crux before; it’s a package providing a set of general-purpose useful commands. One that I use all the time is
crux-open-with, which opens the file currently being visited (or the file at the point in a dired buffer) using the system default application for that filetype. It works on Mac or Linux, by using the
xdg-open commands respectively.
I bind the command to
C-c o, using the following code (which also binds the previously mentioned
:bind (("C-c o" . crux-open-with)
("C-a" . crux-move-beginning-of-line)))
Following on from my post on using
C-x k to kill the current buffer, why not bind
C-x w to
delete-frame in order close the current emacs “window” (remember, in Emacs-speak, a frame is what most other apps would call a window). This is way better than the default
C-x 5 0
Just add the following to your emacs config file
(global-set-key (kbd "C-x w") 'delete-frame)
Here’s a tiny tip. By default
C-x k runs the command
kill-buffer which prompts you for which buffer you want to kill, defaulting to the current active buffer. I don’t know about you, but I rarely want to kill a different buffer than the one I am looking at, so I rebind
C-x k to
kill-this-buffer which just kills the current buffer without prompting (unless there are unsaved changes).
Just add this to your emacs config file
(global-set-key (kbd "C-x k") 'kill-this-buffer)
The built-in view-mode turns the current buffer into a read-only pager, with
DEL to scroll up and down by page. This is a nice way to comfortably read files. Simply toggle on or off with
M-x view-mode (or use
e to exit
view-mode). You can also tell Emacs to always open read-only files in