Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
286 lines (221 sloc) 9.29 KB
;;; ~/.doom.d/+prog.el -*- lexical-binding: t; -*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; COMPANY
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(after! company
(setq company-minimum-prefix-length 2
company-quickhelp-delay nil
company-show-numbers t
company-global-modes '(not comint-mode erc-mode message-mode help-mode gud-mode)))
(use-package! company-lsp
:after company
:init
;; Language servers have better idea filtering and sorting,
;; don't filter results on the client side.
(setq company-transformers nil
company-lsp-cache-candidates nil)
(set-company-backend! 'lsp-mode 'company-lsp))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FLYCHECK
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar cspell-base-program (executable-find "cspell"))
(defvar cspell-config-file-path (concat "'" (expand-file-name "~/Dotfiles/cspell.json") "'"))
(defvar cspell-args (string-join `("--config" ,cspell-config-file-path) " "))
(defun cspell-check-buffer ()
(interactive)
(if cspell-base-program
(let* ((file-name (concat "'" (buffer-file-name) "'"))
(command (string-join `(,cspell-base-program ,cspell-args ,file-name) " ")))
(compilation-start command 'grep-mode))
(message "Cannot find cspell, please install with `npm install -g csepll`")
))
(defun cspell-check-directory ()
(interactive)
(if cspell-base-program
(let* ((files "'**/*.{js,jsx,ts,tsx,c,cc,cpp,h,hh,hpp,go,json}'")
(command (string-join `(,cspell-base-program ,cspell-args ,files) " ")))
(compilation-start command 'grep-mode))
(message "Cannot find cspell, please install with `npm install -g csepll`")))
;; (use-package! wucuo
;; :defer t
;; :init
;; (add-hook! (js2-mode rjsx-mode go-mode c-mode c++-mode) #'wucuo-start))
(after! flycheck
(setq-default flycheck-disabled-checkers
'(
javascript-jshint handlebars
json-jsonlist json-python-json
c/c++-clang c/c++-cppcheck c/c++-gcc
python-pylint python-flake8 python-pycompile
))
;; customize flycheck temp file prefix
(setq-default flycheck-temp-prefix ".flycheck")
;; ======================== JS & TS ========================
(flycheck-add-mode 'typescript-tslint 'web-mode)
(after! tide
(flycheck-add-next-checker 'javascript-eslint '(t . javascript-tide) 'append)
(flycheck-add-next-checker 'javascript-eslint '(t . jsx-tide) 'append)
(flycheck-add-next-checker 'typescript-tslint '(t . typescript-tide) 'append)
(flycheck-add-next-checker 'javascript-eslint '(t . tsx-tide) 'append))
;; ======================== Python ========================
(require 'flycheck-mypy)
;; ======================== CC ========================
(require 'flycheck-google-cpplint)
(setq flycheck-c/c++-googlelint-executable "cpplint")
(flycheck-add-next-checker 'c/c++-gcc '(t . c/c++-googlelint))
(setq flycheck-c/c++-gcc-executable "gcc-7"
flycheck-gcc-include-path '("/usr/local/inclue"))
(add-hook! c++-mode-hook
(setq flycheck-gcc-language-standard "c++11"
flycheck-clang-language-standard "c++11"))
)
(defun disable-flycheck-mode ()
(flycheck-mode -1))
;; (add-hook! (emacs-lisp-mode) 'disable-flycheck-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(after! cc-mode
(c-add-style
"my-cc" '("user"
(c-basic-offset . 2)
(c-offsets-alist
. ((innamespace . 0)
(access-label . -)
(case-label . 0)
(member-init-intro . +)
(topmost-intro . 0)
(arglist-cont-nonempty . +)))))
(setq c-default-style "my-cc")
(setq-default c-basic-offset 2)
(add-to-list 'auto-mode-alist '("\\.inl\\'" . +cc-c-c++-objc-mode))
(add-to-list 'auto-mode-alist '("\\.inc\\'" . +cc-c-c++-objc-mode)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PYTHON
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(after! python
(setq python-indent-offset 4
python-shell-interpreter "python3"
pippel-python-command "python3"
importmagic-python-interpreter "python3"
flycheck-python-pylint-executable "pylint"
flycheck-python-flake8-executable "flake8")
;; if you use pyton2, then you could comment the following 2 lines
;; (setq python-shell-interpreter "python2"
;; python-shell-interpreter-args "-i")
)
(after! lsp-python-ms
(setq lsp-python-ms-python-executable-cmd "python3"))
(use-package! py-isort
:defer t
:init
(setq python-sort-imports-on-save t)
(defun +python/python-sort-imports ()
(interactive)
(when (and python-sort-imports-on-save
(derived-mode-p 'python-mode))
(py-isort-before-save)))
;; (add-hook! 'python-mode-hook
;; (add-hook 'before-save-hook #'+python/python-sort-imports nil t))
)
(use-package! importmagic
:defer t
:hook (python-mode . importmagic-mode)
:commands (importmagic-fix-imports importmagic-fix-symbol-at-point)
:config
(dolist (func '(importmagic-fix-imports importmagic-fix-symbol-at-point))
(advice-add func :before #'revert-buffer-no-confirm)))
(after! pipenv
(setq pipenv-with-projectile t)
;; Override pipenv--clean-response to trim color codes
(defun pipenv--clean-response (response)
"Clean up RESPONSE from shell command."
(replace-regexp-in-string "\n\\[0m$" "" (s-chomp response)))
;; restart flycheck-mode after env activate and deactivate
(dolist (func '(pipenv-activate pipenv-deactivate))
(advice-add func :after #'reset-flycheck)))
(after! conda
(when IS-LINUX
;; Ubuntu anaconda
(setq conda-anaconda-home "~/anaconda3"))
(setq conda-env-home-directory (expand-file-name "~/.conda"))
;; restart flycheck-mode after env activate and deactivate
(dolist (func '(conda-env-activate conda-env-deactivate))
(advice-add func :after #'reset-flycheck)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; JS, WEB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package! indium
:defer t)
(use-package! import-js
:defer t
:init
(add-hook! (js2-mode rjsx-mode) (run-import-js))
(add-hook! (js2-mode rjsx-mode)
(add-hook 'after-save-hook #'import-js-fix nil t)))
(advice-add '+javascript|cleanup-tide-processes :after 'kill-import-js)
(after! web-mode
(web-mode-toggle-current-element-highlight)
(web-mode-dom-errors-show))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GO
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(after! go-mode
(add-hook! go-mode (setq indent-tabs-mode nil))
(add-hook! go-mode #'lsp))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LSP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun toggle-lsp-ui-doc ()
(interactive)
(if lsp-ui-doc-mode
(progn
(lsp-ui-doc-mode -1)
(lsp-ui-doc--hide-frame))
(lsp-ui-doc-mode 1)))
(defun my-lsp-mode-hook ()
;; disable lsp-highlight-symbol
;; (setq lsp-highlight-symbol-at-point nil)
;; toggle off lsp-ui-doc by default
;; (toggle-lsp-ui-doc)
)
;; (add-hook 'lsp-ui-mode-hook #'my-lsp-mode-hook)
(after! lsp-mode
(setq lsp-use-native-json t
lsp-print-io nil)
(dolist (dir '("[/\\\\]\\.ccls-cache$"
"[/\\\\]\\.mypy-cache$"
"[/\\\\]\\.pytest-cache$"
"bazel-bin$"
"bazel-code$"
"bazel-genfiles$"
"bazel-out$"
"bazel-testlogs$"
"[/\\\\]\\.clwb$"
))
(push dir lsp-file-watch-ignored))
)
(after! lsp-ui
(setq lsp-ui-sideline-enable nil
lsp-ui-doc-include-signature t)
;; set lsp-ui-doc position
;; (setq lsp-ui-doc-position 'at-point)
;; Add remapping until doom has better async solution
(define-key! lsp-ui-mode-map
[remap xref-find-definitions] #'lsp-ui-peek-find-definitions
[remap xref-find-references] #'lsp-ui-peek-find-references
;; `set-lookup-handlers!' won't work for lsp-ui-peek commands, because they
;; don't switch buffers
[remap +lookup/definition] #'lsp-ui-peek-find-definitions
[remap +lookup/references] #'lsp-ui-peek-find-references)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DEBUG & RUN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(after! quickrun
(quickrun-add-command "c++/c1z"
'((:command . "clang++")
(:exec . ("%c -std=c++1z %o -o %e %s"
"%e %a"))
(:remove . ("%e")))
:default "c++"))
You can’t perform that action at this time.