Skip to content

Instantly share code, notes, and snippets.

@AgrYpn1a
Created June 26, 2024 16:52
Show Gist options
  • Save AgrYpn1a/32b666649dfbee222ab411523947933a to your computer and use it in GitHub Desktop.
Save AgrYpn1a/32b666649dfbee222ab411523947933a to your computer and use it in GitHub Desktop.
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;; Place your private configuration here! Remember, you do not need to run 'doom
;; sync' after modifying this file!
;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets. It is optional.
;; (setq user-full-name "John Doe"
;; user-mail-address "john@doe.com")
;; Doom exposes five (optional) variables for controlling fonts in Doom:
;;
;; - `doom-font' -- the primary font to use
;; - `doom-variable-pitch-font' -- a non-monospace font (where applicable)
;; - `doom-big-font' -- used for `doom-big-font-mode'; use this for
;; presentations or streaming.
;; - `doom-symbol-font' -- for symbols
;; - `doom-serif-font' -- for the `fixed-pitch-serif' face
;;
;; See 'C-h v doom-font' for documentation and more examples of what they
;; accept. For example:
;;
;;(setq doom-font (font-spec :family "Fira Code" :size 12 :weight 'semi-light)
;; doom-variable-pitch-font (font-spec :family "Fira Sans" :size 13))
;;
;; If you or Emacs can't find your font, use 'M-x describe-font' to look them
;; up, `M-x eval-region' to execute elisp code, and 'M-x doom/reload-font' to
;; refresh your font settings. If Emacs still can't find your font, it likely
;; wasn't installed correctly. Font issues are rarely Doom issues!
;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default:
(setq doom-theme 'doom-one)
;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t)
;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/org/")
;; Whenever you reconfigure a package, make sure to wrap your config in an
;; `after!' block, otherwise Doom's defaults may override your settings. E.g.
;;
;; (after! PACKAGE
;; (setq x y))
;;
;; The exceptions to this rule:
;;
;; - Setting file/directory variables (like `org-directory')
;; - Setting variables which explicitly tell you to set them before their
;; package is loaded (see 'C-h v VARIABLE' to look up their documentation).
;; - Setting doom variables (which start with 'doom-' or '+').
;;
;; Here are some additional functions/macros that will help you configure Doom.
;;
;; - `load!' for loading external *.el files relative to this one
;; - `use-package!' for configuring packages
;; - `after!' for running code after a package has loaded
;; - `add-load-path!' for adding directories to the `load-path', relative to
;; this file. Emacs searches the `load-path' when you load packages with
;; `require' or `use-package'.
;; - `map!' for binding new keys
;;
;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k').
;; This will open documentation for it, including demos of how they are used.
;; Alternatively, use `C-h o' to look up a symbol (functions, variables, faces,
;; etc).
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.
;; General Emacs Config ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq window-divider-default-bottom-width 4 ; in pixels
window-divider-default-right-width 4)
(window-divider-mode +1)
;; Prevent showing eldoc minibuffer if full buffer is open
(setq eldoc-echo-area-use-multiline-p 20)
(setq eldoc-echo-area-prefer-doc-buffer t)
;; Theme ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(with-eval-after-load 'doom-themes
(doom-themes-treemacs-config))
(load-theme 'doom-solarized-light t)
;; Treemacs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package treemacs
:ensure t
:defer t
:init
(with-eval-after-load 'winum
(define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
:config
(progn
(setq
;; treemacs-collapse-dirs (if treemacs-python-executable 3 0)
;; treemacs-deferred-git-apply-delay 0.5
;; treemacs-directory-name-transformer #'identity
;; treemacs-display-in-side-window t
;; treemacs-eldoc-display 'simple
;; treemacs-file-event-delay 2000
;; treemacs-file-extension-regex treemacs-last-period-regex-value
;; treemacs-file-follow-delay 0.2
;; treemacs-file-name-transformer #'identity
;; treemacs-follow-after-init t
;; treemacs-expand-after-init t
;; treemacs-find-workspace-method 'find-for-file-or-pick-first
;; treemacs-git-command-pipe ""
;; treemacs-goto-tag-strategy 'refetch-index
;; treemacs-header-scroll-indicators '(nil . "^^^^^^")
;; treemacs-hide-dot-git-directory t
;; treemacs-indentation 2
;; treemacs-indentation-string " "
;; treemacs-is-never-other-window nil
;; treemacs-max-git-entries 5000
;; treemacs-missing-project-action 'ask
;; treemacs-move-forward-on-expand nil
;; treemacs-no-png-images nil
;; treemacs-no-delete-other-windows t
;; treemacs-project-follow-cleanup nil
;; treemacs-persist-file (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
;; treemacs-position 'left
;; treemacs-read-string-input 'from-child-frame
;; treemacs-recenter-distance 0.1
;; treemacs-recenter-after-file-follow nil
;; treemacs-recenter-after-tag-follow nil
;; treemacs-recenter-after-project-jump 'always
;; treemacs-recenter-after-project-expand 'on-distance
;; treemacs-litter-directories '("/node_modules" "/.venv" "/.cask")
;; treemacs-project-follow-into-home nil
;; treemacs-show-cursor nil
;; treemacs-show-hidden-files t
;; treemacs-silent-filewatch nil
;; treemacs-silent-refresh nil
;; treemacs-sorting 'alphabetic-asc
;; treemacs-select-when-already-in-treemacs 'move-back
;; treemacs-space-between-root-nodes t
;; treemacs-tag-follow-cleanup t
;; treemacs-tag-follow-delay 1.5
;; treemacs-text-scale nil
;; treemacs-user-mode-line-format nil
;; treemacs-user-header-line-format nil
;; treemacs-wide-toggle-width 70
;; treemacs-width 35
;; treemacs-width-increment 1
;; treemacs-width-is-initially-locked t
treemacs-workspace-switch-cleanup nil)
;; The default width and height of the icons is 22 pixels. If you are
;; using a Hi-DPI display, uncomment this to double the icon size.
;;(treemacs-resize-icons 44)
(treemacs-follow-mode t)
(treemacs-filewatch-mode t)
(treemacs-fringe-indicator-mode 'always)
(when treemacs-python-executable
(treemacs-git-commit-diff-mode t))
(pcase (cons (not (null (executable-find "git")))
(not (null treemacs-python-executable)))
(`(t . t)
(treemacs-git-mode 'deferred))
(`(t . _)
(treemacs-git-mode 'simple)))
(treemacs-hide-gitignored-files-mode nil))
:bind
(:map global-map
("M-0" . treemacs-select-window)
("C-x t 1" . treemacs-delete-other-windows)
("C-x t t" . treemacs)
("C-x t d" . treemacs-select-directory)
("C-x t B" . treemacs-bookmark)
("C-x t C-t" . treemacs-find-file)
("C-x t M-t" . treemacs-find-tag)))
(use-package treemacs-evil
:after (treemacs evil)
:ensure t)
(use-package treemacs-projectile
:after (treemacs projectile)
:ensure t)
;; (use-package treemacs-icons-dired
;; :hook (dired-mode . treemacs-icons-dired-enable-once)
;; :ensure t)
(use-package treemacs-magit
:after (treemacs magit)
:ensure t)
(use-package treemacs-persp ;;treemacs-perspective if you use perspective.el vs. persp-mode
:after (treemacs persp-mode) ;;or perspective vs. persp-mode
:ensure t
:config (treemacs-set-scope-type 'Perspectives))
;; Fix icons
(use-package treemacs-nerd-icons
:after treemacs
:config
(treemacs-load-theme "nerd-icons"))
;; Tree-sitter ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (use-package tree-sitter
;; :config
;; ;; activate tree-sitter on any buffer containing code for which it has a parser available
;; (global-tree-sitter-mode)
;; ;; you can easily see the difference tree-sitter-hl-mode makes for python, ts or tsx
;; ;; by switching on and off
;; (add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
(setq treesit-language-source-alist
'((bash "https://github.com/tree-sitter/tree-sitter-bash")
(cmake "https://github.com/uyha/tree-sitter-cmake")
(css "https://github.com/tree-sitter/tree-sitter-css")
(elisp "https://github.com/Wilfred/tree-sitter-elisp")
(go "https://github.com/tree-sitter/tree-sitter-go")
(html "https://github.com/tree-sitter/tree-sitter-html")
(javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src")
(json "https://github.com/tree-sitter/tree-sitter-json")
(make "https://github.com/alemuller/tree-sitter-make")
(markdown "https://github.com/ikatyang/tree-sitter-markdown")
(python "https://github.com/tree-sitter/tree-sitter-python")
(toml "https://github.com/tree-sitter/tree-sitter-toml")
(tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
(typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")
(yaml "https://github.com/ikatyang/tree-sitter-yaml")))
;; Eglot ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package eglot
:after
(project projectile)
:config
;; Scala
(add-to-list 'eglot-server-programs '(scala-mode . ("metals-emacs")))
;; React
(add-to-list 'eglot-server-programs
'((rjsx-mode) "typescript-language-server" "--stdio"))
;; TODO: Testing out this configuration
;; Define workspace configuration for typescript-language-server
(setq-local eglot-workspace-configuration
'((:typescript . (:preferences
(:disableSuggestions false)
:diagnostics
(:noSemanticValidation true)))))
;; React + Typescript
(add-to-list 'eglot-server-programs
'((typescriptreact-mode) "typescript-language-server" "--stdio"))
;; Haskell
(add-hook 'haskell-mode-hook 'eglot-ensure)
(setq-default eglot-workspace-configuration
'((haskell
(plugin
(stan
(globalOn . :json-false))))
)) ;; disable stan
(setq eglot-confirm-server-edits nil)
;; Ensure Flymake is disabled after Eglot is initialized
;; we want to use Flycheck instead
(add-hook 'eglot-managed-mode-hook (lambda ()
(flymake-mode -1)
(flycheck-mode 1)))
(put 'eglot-node 'flymake-overlay-control nil)
(put 'eglot-warning 'flymake-overlay-control nil)
(put 'eglot-error 'flymake-overlay-control nil)
:hook
(typescript-ts-base-mode . eglot-ensure)
(rjsx-mode . eglot-ensure)
:custom
(eglot-autoshutdown t)
)
;; (use-package project :demand t)
;; (cl-defmethod project-root ((project (head eglot-project)))
;; (cdr project))
;; (defun my-project-try-tsconfig-json (dir)
;; (when-let* ((found (locate-dominating-file dir "tsconfig.json")))
;; (cons 'eglot-project found)))
;; (add-hook 'eglot-managed-mode-hook #'eldoc-box-hover-at-point-mode t)
;; Code formatting ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package apheleia
:config
(apheleia-global-mode -1))
;; Typescript ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package typescript-mode
:after tree-sitter
:config
;; we choose this instead of tsx-mode so that eglot can automatically figure out language for server
;; see https://github.com/joaotavora/eglot/issues/624 and https://github.com/joaotavora/eglot#handling-quirky-servers
(define-derived-mode typescriptreact-mode typescript-mode
"TypeScript TSX")
;; use our derived mode for tsx files
(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescriptreact-mode))
;; by default, typescript-mode is mapped to the treesitter typescript parser
;; use our derived mode to map both .tsx AND .ts -> typescriptreact-mode -> treesitter tsx
(add-to-list 'tree-sitter-major-mode-language-alist '(typescriptreact-mode . tsx)))
(add-hook 'typescript-mode-hook (lambda () (flycheck-mode -1)))
;; JSON ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'json-mode-hook
(lambda ()
(make-local-variable 'js-indent-level)
(setq tab-width 4)
(setq js-indent-level 4)))
;; Haskell ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'haskell-mode-hook #'flycheck-haskell-setup)
;; Disable stack, it affects performance badly
(setq-default flycheck-disabled-checkers '(haskell-stack-ghc))
(defun my-haskell-format-on-save ()
"Format Haskell buffer using HLS on save."
(when (eq major-mode 'haskell-mode)
(message "Formatting buffer with HLS...")
(eglot-format-buffer)))
(add-hook 'before-save-hook #'my-haskell-format-on-save)
;; (defun reactjs-eslint-on-save ()
;; "Fix eslint issues on save."
;; (when (eq major-mode 'rjsx-mode)
;; (message "Formatting buffer with HLS...")
;; (eglot-format-buffer)))
;; (defun eslint-fix-file ()
;; (interactive)
;; (message "eslint --fixing the file" (buffer-file-name))
;; (shell-command (concat "eslint_d --fix " (buffer-file-name))))
;; (defun eslint-fix-file-and-revert ()
;; (interactive)
;; (eslint-fix-file)
;; (revert-buffer t t))
;; (add-hook 'rjsx-mode
;; (lambda ()
;; (add-hook 'after-save-hook #'eslint-fix-file-and-revert)))
;; (add-hook 'rjsx-mode #'eslint-fix-auto-mode)
;; Flycheck
(use-package flycheck
:ensure t
:init
(global-flycheck-mode)
:config
(flymake-mode -1)
(advice-add 'flycheck-eslint-config-exists-p :override (lambda() t))
(flycheck-add-mode 'javascript-eslint 'rjsx-mode)
(setq flycheck-javascript-eslint-executable "eslint_d"))
(use-package flycheck-eglot
:ensure t
:after (flycheck eglot)
:custom (flycheck-eglot-exclusive nil)
:config
(global-flycheck-eglot-mode 1))
(add-hook 'after-init-hook #'global-flycheck-mode)
(setq eslint-fix-executable "eslint_d")
;; rjsx-mode setup
(defun my-rjsx-mode-setup ()
(flymake-mode -1) ; Disable Flymake
(flycheck-mode 1)
(eslint-fix-auto-mode 1))
(add-hook 'rjsx-mode-hook 'my-rjsx-mode-setup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment