I want to install nginx-mode
into emacs so that I can have highlighting and formatting of my nginx
configuration files. What is the easiest way to do this?
This requires emacs24
or newer.
emacs
now has a pretty good package management system. The default package repository ELPA
has a pretty restricted set of modes and packages, so instead we'll use MELPA
which is actively maintained and growing.
MELPA
:emacs /sudo::/etc/emacs/site-start.el
Paste in this code: (from https://melpa.org/#/getting-started)
(require 'package) ;; You might already have this line
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line
Save and exit.
nginx-mode
To get nginx pretty-printing and indentation, do this to install nginx-mode:
emacs
M-x package-list-packages RET (Type meta-key and S, then type package-list-packages and hit return)
C-s nginx RET (Type control-S to search, type nginx and hit return to find the nginx-mode package)
i (to mark it to install)
x (to execute installation of marked packages)
nginx-mode
Now you can switch into nginx-mode with M-x nginx-mode
. E.g.:
emacs /sudo::/etc/nginx/sites-available/default
M-x nginx-mode RET
You can make it recognize the sites-enabled files automatically by looking at these instructions.
If you can't use melpa:
You can download the file nginx-mode.el
from https://github.com/ajc/nginx-mode and copy it in ~/.emacs.d/
Then in you .emacs you can add
(add-to-list 'load-path "~/.emacs.d/")
(autoload 'nginx-mode "nginx-mode" nil t)
(add-to-list 'auto-mode-alist '("nginx.conf\\'" . nginx-mode)) ;; or M-x nginx-mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With