Emacs Init: Install Package Manually
What is a Package
- A emacs package is a elisp file or more than one elisp files.
- A elisp file ends in
.el
- A emacs package is usually identified by the file name, e.g.
xah-fly-keys.el
,markdown-mode.el
.
This page is a tutorial on how to install emacs packages manually. e.g. any elisp file you got online.
Load the File
Load the File Interactively
Suppose you downloaded a simple emacs package on the web named “xx.el”. To use the package, all you have to do is to make emacs load the file.
Alt+x load-file
then give the file path.
Now, emacs is aware of the package.
If the package is a
Major Mode
or
Minor Mode,
you have to activate it, by call the command in the package.
For example, if the file name is xx.el
, then the command to activate it is typically Alt+x xx or xx-mode.
Load File at Startup
If you want emacs to load the file when it starts, put the file in the dir
~/.emacs.d/lisp/
where
~/.emacs.d/
is wherever you emacs init dir.
(create that “lisp” directory if it doesn't exist.) then put the following in your emacs init file:
;; add lisp dir in emacs init dir, to load path (add-to-list 'load-path (concat user-emacs-directory "lisp/" )) ;; load a package. (file name is typically xx.el) (load "xx") ;; best not to include the ending .el or .elc. because emacs will then use elc if available.
Byte Compile
optional
Auto Activate Mode When Opening File
This is usually setup by the package, but not always. Here's the basics:
(add-to-list 'auto-mode-alist '("\\.el\\'" . xah-elisp-mode))
For detail, see: Emacs Init: Set Default Major Mode.
Mode Documentation
Emacs mode usually comes with inline doc.
To view it, first activate the mode (Alt+x mode_name).
Once in the mode, Alt+x describe-mode
.
Emacs will show its doc string.
Sometimes, a mode comes with complete documentation in info
format (file with suffix .info
). To read the info, type
Ctrl+u Alt+x info
then type the info file's name.