Skip to content

Instantly share code, notes, and snippets.

@k3karthic
Last active May 16, 2023 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k3karthic/dc60bf314f6b43b682a0c8149c6e5fa8 to your computer and use it in GitHub Desktop.
Save k3karthic/dc60bf314f6b43b682a0c8149c6e5fa8 to your computer and use it in GitHub Desktop.
Emacs Configuration
;; Maximize GUI on launch
(add-hook 'window-setup-hook 'toggle-frame-maximized t)
(setq package-enable-at-startup nil)
(defun clear-welcome-buffer ()
"Blank welcome buffer."
(with-current-buffer (get-buffer-create "*Welcome*")
(setq truncate-lines t)
(let* ((buffer-read-only))
(erase-buffer)
(setq mode-line-format nil))
(setq cursor-type nil)
(read-only-mode +1)
(switch-to-buffer (current-buffer))
(local-set-key (kbd "q") 'kill-this-buffer)))
(setq initial-scratch-message nil)
(setq inhibit-startup-screen t)
(when (< (length command-line-args) 2)
(add-hook 'emacs-startup-hook (lambda ()
(when (display-graphic-p)
(clear-welcome-buffer)))))
(global-linum-mode 1)
(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.
)
(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 ((t (:family "DroidSansM Nerd Font Mono" :foundry "outline" :slant normal :weight normal :height 120 :width normal)))))
;; Install straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;; Install use-package
(straight-use-package 'use-package)
;; Configure use-package to use straight.el by default
(use-package straight
:custom (straight-use-package-by-default t))
(use-package doom-themes
:ensure t
:config
;; Global settings (defaults)
(setq doom-themes-enable-bold t ; if nil, bold is universally disabled
doom-themes-enable-italic t) ; if nil, italics is universally disabled
(load-theme 'doom-moonlight t)
;; Enable flashing mode-line on errors
(doom-themes-visual-bell-config))
(use-package nerd-icons
:custom
;; The Nerd Font you want to use in GUI
;; "Symbols Nerd Font Mono" is the default and is recommended
;; but you can use any other Nerd Font if you want
(nerd-icons-font-family "Symbols Nerd Font Mono")
)
(use-package doom-modeline
:ensure t
:hook ((after-init . doom-modeline-mode))
:init
(setq doom-modeline-mu4e nil))
(use-package editorconfig
:ensure t
:config
(editorconfig-mode 1))
(use-package flycheck
:ensure t
:config
(defun my-setup-flycheck-for-typescript ()
(when (and (bound-and-true-p lsp-mode)
(eq major-mode 'typescript-mode))
(flycheck-add-next-checker 'lsp 'javascript-eslint)))
(add-hook 'flycheck-mode-hook #'my-setup-flycheck-for-typescript))
(use-package company
:ensure t
:config
(add-hook 'after-init-hook 'global-company-mode))
(use-package company-tabnine
:ensure t
:config(add-to-list 'company-backends #'company-tabnine)
;; Trigger completion immediately.
(setq company-idle-delay 0)
;; Number the candidates (use M-1, M-2 etc to select completions).
(setq company-show-numbers t))
(use-package counsel
:ensure t
:config
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
;; ivy interface to standard commands
(global-set-key (kbd "C-s") 'swiper-isearch)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "M-y") 'counsel-yank-pop)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "<f2> j") 'counsel-set-variable)
(global-set-key (kbd "C-x b") 'ivy-switch-buffer)
;; ivy resume and other commands
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "C-c b") 'counsel-bookmark)
(global-set-key (kbd "C-c d") 'counsel-descbinds)
(global-set-key (kbd "C-c t") 'counsel-load-theme)
(ivy-mode 1))
(use-package tree-sitter
:ensure t
:config
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
(use-package tree-sitter-langs
:ensure t)
(use-package yaml-mode
:ensure t
:config
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))
(use-package apheleia
:ensure t
:config
(global-set-key (kbd "C-x a f") 'apheleia-format-buffer)
(setf (alist-get 'python-mode apheleia-mode-alist)
'(black))
(setf (alist-get 'typescriptreact-mode apheleia-mode-alist)
'(prettier)))
(use-package typescript-mode
:ensure t
:after tree-sitter)
(straight-use-package '(tsi :type git :host github :repo "orzechowskid/tsi.el"))
(straight-use-package '(tsx-mode :type git :host github :repo "orzechowskid/tsx-mode.el" :branch "emacs28"))
;; use our derived mode for tsx files
;; (add-to-list 'auto-mode-alist '("\\.tsx?\\'" . tsx-mode))
;; tsx-mode automatically loads lsp which can slowdown startup
;; 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 '(tsx-mode . tsx))
(use-package lsp-mode
:ensure t
:init
(setq lsp-keymap-prefix "C-c l")
(setq lsp-enable-snippet nil)
(setq gc-cons-threshold 200000000)
(setq read-process-output-max (* 10 (* 1024 1024)))
:hook ((python-mode . lsp)
(typescript-mode . lsp))
:commands lsp
:config
(defcustom lsp-pylsp-plugins-ruff-enabled nil
"Enable or disable the plugin."
:type 'boolean
:group 'lsp-pylsp)
(defcustom lsp-pylsp-plugins-mypy-enabled nil
"Enable or disable the plugin."
:type 'boolean
:group 'lsp-pylsp)
(lsp-register-custom-settings
'(("pylsp.plugins.ruff.enabled" lsp-pylsp-plugins-ruff-enabled)
("pylsp.plugins.pylsp_mypy.enabled" lsp-pylsp-plugins-mypy-enabled)))
(setq lsp-pylsp-plugins-autopep8-enabled nil)
(setq lsp-pylsp-plugins-yapf-enabled nil)
(setq lsp-pylsp-plugins-black-enabled t)
(setq lsp-pylsp-plugins-flake8-enabled nil)
(setq lsp-pylsp-plugins-mccabe-enabled nil)
(setq lsp-pylsp-plugins-pycodestyle-enabled nil)
(setq lsp-pylsp-plugins-pydocstyle-enabled nil)
(setq lsp-pylsp-plugins-pyflakes-enabled nil)
(setq lsp-pylsp-plugins-pylint-enabled nil)
(setq lsp-pylsp-plugins-ruff-enabled t)
(setq lsp-pylsp-plugins-mypy-enabled t))
(use-package lsp-ui :commands lsp-ui-mode)
(use-package lsp-ivy :commands lsp-ivy-workspace-symbol)
(use-package projectile
:ensure t
:init
(setq projectile-track-known-projects-automatically nil)
(projectile-mode +1)
:bind (:map projectile-mode-map
("C-c p" . projectile-command-map)))
(use-package rg
:ensure t
:config
(rg-enable-default-bindings))
(use-package diff-hl
:ensure t
:config
(global-diff-hl-mode))
(use-package with-venv
:ensure t)
(use-package dap-mode
:ensure t
:after lsp-mode
:commands dap-debug
:config
(dap-auto-configure-mode t)
(require 'dap-python)
(setq dap-python-debugger 'debugpy)
(defun dap-python--pyenv-executable-find (command)
(let ((venv-dir (with-venv-find-venv-dir t)))
(when venv-dir
(let ((dirs (list venv-dir (concat venv-dir "/Scripts"))))
(locate-file "python" dirs exec-suffixes))))))
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: manage.py",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"justMyCode": true,
"args": [
"runserver"
]
},
// Required for some editors which hang or don't work with hot reload
{
"name": "Python: manage.py (no-reload)",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"justMyCode": true,
"args": [
"runserver"
],
"env": {
"DISABLE_HOT_RELOAD": "true"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment