How can I install nginx-mode into emacs? - 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?

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.

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

Related

Flycheck installation: M-x package-install [No match]

I'm relatively new to Emacs (and Linux for that matter). I'm trying to install flycheck. Following the installation instructions, I added
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(package-initialize)
to my .emacs file (then killed Emacs and restarted).
Then M-x package-install RET flycheck RET. But Emacs says [No match]. Any ideas what I'm doing wrong?
Platform: Emacs 24.3.1, Ubuntu 14.04 LTS 64bit running on VMware (Windows 10 host).
I'm also quite new to emacs, and I've had the same problem. What worked for me:
M-x package-list-packages RET
Find flycheck, mark it with an I
Use X to install marked package.
For reference, this is how I call package in my .emacs:
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "http://stable.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)`

package-install can't find icicles

I'm trying to install icicles in Emacs because I've read it makes for a more clear emacs experience. The problem is, even though I'm loading the Melpa repositories, and Checked melpa for if the package was available (it was) If I try package-install on it, it returns [no match].
I've tried package-refresh-contents to na avail. Please help with this, I could do it manually, but AUGH!
Just for context, here's the contents on my .emacs:
;; packages
(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("org" . "http://orgmode.org/elpa/")
("marmalade" . "https://marmalade-repo.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(add-to-list 'load-path "~/.emacs.d/elisp")
(defun require-package (package)
(setq-default highlight-tabs t)
"Install given PACKAGE."
(unless (package-installed-p package)
(unless (assoc package package-archive-contents)
(package-refresh-contents))
(package-install package)))
(package-initialize)
(load-theme 'zenburn t)
(require 'php-mode)
(eval-after-load 'php-mode
'(require 'php-ext))
(add-to-list 'auto-mode-alist '("\\.json$" . js-mode))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes (quote ("f5eb916f6bd4e743206913e6f28051249de8ccfd070eae47b5bde31ee813d55f" default))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;;
Thanks in advance, all help is very much appreciated
Icicles is no longer distributed on ELPA or MELPA:
NOTE:
Icicles, as well as my other libraries that are on EmacsWiki, used to be obtainable also from MELPA. You may still find some of them there, but they are likely not up-to-date.
As of 2017-10, MELPA has decided to no longer accept Lisp libraries from EmacsWiki. This includes my libraries, even though these libraries are read-only (administrator lock on the wiki pages). Too bad. This means that you must download Icicles and my other libraries only from Emacs Wiki. Sorry about that. I upload Icicles files only to the wiki.
https://www.emacswiki.org/emacs/Icicles_-_Libraries
Solved the problem by doing M-x eval-buffer on my .emacs.

emacs: Why can't I install auto-complete via package-install?

I am new to emacs and have never used package-install before. I am using emacs 24.4 on Windows, but I would like to do the same thing on my emacs installed ona unix server that I ssh into.
These instructions say that I can install auto-complete with M-x package-install [RET] auto-complete [RET], but when I do this I get [No match]. Why is this? How can I install it?
Have a look at what the instructions say with a little more context:
Install
auto-complete is available on MELPA and MELPA-STABLE
You can install auto-complete with the following command.
M-x package-install [RET] auto-complete [RET]
Before running the package-install you need to enable MELPA or MELPA stable:
Enable installation of packages from MELPA by adding an entry to package-archives after (require 'package) and before the call to package-initialize in your init.el or .emacs file:
(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
or to add the stable package repository, use this instead of "melpa":
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/") t)
You might also need to run M-x package-refresh-contents before M-x package-install will work. Alternatively, run M-x package-list-packages and use the UI provided there, which refreshes contents automatically.

Emacs: list-packages [no match]

I'm new to Emacs. I'd like to install a package, but doing M-x package-install says there is no such command.
Trying to look which packages are installed with M-x list-packages does not work either. GNU Emacs manual does not say much about it (or I looked in a wrong place), and I can't quite come up with meaningful keywords for search due to my limited Emacs knowledge.
Thanks phils and shyamupa for setting me on track. Indeed, I am using emacs 23 ("M-x version" to check).
I used instruction from here to install packaging system. I had to copy the following in scratch:
(let ((buffer (url-retrieve-synchronously
"http://tromey.com/elpa/package-install.el")))
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(eval-region (point) (point-max))
(kill-buffer (current-buffer))))
and then M-x eval-buffer
Then, M-x package-list-packages works.
UPDATE:
It turns out I was looking for a package in MELPA, and the above procedure sets you up for ELPA only. The content of my .emacs file after installation was following:
(when
(load
(expand-file-name "~/.emacs.d/elpa/package.el"))
(package-initialize))
To enable MELPA load I had to replace the contents of package.el with this and change .emacs as follows (inspired by this SO question):
(load (expand-file-name "~/.emacs.d/elpa/package.el"))
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(package-initialize)
This did the trick and I got a huge list of packages from MELPA. Hope this will save someone time in future.

auto-complete-mode not working

I just followed this site to install auto-complete on Emacs. I installed it with "M-x load-file RETURN ~/path/to/etc/install.el".
The output of my installation was: http://paste.ubuntu.com/6184523/
After that, I added the recommended code to my ~/.emacs file and restarted Emacs. Typing "M-x auto-complete-mode" says "No match". I also tried to fix it by replacing flet with c-flet etc. but it hasn't changed anything too.
Version: GNU Emacs 24.3.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.8.2)
Emacs has a package manager now. So just install the package from the list and you're done.
Here's the configuration that adds the two most popular repositories:
(package-initialize)
(add-to-list
'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list
'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/"))
After this, M-x package-list-packages. The rest is pretty intuitive.
UPD: A simple auto-complete setup for C++
(add-hook 'c++-mode-hook
(lambda()
(semantic-mode 1)
(define-key c++-mode-map (kbd "C-z") 'c++-auto-complete)))
(defun c++-auto-complete ()
(interactive)
(let ((ac-sources
`(ac-source-semantic
,#ac-sources)))
(auto-complete)))
I tried some solutions that worked for other people, but it didn't quite work out.
Try setting the environment variable(s) to ~/emacs.d/ in both .profile and .bashrc
If that doesn't work out, try exporting the environment variable(s) with su root (won't work with sudo).
At least that worked for me while trying to install auto-complete-mode with golangs auto-complete-mode