- Running through #DOOMEternal with all cheats on!SUBSCRIBE to DanQ8000 ⊳ A DANQ8000.
- Options: -n: add line numbers to the source code. +n: add line numbers but continue from last SRC snippet.-r: remove labels from source code; Commands: C-c ': Allows you to edit the source code at point in its native mode.
Github-review: GitHub code reviews with Emacs. This package contains a handful of Emacs commands to review GitHub pull request without leaving Emacs. To get an overview of the package you can watch this 4-minute video: You can start by calling github-review-start and entering a Pull Request URL. You will, then be prompted with a buffer.
A gateway drug to the wonderful world of Emacs and Spacemacs for Clojure users.
None of the following config is meant to be permanent, although it could be used as the basis of a personal emacs configuration. It’s meant as a basic setup so non-emacs users can try out emacs as simply and quickly as possible.
First some terminology
Installing Clojure Specific Plugins
Clojure mode comes by default, but there are some other things that help. Most importantly, Cider. This is available from the melpa archive and the first step is to add that. There are several ways, but as emacs lisp is very closely related to Clojure and we can run lisp commands directly from emacs, the easiest way is to use that method. To do this call up the lisp interpreter by either of these:
M-x eval-expression
M-S-;
Then enter the command you want to run. Ie:
Fetching the list of packages can take a while depending on network connection. Best to check it, if the last command fails, with:
You can now start a repl by navigating to a Clojure project root directory and running the following command:
A Minimal Set of Commands. Just enough to get going…
Window Controls
Emacs by default will split windows so you can see multiple buffers at once. This behaviour can be changed, but to start with learning these basics:
Opening Files
Note that sometimes this is bound to C-x d
. The one you need is the one that DOESN’T say (brief) in the minibuffer. Try them both. The (brief) version is not useful.
<return> open file at point
Navigation
(arrow keys also work as expected. Ctrl-arrow gives bigger movements)
Cut and Paste
The emacs model for cut and paste predates the generally used C-c C-v
convention. It is possible to modify this, but better to understand the emacs default behaviour first. A region is the text between the cursor and the “mark”. This can be cut and stored in the cut buffer and “yanked” back again.
Help
Emacs can provide all sorts of help, even straight out of the box. Here are some shortcuts:
Other Essentials
That should be enough to actually get around and edit files and run Clojure functions either in the repl or directly from the files. Before continuing it’s worth adding a few helpful packages. These often have ready made keybindings, but not always. Most people will keep the bindings we have seen so far, but this is not possible for every combination of all possible packages. Commands can always be run using M-x
and the command name though. Emacs will tell you if the command is already bound to a key and you can use that binding or re-bind it as you see fit.
Cider
Cider had a wealth of commands, none of which are bound to keys by default. At the very least it would be good to bind cider-jack-in
to something. I would recommend C-c C-j
but for now, just run them from M-x
.
Non-essential, but useful, additions
Paredit Mode
Makes life easier by strictly matching paren pairs. Not the only option, there are other similar packages worth investigating too. Install it with package-install
and enable it for all Clojure files with these lisp commands:
(package-install ‘paredit)
(add-hook 'clojure-mode-hook 'enable-paredit-mode)
Useful paredit commands:
Which-key
Makes finding half-remembered commands a whole lot easier
Now if you start to type a keybinding, all the options will appear in the mini-buffer. Try it by typing C-x
. There are many useful commands starting with C-x
.
Ivy
Improves searching for M-x
commands.
(package-install ‘ivy)
(setq ivy-use-selectable-prompt t)
(ivy-mode 1)
Swiper
Makes searching in a file much easier
(package-install ‘swiper)
(global-set-key 'C-s' 'swiper)
Smex and Counsel
Smex in counsel-mode gives a nice command history for M-x
commands. Also, counsel provides many more overlays to built-in functions that are well worth exploring.
(package-install ‘smex)
(smex-install)
(package-install ‘counsel)
(counsel-mode 1)
Problems
Lein not found?
You may need to add an entry to exec-path, which is what emacs uses to find executables for external commands. Some versions of emacs set this from $PATH
, others don’t so if you have lein installed in your home directory you may need to add that to emacs’ exec-path.
(add-to-list 'exec-path '/Users/<me>/bin')
Stop the bell ringing
(setq ring-bell-function 'ignore)
Broken config file
Sometimes problems occur when editing emacs init files that stop it from booting properly. Moving/renaming it and starting with bare emacs again to fix the problem is one way to do it. I prefer this:
vi ~/emacs.d/init.el
What next?
All the preceding info is arranged to help try out emacs. Although emacs will remember certain things like the packages installed, it won’t automatically remember all the settings applied. Any lisp code that has been run using M-S-;
can also be added to a startup file so it gets applied every time. The best starting place is ~/.emacs.d/init.el
. This is the whole of the above setup in one place. This can be pasted into your init.el file:
(require 'package)
(package-initialize)
(add-to-list 'package-archives '('melpa' . 'http://melpa.org/packages/') t)
(package-install 'cider)
(package-install 'paredit)
(paredit-mode)
(add-hook 'clojure-mode-hook 'enable-paredit-mode)
(package-install 'which-key)
(which-key-mode 1)
(package-install 'ivy)
(setq ivy-use-selectable-prompt t)
(ivy-mode 1)
(package-install 'swiper)
(global-set-key 'C-s' 'swiper)
(package-install 'smex)
(smex-initialize)
(package-install 'counsel)
(counsel-mode 1)
You may prefer to only keep certain parts. There are also many good emacs starter packs, although there is a lot to be said for starting from scratch and only adding things you will actually use. Browse the available packages with this command:
C-x package-list-packages
Some other useful ones worth trying are:
- magit
- git-gutter
- paradox
- rainbow-parens
- aggressive-indent-mode
- evil
- flycheck
- google-translate
- tetris
- …
Spacemacs
Spacemacs is a self contained emacs setup. It has a curated set of packages and bindings and some might prefer this to setting up and tweaking their own system. It is also tailored to be easy for vi users to use, although this can also be done in regular emacs by installing evil-mode
. Underneath it’s still just emacs so the basics are the same either way. Emacs must be installed and run as normal. Spacemacs is not a separate application.
A lot of the niceties detailed above are already included in spacemacs but installing cider is slightly different.
To setup spacemacs from scratch first remove all traces of emacs config files then install the spacemacs config to ~/.emacs.d
:
cd ~
mv .emacs.d .emacs.d.bak
mv .emacs .emacs.bak
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
Try running emacs and let it install all the necessary packages. This may take a while and may also require exiting emacs and restarting. When it comes up clean, then cider can be added. Do this by editing ~/.spacemacs
and adding clojure
to the existing dotspacemacs-configuration-layers
list and restarting. At this point most of the above information will apply.
You can download a short printable version of the cheatsheets here:
Doom Emacs Cheat Sheets
Doom-emacs. It's a configuration framework for Emacs. Basically, it overrides the Emacs keybindings with most of vim's.
As I mentioned in the last post. I started using Emacs at work due to org-mode… and work PC's use windows behind a Firewall, so using git, pip, melpa and some more are useless in my work desktop (In the Laptop all of them work if I connect to another network, which was what I did).
As you can imagine, Doom is for a GNU program so Windows support is limited (because, who cares?). The guide is poor, it describes how to install it with scoop/chocolatey (that don't work with a firewall). However, you can use the git-bash to install Doom without scoop/chocolatey.Here is how you do it:
What you need
If you have limited permissions in Windows PC (e.g. admin privileges), you might not be able to use Chocolatey/Scoop.However, you can still use git-bash.exe
portable version!
Download git.
Download Ripgrep and fd. Make sure you download the
windows-gnu
version.Of course, download emacs.
Extract the binaries1 from Ripgrep
and fd
to their respective folders and place them where you want.
You should have one folder for
Ripgrep
and another forfd
.
Extract emacs and place it where you want.It does not matter where they are, we will add them to the Path
later (but keep themsafe and where you can remember).
Instructions
Edit system environment variables
Go to
Control panel -> User Accounts -> Change my environment variables
.New
, typeHOME
and set yourC:UsersUSERNAME
andOK
.Select
Path
,edit
and add yourC:pathtotheemacsbin
folder andOK
.Select
Path
,edit
and add yourC:pathtotheripgrep
folder andOK
.Select
Path
,edit
and add yourC:pathtothefd
folder andOK
.Click
Ok
.
We still need to add
C:UsersUSERNAME.emacs.dbin
; but first download Doomfiles.
Install Doom
Open
git-bash.exe
Type
cd ~
Run:
git clone https://github.com/hlissner/doom-emacs ~/.emacs.d
After the download is completed, type
cd ~/.emacs.d/bin
and run:./doom install
If everything is fine, Doom is now installed.
Just in case run
./doom sync
Go to
Control panel -> User Accounts -> Change my environment variables
.Select
Path
,edit
and addC:UsersUSERNAME.emacs.dbin
, clickOK -> OK
.
Now you can start emacs and will see the Doom dashboard!
All the icons
By default all-the-icons will not be enabled in Windows.
If all-the-icons is not installed. Open emacs and
M-x package-install RET all-the-icons RET
.M-x all-the-icons-install-fonts
select where to download the fonts andinstall them (double click -> install).Restart emacs and there you go.
From one PC to another
If one of your PCs does not have internet connection or is under a firewall, you can:
Copy your
~/.doom.d ~/.emacs.d ripgrep fd emacs
folders directly to theother PC (~/.domm.d ~/.emacs.d
go inC:UsersUSERNAME
)Edit the system environment variables accordingly.
Copy and install the fonts you downloaded with
all-the-icons
Open
git-bash.exe
,cd ~/.emacs.d/bin
and run:./doom sync
et voilà!.
Emacs server
If you use emacs server, Doom will place the server file inC:UsersUSERNAME.emacs.d.localcacheserver
folder.
Go to
Control panel -> User Accounts -> Change my environment variables
.New
typeEMACS_SERVER_FILE
and set the file pathC:UsersUSERNAME.emacs.d.localcacheserverserver
.Create a
emacsclientw.exe
shortcut withemacsclientw.exe -nc
in target,run emacs server and emacsclientw will work.
Doom Emacs Org Mode Cheat Sheet
Now, rejoice!