aez-notes
Table of Contents
Emacs
Keyboard macros
- Start recording with
C-x (
. - Stop recording with
C-x )
. - Execute the recording with
C-x e
.
If you want to save a macro for later use, you can get a emacs-lisp definition
of it with insert-kbd-macro
.
Jargon
There is a glossary in the manuals, the nodes are Emacs > Glossary
. The regex
search entered with s
is very useful here.
The daemon and the client
To start an Emacs daemon run emacs --daemon
. To open a new frame run
emacsclient -c
, or to open a specific file emacsclient -c <path/to/file>
.
Documentation
Running the info
function will load the manuals. Although, C-h i
brings you
there much quicker. To start with you are in vim keybindings so can move around
with hjkl
, but apart from that you'll want to jump to emacs keybindings so you
can use dubnpmlrsf[]<SPC>
for greater flexibility navigation.
Info navigation
n
next nodep
previous node[
and]
are for up and down levels of nodesb
to go to the start of a nodeSPC
to go to the end o a nodel
last node before this ones
search with a regexf
find a node linked from herem
is a menu of linked nodesu
up a level of nodesd
go to the root node
Documentation on debugging
In the Emacs Lisp Intro there is a section, Debugging, which walks through the use of the built-in debugging facilities.
Emacs Lisp
See my Emacs Lisp notes.
Spacemacs
Configuration
My configuration for spacemacs is available as an org-mode file here. I have also written a small quick start guide for spacemacs as part of the ESS introductions project.
Startup
To put your own image on the splash screen you need to modify
dotspacemacs/init
, specifically you need to set the variable
dotspacemacs-startup=banner
to be a string of the full path to the desired
PNG. A sensible place to put the image is ~/.emacs.d/core/banners/img
. You can
reduce the size of PNG to get a better fit with the following command.
convert -resize 50% foo.png bar.png
Here is the image I (previously) used. Now I use banner 100.
Welcome to ███████╗███╗ ███╗ █████╗ ██████╗███████╗ ██╔════╝████╗ ████║██╔══██╗██╔════╝██╔════╝ █████╗ ██╔████╔██║███████║██║ ███████╗ ██╔══╝ ██║╚██╔╝██║██╔══██║██║ ╚════██║ ███████╗██║ ╚═╝ ██║██║ ██║╚██████╗███████║ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚══════╝
Default colour schemes
The hexcodes for the default colour schemes used by Spacemacs can be found in
spacemacs/core/libs/spacemacs-theme/spacemacs-common.el
Miscellaneous
Completion with company producing unacceptable lag
Try adjusting company-idle-delay
and company-minimum-prefix-length
to
prevent the backend being queried too often.
Change Logs
Emacs has built-in support for change logs which should be saved to a file
called ChangeLog
. From within the file you are editing, use C-x 4 a
to open
a new window with the change log file with the name, date and filename (and
potentially function name) added.
Dired
Task | Command |
---|---|
Rename a file | R |
Copy file | C |
Make directory | + |
Mark | m |
Unmark | u |
Flag for deletion | d |
Execute deletions | x |
Move up a directory | ^ or - |
Moving multiple files
Suppose you want to move some of the files from directory X
to directory Y
.
- Go to
X
in dired, - Mark the files you want to copy with
m
, - Copy them with
C
(yes that is a capital 'c'), - Select
Y
from the pop-up menu.
Searching for things with Dired
The following advice from the emacs manual may be useful if you are trying to locate some files.
To search for files with names matching a wildcard pattern use
M-x find-name-dired
. It reads arguments DIRECTORY and PATTERN, and chooses all the files in DIRECTORY or its subdirectories whose individual names match PATTERN.
There is also the grep
command for searching within files and the find
command for searching based on the filename.
Buffer menu
Ibuffer
Use ibuffer
or SPC o f b
to summon the Ibuffer menu.
The buffer menu is a built-in mode which provides features like Dired, but for
working on buffers. By clicking on the column labels you can sort the buffers in
helpful ways, you can use d
to mark buffers for deletion and execute such
instructions with x
. Similarly files can be marked for saving with s
and
unmarked with u
.
The s
command opens a menu for sorting.
Buffer menu
Use list-buffers
or C-x C-b
to summon the buffer menu.
The buffer menu is a built-in mode which provides features like Dired, but for
working on buffers. By clicking on the column labels you can sort the buffers in
helpful ways, you can use d
to mark buffers for deletion and execute such
instructions with x
. Similarly files can be marked for saving with s
and
unmarked with u
.
The buffer name and the visited file are clearly labelled, the letters CRM stand for current, read-only and modified.
Elfeed
RSS reader for emacs.
To start the elfeed application use SPC a f
.
Mnemonic: [a]pplication [f]eed.
Set up a list of feeds by setting the elfeed-feeds
variable.
Shortcuts
Keys | Description |
---|---|
SPC a f |
Enter elfeed |
r |
Mark as read |
u |
Mark as unread |
g r |
Refresh feed |
s |
Search feed |
+ |
Add a tag |
Configuration
You can put the configuration of elfeed in a seperate file and then load it from your init
.
In Spacemacs, this means adding the following to your dotspacemacs/user-config
:
(load-file "<path/to/config.el>")
where the configuration file sets the elfeed-feeds
quantity to be a list of URLs.
NOTE! If you want to add tag specific faces for the entries, you need to include (require 'elfeed-search)
at the top of the configuration file.
Automatic tagging of entries
The elfeed-new-entry-hook
provides a way to automatically tag new entries, for example, by checking if the title and content contain particular words.
The following snippet is taken from the author's blog demonstrating how to do this.
(defun score-elfeed-entry (entry) (let ((title (elfeed-entry-title entry)) (content (elfeed-deref (elfeed-entry-content entry))) (score 0)) (loop for (pattern n) in '(("alloy" 1) ("machine learning\\|neural" 1) ("database" 1) ("reproducible" 1) ("carbon dioxide\\|CO2" 1) ("oxygen evolution\\|OER\\|electrolysis" 1) ("perovskite\\|polymorph\\|epitax" 1) ("kitchin" 2)) if (string-match pattern title) do (incf score n) if (string-match pattern content) do (incf score n)) (message "%s - %s" title score) (cond ((= score 1) (elfeed-tag entry 'relevant)) ((> score 1) (elfeed-tag entry 'important))) entry)) (add-hook 'elfeed-new-entry-hook 'score-elfeed-entry)
Magit
I have some notes on git, but this section is about the emacs package magit
which is like a git client. To get to the magit status buffer use SPC g s
.
Keys | Command | Description |
---|---|---|
SPC g s |
magit-status |
Open the status buffer |
F p |
magit-pull-from-pushremote |
Pull commits from remote |
s and u |
Stage and unstage files | |
c c |
Create commit | |
, k |
Kill (cancel) a commit | |
C-c C-c |
Confirm commit | |
p p |
Push commits to remote | |
l l |
Show commits graphically | |
b b |
Checkout a branch |
The following definition tells magit to open the status buffer in a full frame.
(setq magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
Spell checking
Configuration
Add spell-checking
to the layers list.
By default it will look for aspell
on the path (which is the GNU replacement for ispell
.)
The program that will be used is described by ispell-program-name
.
The dictionary that will be used is defined by ispell-dictionary
.
I have the following settings for spell checking
(spell-checking :variables spell-checking-enable-by-default nil enable-flyspell-auto-completion t)
Usage
I need to explicitly use SPC t S
to toggle on spell checking.
To spell check the buffer I use SPC S b
.
Leaving the point over a misspelled word will bring up a list of potential corrections.
To add a new word to a private dictionary use M-$
to bring up the list of potential solutions and then press [i]nsert to add the word to a private dictionary.
Spray
Speed reader for emacs.
Enable this by adding speed-reading
to your configuration.
Keys | Description |
---|---|
SPC a R |
Start spray |
SPC |
Pause |
f |
faster |
s |
slower |
h |
back (vim left) |
l |
forward (vim right) |
q |
quit |
Yasnippet
There is a single snippet per file, there is a convenience function for creating
new snippets: yas-new-snippet
. The name
is a human readable description and
the key
is the keyword you'll use to invoke the snippet. When writing a
snippet, tab-stop fields (e.g., $1
, $2
, etcetera,) are used to specify
additional data.
For spacemacs, the snippets are saved in
/home/aez/.emacs.d/private/snippets/<major-mode>
. Finally, use
yas-reload-all
to reload all of the snippets in that directory. Finally, to
invoke the snippet there is functionality provided by helm with the
spacemacs/helm-yas
which is bound to SPC i s
which will bring up a search
option.
Word count
To count the words in a selected region use M =
Multiple cursors
Use the g r
functions to set up some cursors then use the SPC s e
to enter
the editing mode for them. This seems to have been a source of confusion for
many users….