alex / emacs-config

~/.emacs.d/init.el Commits Diff Raw
;;; init.el --- Initialization file for Emacs
;;; Commentary:
;; Emacs Startup File --- initialization for Emacs

;;; Code:
(require 'package)

(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))
(package-initialize)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

;; Line numbers in modern emacs
(when (version<= "26.0.50" emacs-version )
  (global-display-line-numbers-mode))

;; powerline status bar
(use-package powerline
  :ensure t
  :config
  (powerline-default-theme))

;; evil mode for vim emulation
(use-package evil
  :ensure t
  :init
  (setq evil-want-integration nil) ;; required by evil-collection
  (setq evil-search-module 'evil-search)
  (setq evil-ex-complete-emacs-commands nil)
  (setq evil-vsplit-window-right t) ;; like vim's 'splitright'
  (setq evil-split-window-below t) ;; like vim's 'splitbelow'
  (setq evil-shift-round nil)
  (setq evil-want-C-u-scroll t)
  :config
  (evil-mode))

;; lsp Language Server Interface Mode
(use-package lsp-mode
  :ensure t)

;; Company mode for autocomplete
(use-package company
  :ensure t
  :config
  (add-hook 'after-init-hook 'global-company-mode))

;; yasnippet templating for autocomplete in company-mode
(use-package yasnippet
  :ensure t
  :config
  (yas-global-mode 1))

(use-package company-quickhelp
  :ensure t
  :config
  (company-quickhelp-mode))

; bind company-select-next to tab
(eval-after-load 'company
  '(progn
     (define-key company-active-map (kbd "TAB") 'company-select-next)
     (define-key company-active-map [tab] 'company-select-next)))
;; (setq company-selection t) <-- this doesn't make sense -- Dmitry
(setq company-idle-delay 0)

(use-package flycheck
  :ensure t
  :config
  (flycheck-add-mode 'javascript-eslint 'web-mode) ;; use eslint for jsx files
  (add-hook 'after-init-hook #'global-flycheck-mode)) ;; enable in all buffers

;; Javascript IDE
(use-package web-mode
  :ensure t
  :config
  (add-hook 'web-mode-hook 'lsp-deferred) ;; use lsp when in web-mode
  (add-to-list 'auto-mode-alist '("\\.jsx?$" . web-mode))) ;; auto-enable for js/jsx files

(use-package prettier-js
  :ensure t
  :config
  (add-hook 'web-mode-hook  'prettier-js-mode))

(use-package add-node-modules-path
  :ensure t
  :config
  (add-hook 'flycheck-mode-hook 'add-node-modules-path)) ;; use eslint from node_modules

(defun web-mode-init-hook ()
  "Hooks for Web mode.  Adjust indent."
  (setq web-mode-markup-indent-offset 2))
  
(add-hook 'web-mode-hook  'web-mode-init-hook)
;; JSX syntax highlighting
(setq web-mode-content-types-alist '(("jsx" . "\\.js[x]?\\'")))

;; Golang IDE
(use-package go-mode
  :ensure t
  :hook (flycheck-add-next-checker 'lsp-ui 'golangci-lint)
  :config
  (setq gofmt-command "goimports") ;; use goimports instead of gofmt
  (add-hook 'before-save-hook 'gofmt-before-save)
  (add-hook 'go-mode-hook 'lsp-deferred)
  ;; Use go-mode when loading a file with extension .go
  (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode)))

(use-package flycheck-golangci-lint
  :ensure t
  :hook (go-mode . flycheck-golangci-lint-setup)
  :config
  (setq flycheck-golangci-lint-enable-all t))

(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.
 '(company-selection-wrap-around t)
 '(custom-enabled-themes '(wombat))
 '(inhibit-startup-screen t)
 '(package-selected-packages
   '(yaml-mode coverlay cov go-mode yasnippet which-key web-mode use-package prettier-js powerline neotree lsp-ui flycheck evil dumb-jump company add-node-modules-path)))
(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.
 )

(provide 'init)

;;; init.el ends here