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.
** 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 **
First install what you need to build code completion related.
sudo apt-get install -y cmake clang
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.
(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.
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.
(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.
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.
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.
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 ʻintand
class, 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.
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.
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