Skip to content

Instantly share code, notes, and snippets.

@GnaneshKunal
Last active December 12, 2021 14:05
Show Gist options
  • Save GnaneshKunal/1d33e8ed2ae13379b8a597344c3c812b to your computer and use it in GitHub Desktop.
Save GnaneshKunal/1d33e8ed2ae13379b8a597344c3c812b to your computer and use it in GitHub Desktop.
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
(setq package-check-signature nil)
(eval-and-compile
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package)))
(setq backup-directory-alist '(("." . "~/.emacs.d/backup"))
backup-by-copying t ; Don't delink hardlinks
version-control t ; Use version numbers on backups
delete-old-versions t ; Automatically delete excess backups
kept-new-versions 20 ; how many of the newest versions to keep
kept-old-versions 5 ; and how many of the old
)
(setq create-lockfiles nil) ; https://github.com/craig-feldman/personal-website-react/issues/1#issuecomment-636466524
(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.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#e090d7" "#8cc4ff" "#eeeeec"])
'(custom-enabled-themes '(tsdh-dark))
'(exwm-floating-border-color "#161616")
'(fci-rule-color "#5c5e5e")
'(highlight-tail-colors ((("#2f383b") . 0) (("#32383d") . 20)))
'(inhibit-startup-screen t)
'(jdee-db-active-breakpoint-face-colors (cons "#0d0d0d" "#5DD8FF"))
'(jdee-db-requested-breakpoint-face-colors (cons "#0d0d0d" "#67B7A4"))
'(jdee-db-spec-breakpoint-face-colors (cons "#0d0d0d" "#6C7986"))
'(lsp-treemacs-sync-mode t)
'(objed-cursor-color "#FC6A5D")
'(package-selected-packages
'(xclip counsel magit lsp-ivy treemacs-perspective yasnippet-snippets which-key web-mode htmlize scala-mode auctex-latexmk vterm typescript-mode lsp-sonarlint flycheck-plantuml plantuml-mode dap-mode lsp-treemacs rainbow-delimiters speed-type dockerfile-mode treemacs-magit swiper ivy go-playground yaml-mode free-keys treemacs-icons-dired treemacs-projectile pbcopy poetry flycheck yasnippet lsp-ui rustic projectile use-package treemacs slime lsp-pyright go-mode company async))
'(pdf-view-midnight-colors (cons "#FFFFFF" "#292A30"))
'(persp-mode t)
'(persp-nil-name "nil")
'(rustic-ansi-faces
["#292A30" "#FC6A5D" "#67B7A4" "#D0BF68" "#5DD8FF" "#D0A8FF" "#8abeb7" "#FFFFFF"])
'(vc-annotate-background "#292A30")
'(vc-annotate-color-map
(list
(cons 20 "#67B7A4")
(cons 40 "#8ab990")
(cons 60 "#adbc7c")
(cons 80 "#D0BF68")
(cons 100 "#dfaf5a")
(cons 120 "#ee9f4c")
(cons 140 "#FD8F3F")
(cons 160 "#ee977f")
(cons 180 "#df9fbf")
(cons 200 "#D0A8FF")
(cons 220 "#de93c9")
(cons 240 "#ed7e93")
(cons 260 "#FC6A5D")
(cons 280 "#d86d67")
(cons 300 "#b47171")
(cons 320 "#90757b")
(cons 340 "#5c5e5e")
(cons 360 "#5c5e5e")))
'(vc-annotate-very-old-color nil)
'(warning-suppress-types '((comp))))
(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.
)
(setq python-indent-offset 4)
(global-set-key (kbd "C-x C-,") 'previous-buffer)
(global-set-key (kbd "C-x ,") 'previous-buffer)
(global-set-key (kbd "C-x /") 'next-buffer)
(global-set-key (kbd "C-x C-/") 'next-buffer)
(global-set-key (kbd "C-x C-_") 'next-buffer)
(menu-bar-mode -1)
(tool-bar-mode -1)
(display-time-mode t)
;; (scroll-bar-mode -1)
(global-linum-mode 1)
(add-hook 'shell-mode-hook (lambda () (linum-mode -1)))
(add-hook 'eshell-mode-hook (lambda () (linum-mode -1)))
;; load bash profile
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (replace-regexp-in-string
"[ \t\n]*$"
""
(shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq eshell-path-env path-from-shell) ; for eshell users
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
(unless package-archive-contents
(package-refresh-contents))
(package-install-selected-packages)
;; font size
(set-face-attribute 'default nil
:family "Source Code Pro"
:height 125
:weight 'medium)
;; mode-line font
(set-face-attribute 'mode-line nil
:family "Source Sans 3")
(use-package xclip :ensure t
:config (xclip-mode))
(use-package projectile
:ensure t
:config
'(projectile-mode t nil (projectile)))
;; magit
(use-package magit
:ensure
:config
(global-set-key (kbd "C-x g") 'magit-status)
(setq transient-default-level 6))
(when (load "flymake" t)
(defun flymake-pylint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "epylint" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pylint-init)))
(use-package rustic
:ensure
:bind (:map rustic-mode-map
("M-j" . lsp-ui-imenu)
("M-?" . lsp-find-references)
("C-c C-c l" . flycheck-list-errors)
("C-c C-c a" . lsp-execute-code-action)
("C-c C-c r" . lsp-rename)
("C-c C-c q" . lsp-workspace-restart)
("C-c C-c Q" . lsp-workspace-shutdown)
("C-c C-c s" . lsp-rust-analyzer-status))
:config
;; uncomment for less flashiness
;; (setq lsp-eldoc-hook nil)
;; (setq lsp-enable-symbol-highlighting nil)
;; (setq lsp-signature-auto-activate nil)
;; comment to disable rustfmt on save
(setq rustic-format-on-save t)
(add-hook 'rustic-mode-hook 'rk/rustic-mode-hook))
(defun rk/rustic-mode-hook ()
;; so that run C-c C-c C-r works without having to confirm, but don't try to
;; save rust buffers that are not file visiting. Once
;; https://github.com/brotzeit/rustic/issues/253 has been resolved this should
;; no longer be necessary.
(when buffer-file-name
(setq-local buffer-save-without-query t)))
(use-package which-key :ensure t
:config
(which-key-mode)
(with-eval-after-load 'lsp-mode
(add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration)))
(use-package ace-window
:ensure
:config
(global-set-key (kbd "C-c ;") 'ace-window))
(global-set-key (kbd "C-c i") 'windmove-right)
(global-set-key (kbd "C-c e") 'windmove-left)
(global-set-key (kbd "C-c p") 'windmove-up)
(global-set-key (kbd "C-c n") 'windmove-down)
;; ivy mode
(use-package ivy
:ensure
:config
(ivy-mode))
;; swiper search
(use-package swiper
:ensure
:config
(global-set-key (kbd "C-s") 'swiper)
(global-set-key (kbd "C-r") 'swiper-backward))
;; ido mode - pre-installed
(setq ido-everywhere t)
(setq ido-enable-flex-matching t)
(ido-mode t)
(use-package rainbow-delimiters
:ensure t
:config (rainbow-delimiters-mode))
(use-package lsp-mode
:ensure
:commands lsp
:init
(setq lsp-keymap-prefix "C-c l")
:custom
;; what to use when checking on-save. "check" is default, I prefer clippy
(lsp-rust-analyzer-cargo-watch-command "clippy")
(lsp-eldoc-render-all t)
(lsp-idle-delay 0.6)
(lsp-rust-analyzer-server-display-inlay-hints t)
:config
(add-hook 'lsp-mode-hook 'lsp-ui-mode)
(lsp-enable-which-key-integration t)
(define-key lsp-mode-map (kbd "C-c C-l") lsp-command-map)
(define-key lsp-mode-map (kbd "C-c l") lsp-command-map))
(use-package lsp-ui
:ensure
:commands lsp-ui-mode
:custom
(lsp-ui-peek-always-show t)
(lsp-ui-sideline-show-hover t)
(lsp-ui-doc-enable nil))
(use-package lsp-ivy
:ensure t)
(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp)))) ; or lsp-deferred
(use-package company
:ensure
:config
;; (company-begin-commands nil) ;; uncomment to disable popup
;; aligns annotation to the right hand side
(setq company-tooltip-align-annotations t)
;; 0.1 second delay before the pop-up appears
(setq company-idle-delay 0.1)
;; you only need to enter one character in a buffer before auto-completion starts
(setq company-minimum-prefix-length 1)
:bind
(:map company-mode-map
("<tab>". tab-indent-or-complete)
("TAB". tab-indent-or-complete))
(:map company-active-map
("C-n". company-select-next)
("C-p". company-select-previous)
("M-<". company-select-first)
("M->". company-select-last)))
(use-package yasnippet
:ensure
:config
(yas-reload-all)
(add-hook 'prog-mode-hook 'yas-minor-mode)
(add-hook 'text-mode-hook 'yas-minor-mode))
(defun company-yasnippet-or-completion ()
(interactive)
(or (do-yas-expand)
(company-complete-common)))
(defun check-expansion ()
(save-excursion
(if (looking-at "\\_>") t
(backward-char 1)
(if (looking-at "\\.") t
(backward-char 1)
(if (looking-at "::") t nil)))))
(defun do-yas-expand ()
(let ((yas/fallback-behavior 'return-nil))
(yas/expand)))
(defun tab-indent-or-complete ()
(interactive)
(if (minibufferp)
(minibuffer-complete)
(if (or (not yas/minor-mode)
(null (do-yas-expand)))
(if (check-expansion)
(company-complete-common)
(indent-for-tab-command)))))
;; ================ RUST END ====================
;; Go - lsp-mode
;; Set up before-save hooks to format buffer and 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))
(use-package go-mode
:ensure
:config
;; 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 #'rainbow-delimiters-mode)
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks))
(use-package perspective
:bind
("C-x C-b" . persp-list-buffers) ; or use a nicer switcher, see below
:config
(persp-mode))
(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 t
treemacs-file-event-delay 5000
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-git-command-pipe ""
treemacs-goto-tag-strategy 'refetch-index
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-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-user-mode-line-format nil
treemacs-user-header-line-format nil
treemacs-width 30
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)
(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 B" . treemacs-bookmark)
("C-x t C-t" . treemacs-find-file)
("C-x t M-t" . treemacs-find-tag)))
(use-package treemacs-projectile
:after (treemacs projectile)
:ensure t)
(use-package treemacs-icons-dired
:after (treemacs dired)
:ensure t
:config (treemacs-icons-dired-mode))
(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))
(use-package treemacs-perspective
:after (treemacs perspective)
:ensure t
:config (treemacs-set-scope-type 'Perspectives))
(setq lsp-sqls-connections
'(((driver . "postgresql") (dataSourceName . "host=127.0.0.1 port=5432 user=setudbuser password=Solong,andthanksforallthefish. dbname=dolphin sslmode=disable"))))
(use-package dap-mode
:ensure
:config
(require 'dap-go))
(use-package plantuml-mode
:ensure
:config
(setq plantuml-jar-path "~/.emacs.d/plantuml.jar")
(setq plantuml-default-exec-mode 'jar)
(add-to-list 'auto-mode-alist '("\\.puml\\'" . plantuml-mode))
(add-to-list 'auto-mode-alist '("\\.plantuml\\'" . plantuml-mode)))
(use-package typescript-mode
:ensure
:config
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-mode))
(add-hook 'typescript-mode-hook #'lsp-deferred)
(add-hook 'typescript-mode-hook #'yas-minor-mode)
(add-hook 'typescript-mode-hook #'rainbow-delimiters-mode))
;; ;; (use-package ligature
;; ;; :load-path "~/.emacs.d/ligature.el"
;; (add-to-list 'load-path "~/.emacs.d/")
;; (load "ligature.el")
;; ;; :config
;; ;; Enable the "www" ligature in every possible major mode
;; (ligature-set-ligatures 't '("www"))
;; ;; Enable traditional ligature support in eww-mode, if the
;; ;; `variable-pitch' face supports it
;; (ligature-set-ligatures 'eww-mode '("ff" "fi" "ffi"))
;; ;; Enable all Cascadia Code ligatures in programming modes
;; (ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
;; ":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
;; "!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
;; "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
;; "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
;; "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
;; "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
;; "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
;; ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
;; "<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
;; "##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
;; "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
;; "\\\\" "://"))
;; ;; Enables ligature checks globally in all buffers. You can also do it
;; ;; per mode with `ligature-mode'.
;; (global-ligature-mode t)
;; ;; )
(use-package web-mode :ensure t
:mode (("\\.js\\'" . web-mode)
("\\.jsx\\'" . web-mode)
("\\.ts\\'" . web-mode)
("\\.tsx\\'" . web-mode)
("\\.html\\'" . web-mode)
("\\.vue\\'" . web-mode)
("\\.json\\'" . web-mode))
:commands web-mode
:config
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq web-mode-content-types-alist
'(("jsx" . "\\.js[x]?\\'")))
(add-hook 'web-mode-hook #'lsp-deferred)
(add-hook 'web-mode-hook #'yas-minor-mode)
(add-hook 'web-mode-hook #'rainbow-delimiters-mode))
;; enable `counsel' for `M-x'.
;; Used to show key-bindings next to the command.
(use-package counsel
:ensure t
:config
(when (commandp 'counsel-M-x)
(global-set-key [remap execute-extended-command] #'counsel-M-x)))
(remove-hook 'flymake-diagnostic-functions 'flymake-proc-legacy-flymake)
;; Allow emacs uppercase (which is disable by default).
(put 'upcase-region 'disabled nil)
;; Bind `avy's versatile `avy-goto-char-timer' to `M-j'
(use-package avy
:ensure t
:config
(global-set-key (kbd "M-j") 'avy-goto-char-timer))
;; lsp for c/c++
(add-hook 'c-mode-hook 'lsp)
(add-hook 'c++-mode-hook 'lsp)
;; utf-8 charset in `ansi-term'
(defadvice ansi-term (after advise-ansi-term-coding-system)
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))
(ad-activate 'ansi-term)
;; Don't store duplicate shell commands history
(setq comint-input-ignoredups t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment