Last active
November 2, 2021 14:25
-
-
Save jehuamanna/9ad864047eb376193b9be441c1995a64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(menu-bar-mode -1) | |
(tool-bar-mode -1) | |
(toggle-scroll-bar -1) | |
;; Initialize package sources | |
(require 'package) | |
(setq package-archives '(("melpa" . "https://melpa.org/packages/" ) | |
("org" . "https://orgmode.org/elpa/" ) | |
("elpa" . "https://elpa.gnu.org/packages/"))) | |
(package-initialize) | |
(unless package-archive-contents (package-refresh-contents)) | |
(unless (package-installed-p 'package-install) | |
(package-install 'use-package)) | |
(require 'use-package) | |
(setq use-package-always-ensure t) | |
(setq package-selected-packages '( | |
elisp-format | |
yasnippet | |
company | |
lsp-mode | |
go-mode | |
exec-path-from-shell | |
lsp-ui | |
lsp-treemacs | |
helm-lsp | |
projectile | |
hydra | |
flycheck | |
avy | |
which-key | |
helm-xref | |
dap-mode | |
json-mode | |
prettier-js | |
ag | |
ripgrep | |
solarized-theme | |
vscode-dark-plus-theme | |
flatui-theme | |
editorconfig | |
tango-plus-theme | |
objed | |
avy | |
rainbow-delimiters | |
unicode-fonts | |
nov | |
auto-rename-tag | |
terraform-mode)) | |
(when (cl-find-if-not #'package-installed-p package-selected-packages) | |
(package-refresh-contents) | |
(mapc #'package-install package-selected-packages)) | |
;; theme | |
(load-theme 'solarized-light t t) | |
(enable-theme 'solarized-light) | |
;; elisp code | |
(require 'elisp-format) | |
;; initializing go env variables. | |
(setenv "PATH" (concat "/home/jehu/go/bin" ":" "/usr/local/go/bin" ":" (getenv "PATH"))) | |
(setq exec-path (append '("/home/jehu/go/bin") '("/usr/local/go/bin") (split-string (getenv "PATH") ":" ))) | |
;; yasnippet | |
(require 'yasnippet) | |
(yas-global-mode 1) | |
;; company mode | |
(setq company-idle-delay 0) | |
(setq company-minimum-prefix-length 1) | |
;; Go lsp-mode | |
;; Setup before-save hooks to format buffers and to add/delete imports | |
(defun lsp-go-install-save-hooks () | |
(add-hook 'before-save-hook #'lsp-format-buffer t t) | |
(add-hook 'before-save-hook #'lsp-organize-imports t t)) | |
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks) | |
;; Start lsp-mode and yasnippet mode | |
(add-hook 'go-mode-hook #'lsp-deferred) | |
(add-hook 'go-mode-hook #'yas-minor-mode) | |
(add-hook 'go-mode-hook | |
(lambda () | |
(local-set-key (kbd "C-c g d p") 'godoc-at-point) | |
(local-set-key (kbd "C-c g d d") 'godoc))) | |
(setq lsp-keymap-prefix "C-c l") | |
;; Auto save and backup directory | |
(setq auto-save-file-name-transforms | |
`((".*" "~/.emacs-saves/" t))) | |
(setq backup-directory-alist `(("." . "~/.emacs-saves"))) | |
(setq backup-by-copying-when-linked t) | |
;; smaple helm configuration use https://github.com/emacs-helm/helm/ for details | |
(helm-mode) | |
(require 'helm-xref) | |
(define-key global-map [remap find-file] #'helm-find-files) | |
(define-key global-map [remap execute-extended-command] #'helm-M-x) | |
(define-key global-map [remap switch-to-buffer] #'helm-mini) | |
(which-key-mode) | |
(add-hook 'prog-mode-hook #'lsp) | |
(add-hook 'c-mode-hook 'lsp) | |
(add-hook 'c++-mode-hook 'lsp) | |
(setq gc-cons-threshold (* 100 1024 1024) | |
read-process-output-max (* 1024 1024) | |
lsp-idle-delay 0.1 | |
create-lockfiles nil) ;; lock files will kill `npm start` | |
(with-eval-after-load 'lsp-mode | |
(add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration) | |
(require 'dap-cpptools) | |
(require 'dap-chrome) | |
(yas-global-mode)) | |
(with-eval-after-load 'js | |
(define-key js-mode-map (kbd "M-.") nil)) | |
(setq lsp-clients-angular-language-server-command | |
'("node" | |
"/home/jehu/.local/lib/node_modules/@angular/language-server" | |
"--ngProbeLocations" | |
"/home/jehu/.local/lib/node_modules" | |
"--tsProbeLocations" | |
"/home/jehu/.local/lib/node_modules" | |
"--stdio")) | |
;; web-mode | |
(setq web-mode-markup-indent-offset 2) | |
(setq web-mode-code-indent-offset 2) | |
(setq web-mode-css-indent-offset 2) | |
(use-package web-mode | |
:ensure t | |
:mode (("\\.js\\'" . web-mode) | |
("\\.jsx\\'" . web-mode) | |
("\\.ts\\'" . web-mode) | |
("\\.tsx\\'" . web-mode) | |
("\\.css\\'" . web-mode) | |
("\\.html\\'" . web-mode)) | |
:commands web-mode) | |
(add-hook 'web-mode-hook #'lsp-deferred) | |
;; magit | |
(use-package magit | |
:ensure t | |
:bind (("C-x g" . magit-status))) | |
;; lsp-mode configurations | |
(setq lsp-log-io nil) ;; Don't log everything === speed | |
(setq lsp-restart 'auto-restart) | |
(setq lsp-ui-sideline-show-diagnostics t) | |
(setq lsp-ui-sideline-show-hover t) | |
(setq lsp-ui-sideline-show-code-actions t) | |
(use-package lsp-ui | |
:ensure t | |
:commands lsp-ui-mode) | |
;; prettier | |
(defun enable-minor-mode (my-pair) | |
"Enable minor mode if filename match the regexp. MY-PAIR is a cons cell (regexp . minor-mode)." | |
(if (buffer-file-name) | |
(if (string-match (car-my-pair) buffer-file-name) | |
(funcall (cdr my-pair))))) | |
(use-package prettier-js | |
:ensure t) | |
(add-hook 'web-mode-hook #'(lambda () | |
(enable-minor-mode | |
'("\\.jsx?\\'" . prettier-js-mode)) | |
(enable-minor-mode | |
'("\\.tsx?\\'" . prettier-js-mode)))) | |
(global-set-key (kbd "C-c f") 'find-file-at-point) | |
(require 'prettier-js) | |
(add-hook 'js-mode-hook 'add-node-modules-path) | |
(add-hook 'js-mode-hook 'prettier-js-mode) | |
(add-hook 'web-mode-hook 'add-node-modules-path) | |
(add-hook 'web-mode-hook 'prettier-js-mode) | |
(global-unset-key (kbd "C-z")) | |
(use-package projectile | |
:config (projectile-mode 1) | |
(setq projectile-project-search-path '("~/Workspace")) | |
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)) | |
(global-auto-revert-mode t) | |
(define-key global-map (kbd "C-.") 'company-files) | |
(require 'yaml-mode) | |
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)) | |
(add-hook 'yaml-mode-hook | |
(lambda () | |
(define-key yaml-mode-map "\C-m" 'newline-and-indent))) | |
(editorconfig-mode 1) | |
;; Add new line below and move the cursor and indent | |
(global-set-key (kbd "C-S-M") (lambda () | |
(interactive) | |
(end-of-line) | |
(newline-and-indent))) | |
(global-set-key (kbd "C-S-O") (lambda () | |
(interactive) | |
(previous-line) | |
(end-of-line) | |
(newline-and-indent))) | |
(global-set-key (kbd "C-c i V") (lambda () | |
(interactive) | |
(move-beginning-of-line nil) | |
(set-mark-command nil) | |
(move-end-of-line nil))) | |
;; enable objed-mode | |
(global-set-key (kbd "C-c o") 'objed-mode) | |
;; enable line highlight | |
(global-hl-line-mode +1) | |
;; avy | |
(use-package avy | |
:ensure t) | |
(avy-setup-default) | |
(add-hook 'foo-mode-hook #'rainbow-delimiters-mode) | |
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode) | |
(setq scroll-preserve-screen-position nil) | |
;; unicode fonts | |
(require 'unicode-fonts) | |
(unicode-fonts-setup) | |
;; emoji | |
(use-package emojify | |
:hook (after-init . global-emojify-mode)) | |
;; character encoding https://www.masteringemacs.org/article/working-coding-systems-unicode-emacs | |
(prefer-coding-system 'utf-8) | |
(set-default-coding-systems 'utf-8) | |
(set-terminal-coding-system 'utf-8) | |
(set-keyboard-coding-system 'utf-8) | |
;; backwards compatibility as default-buffer-file-coding-system | |
;; is deprecated in 23.2. | |
(if (boundp 'buffer-file-coding-system) | |
(setq-default buffer-file-coding-system 'utf-8) | |
(setq default-buffer-file-coding-system 'utf-8)) | |
;; Treat clipboard input as UTF-8 string first; compound text next, etc. | |
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)) | |
;; font | |
(set-frame-font "Hack 11" nil t) | |
(setq Man-coding-system 'utf-8) | |
;; epub reader nov | |
(add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)) | |
;; move text up and down | |
(defun move-text-internal (arg) | |
(cond | |
((and mark-active transient-mark-mode) | |
(if (> (point) (mark)) | |
(exchange-point-and-mark)) | |
(let ((column (current-column)) | |
(text (delete-and-extract-region (point) (mark)))) | |
(forward-line arg) | |
(move-to-column column t) | |
(set-mark (point)) | |
(insert text) | |
(exchange-point-and-mark) | |
(setq deactivate-mark nil))) | |
(t | |
(beginning-of-line) | |
(when (or (> arg 0) (not (bobp))) | |
(forward-line) | |
(when (or (< arg 0) (not (eobp))) | |
(transpose-lines arg)) | |
(forward-line -1))))) | |
(defun move-text-down (arg) | |
"Move region (transient-mark-mode active) or current line | |
arg lines down." | |
(interactive "*p") | |
(move-text-internal arg)) | |
(defun move-text-up (arg) | |
"Move region (transient-mark-mode active) or current line | |
arg lines up." | |
(interactive "*p") | |
(move-text-internal (- arg))) | |
(global-set-key [\M-\S-up] 'move-text-up) | |
(global-set-key [\M-\S-down] 'move-text-down) | |
;; kill all buffers | |
(defun close-all-buffers () | |
(interactive) | |
(mapc 'kill-buffer (buffer-list))) | |
;; terraform | |
(add-to-list 'lsp-language-id-configuration '(terraform-mode . "terraform")) | |
(lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection '("/home/jehu/terraform-lsp" | |
"-enable-log-file")) | |
:major-modes '(terraform-mode) | |
:server-id 'terraform-ls)) | |
(add-hook 'terraform-mode-hook #'lsp) | |
(auto-rename-tag-mode 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. | |
'(package-selected-packages | |
'(emojify ivy-avy objed editorconfig use-package elisp-format yasnippet company lsp-mode go-mode exec-path-from-shell lsp-ui lsp-treemacs helm-lsp projectile hydra flycheck avy which-key helm-xref dap-mode json-mode prettier-js ag ripgrep))) | |
(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. | |
'(default ((((class color) (min-colors 89)) (:foreground "#657b83" :background "#fdf6e3"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment