[LINUX] Emacs-based environment construction

I usually use Emacs a lot, and even when I build a new Linux environment in a virtual environment, I am the first to install Emacs. [Vagrant](https://ja.wikipedia.org/wiki/Vagrant_(%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3 The emacs installation command is written in% 82% A2)) every time.

I wish I was satisfied with just being able to use Emacs, but because I customized it to my liking and used it everyday, it became inconvenient in the initial state of Emacs.

Therefore, I will write the procedure to build a ** base environment ** when using Emacs normally.

Contents

** 1. Preparation **

** 2. Construction by .emacs description ** ** 2.1 Display related settings ** ** 2.2 color setting ** ** 2.3 Package related settings ** ** 2.4 Code completion related settings **

** 3. Build with M-x command ** ** 3.1 Color settings ** ** 3.2 Code completion related introduction **

** 4. Whole .emacs description **

1. Advance preparation

First install what you need to build code completion related.

sudo apt-get install -y cmake clang

2. Construction by .emacs description

In Emacs settings, describe various things in a file called .emacs. By the way, if you look up other articles, there are descriptions in .emacs.el and ʻinit.el, So far, I have set everything in .emacs, so I will write on the premise of .emacs`. By the way, the location of the file is

$HOME/.emacs

is.

2.1 Display related settings

(global-linum-mode t)
(menu-bar-mode -1)
(tool-bar-mode -1)
(setq inhibit-startup-message t)
(setq make-backup-files nil)

The first line is a description for displaying the line number. Required. After that, the description that hides various bars and hides the message at startup. Honestly, it is usually started with the -nw option, so it is not very effective.

2.2 Color settings

This item is also described in .emacs, but manual input is not recommended. There is a high possibility that the settings will not be reflected, so this will be explained later in ** 2. Building with the M-x command **. By the way, the following warning message is displayed in the comment out.

 ;; 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.
 ;; If there is more than one, they won't work right.

Simply put, it doesn't work well when you change it manually, so be careful.

2.3 Package related settings

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)

(package-initialize)

Settings required when installing the functions described below. Let's make a package called Melpa available. Also, (package-initialize) needs to be executed after writing various package settings. If you want to add packages other than Melpa, be sure to write before this setting.

2.4 Code completion related settings

company


(when (locate-library "company")
  (global-company-mode 1)
  (global-set-key (kbd "C-M-i") 'company-complete)
  
  (setq company-idle-delay 0)
  (setq company-selection-wrap-around t)
  
  (define-key company-active-map (kbd "C-s") 'company-select-next)
  (define-key company-active-map (kbd "C-w") 'company-select-previous)
  (define-key company-search-map (kbd "C-s") 'company-select-next)
  (define-key company-search-map (kbd "C-w") 'company-select-previous)
  (define-key company-active-map (kbd "<tab>") 'company-complete-selection))

irony


(eval-after-load "irony"
  '(progn
    (add-to-list 'company-backends 'company-irony)
    (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
    (add-hook 'c-mode-common-hook 'irony-mode)
    (add-hook 'c++-mode-hook 'irony-mode)))

yasnippet


(eval-after-load "yasnippet"
 '(progn
    (define-key yas-keymap (kbd "<tab>") nil)
    (yas-global-mode 1)))

Build code completion using company + ʻirony + yasnippet. It's okay to change the various operation methods of the company as you like. I bind with w, s so that I can select while pressing Ctrl with my left hand. Also, (setq ~)` is the delay time until the completion candidate appears in the first. The default is 0.5 seconds and you have to wait for a while, so it is set to 0 seconds. The second is a setting that allows candidates to go to the bottom and then return to the top. Of course, this description alone will not be executed, so later in ** 2. Build with M-x command ** I will explain the installation procedure. Other articles explain more about company, irony, and yasnippet, so please check them out. By the way, if you don't install the package first, you will get an error when you start emacs. So it is recommended to write this description after installation.

3. Build with M-x command

I will explain various settings using the M-x command. By the way, M-x is ʻAlt + x`. M is derived from the Meta key.

3.1 Color settings

As explained earlier, handwriting is not recommended, so set it with a command. Move the cursor to the part you want to set (for example, if you want to set the color of the variable, move the cursor to int etc.)

M-x describe-face RET

Enter. Then, in this example, Describe face (default ‘font-lock-type-face’): is displayed. In emacs, types are set to ʻintandclass, and the code is easier to see by setting the color for each. If you press the ENTER key in this state, the screen will be split and you can move to the information screen of this font type. By the way, if you are running in No Window mode, you cannot switch operations with the mouse, so you can switch operations with Ctrl-x + o`.

Next, move the cursor to the first line of this setting screen, customize this face, and press the ENTER key. If you go to the bottom, there is a column called [X] Foreground: color-xxx [choose](sample), so Press choose to display a list of colors. Please set your favorite color from this.

By the way, depending on the environment and version, it may be [X] Inherit instead of Foreground. In that case, go to Show All Attributes just below and select Foreground. After completing the settings, use [Apply and save] at the top or Ctrl-x + Ctrl-s to save as usual.

3.2 Code completion related introduction

M-x package-install RET irony RET
M-x package-install RET company-irony RET
M-x package-install RET yasnippet RET
M-x package-install RET flycheck RET

If the package description on .emacs is correct, I think it can be installed without any problem. Only irony is installed after installation

M-x irony-install-server RET

Please execute. By executing this command, irony related settings will be made.

4. Whole .emacs description

Finally, I will post the entire .emacs including the ones I have set up so far.

.emacs


(global-linum-mode t)
(menu-bar-mode -1)
(tool-bar-mode -1)
(setq inhibit-startup-message t)
(setq make-backup-files nil)

;; faces color
;;(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.
 ;; If there is more than one, they won't work right.
 ;; '(font-lock-comment-face ((t (:foreground "color-71"))))
 ;; '(font-lock-constant-face ((t (:foreground "color-105"))))
 ;; '(font-lock-function-name-face ((t (:foreground "color-43"))))
 ;; '(font-lock-keyword-face ((t (:foreground "color-33"))))
 ;; '(font-lock-preprocessor-face ((t (:foreground "color-141"))))
 ;; '(font-lock-string-face ((t (:foreground "color-172"))))
 ;; '(font-lock-type-face ((t (:foreground "color-45"))))
 ;; '(font-lock-variable-name-face ((t (:foreground "color-179")))))

;; package
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(package-initialize)

;; yasnippet
(eval-after-load "yasnippet"
 '(progn
    (define-key yas-keymap (kbd "<tab>") nil)
    (yas-global-mode 1)))

;; company
(when (locate-library "company")
  (global-company-mode 1)
  (global-set-key (kbd "C-M-i") 'company-complete)

  (setq company-idle-delay 0)
  (setq company-selection-wrap-around t)

  (define-key company-active-map (kbd "C-s") 'company-select-next)
  (define-key company-active-map (kbd "C-w") 'company-select-previous)
  (define-key company-search-map (kbd "C-s") 'company-select-next)
  (define-key company-search-map (kbd "C-w") 'company-select-previous)
  (define-key company-active-map (kbd "<tab>") 'company-complete-selection))

;; irony
(eval-after-load "irony"
  '(progn
     (add-to-list 'company-backends 'company-irony)
     (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
     (add-hook 'c-mode-common-hook 'irony-mode)
     (add-hook 'c++-mode-hook 'irony-mode)))

I totally like the color settings. You can use it with copy and paste, but as for the color setting, it is recommended to set it with the command as described above. Please use it after erasing it. (Commented out for the time being)

It's my base environment, so I can extend it further from here, or just this. After that, please create an environment as you like.

Recommended Posts

Emacs-based environment construction
Django environment construction
DeepIE3D environment construction
Linux environment construction
Python environment construction
Environment construction (python)
django environment construction
CodeIgniter environment construction
python environment construction
Python --Environment construction
Python environment construction
Golang environment construction
python environment construction
Word2vec environment construction
Environment construction: GCP + Docker
Django project environment construction
python windows environment construction
Go language environment construction
ConoHa environment construction memo
homebrew python environment construction
PyData related environment construction
Anaconda-4.2.0-python3 environment construction (Mac)
Python development environment construction
YOLO v4 environment construction ①
pyenv + fish environment construction
python2.7 development environment construction
BigGorilla environment construction memo
grip environment construction onCentOS6.5
Anaconda environment construction memo
Golang environment construction [goenv]
Mac environment construction Python
Pyxel environment construction (Mac)
Python environment construction @ Win7
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Python + Anaconda + Pycharm environment construction
About Linux environment construction (CentOS)
PyTorch C ++ (LibTorch) environment construction
Anaconda environment construction on CentOS7
Django development environment construction memo
First LAMP environment construction (Linux)
Python environment construction (Windows10 + Emacs)
Environment
CI environment construction ~ Python edition ~
[Memo] Construction of cygwin environment
ML environment construction with Miniconda
Python environment construction For Mac
Anaconda3 python environment construction procedure
Docker + Django + React environment construction
Anaconda3 × Pycharm environment construction memo
Python3 environment construction (for beginners)
Python environment construction and TensorFlow
NumPy and matplotlib environment construction
Machine learning environment construction macbook 2021
Python environment construction under Windows7 environment
[MEMO] [Development environment construction] Python
Ubuntu14.04 + GPU + TensorFlow environment construction
[Tensorflow] Tensorflow environment construction on Windows 10
Environment construction, Build -Go edition-
django project development environment construction
Linux environment construction (on WSL environment)
Environment construction of python2 & 3 (OSX)