Emacs cookbook
Packages
Load local packages
To load an Emacs package locally, you’ll need to do a few things. Here’s a step-by-step guide:
Install the package manually: First, you’ll need to have the package files somewhere on your system. You may download it from a source or create it yourself. Let’s say you have a package named
mypackage
in a directory at~/emacs/mypackage
.Add the package directory to your load path: Emacs uses a variable called
load-path
to determine where to look for packages to load. You can add your package’s directory to this path by adding the following line to your Emacs configuration file (.emacs
orinit.el
):
(add-to-list 'load-path "~/emacs/mypackage")
Note that Emacs does not expand the ~
character in paths, so you’ll need to use the full path to your package directory or use the expand-file-name
function to expand the path.
- Require the package: Once the directory is in your load path, you can require the package in your Emacs configuration file:
(require 'mypackage)
This tells Emacs to load the mypackage
package when it starts up.
Note: The package’s main file should be named mypackage.el
, and there should be a (provide 'mypackage)
expression at the end of this file for the require
function to work.
This approach is for simple, single-file packages. More complex packages that have a structure and come with an -autoloads.el
file will require a different approach. You might need to use the built-in package manager (package.el
) or a third-party package manager like straight.el
or use-package
to handle autoloading and dependencies properly.
Ordering JSON by key value
Run json-pretty-print-buffer-ordered
[^spacemacslayer]
[^spacemacslayer] If using spacemacs
, it requires the Javascript
layer
Projects
Creating a projectile project
To create a projectile
project either use a valid Git repository or create the special .projectile
file in root.
Fuzzy search
Do a SPC p f, but make sure the projectile project is created.
Split screen
The standard Emacs keys are valid here (even for Spacemacs).
- SPC w h
Indent a block of text
Select the block with V
and then press Ctrl-x TAB. Then use h
or l
to move it along