Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install nginx-mode into emacs?

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?

like image 602
Simon Woodside Avatar asked Nov 29 '16 02:11

Simon Woodside


2 Answers

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.

First, install 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.

Second, install 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)

Use 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.

like image 80
Simon Woodside Avatar answered Oct 17 '22 19:10

Simon Woodside


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
like image 20
djangoliv Avatar answered Oct 17 '22 20:10

djangoliv