/.emacs.d

my .emacs.d conf files

Primary LanguageEmacs Lisp

BUMP GARBAGE COLLECTION

;; Make startup faster by reducing the frequency of garbage
;; collection.  The default is 800 kilobytes.  Measured in bytes.
(setq gc-cons-threshold (* 96 1024 1024))

UI CLEANUP

 ;; remove default menu bar
 (menu-bar-mode nil)

 ;; disable electric pair and show parent
 (electric-pair-mode nil)
 (show-paren-mode nil)

 ;; hide both frame title bar and the icon
 (setq ns-use-proxy-icon  nil
	   frame-title-format nil)

 ;; disable these GUI based behaviors
 (when window-system
   (scroll-bar-mode -1)
   (tool-bar-mode -1)
   (tooltip-mode -1))

 ;; disable and customize startup message
 (setq inhibit-startup-message t
	   initial-scratch-message ";; Happy Hacking\n")

TEXT RENDERING

;;; use UTF-8 everywhere
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

;; define the font family and size
(set-frame-font "PragmataPro-14" nil t)
(setq prettify-symbols-unprettify-at-point 'right-edge)

;; Load pragmatapro-lig.el
(add-to-list 'load-path "~/.emacs.d/files")
(require 'pragmatapro-lig)
(pragmatapro-lig-global-mode)

(global-prettify-symbols-mode t)

FRAME POSITIONING

   (defun set-initial-frame ()
     "Defines and center the frame window"
     (let* ((base-factor 0.34)
	     (a-width (* (display-pixel-width) base-factor))
	     (a-height (* (display-pixel-height) base-factor))
	     (a-left (truncate (/ (- (display-pixel-width) a-width) 2)))
	     (a-top (truncate (/ (- (display-pixel-height) a-height) 2))))
	(set-frame-position (selected-frame) a-left a-top)
	(set-frame-size (selected-frame) (truncate a-width) (truncate a-height) t)))

   (setq frame-resize-pixelwise t)
   (set-initial-frame)

MAC CONFIGS

;; enable transparent titlebar with dark-mode
(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
(add-to-list 'default-frame-alist '(ns-appearance . dark))

UX CLEANUP

 ;; disable backup
 (setq make-backup-files nil)

 ;; Don't make new frames when opening a new file with Emacs
 (setq ns-pop-up-frames nil)

 ;; define alias to answering just 'y' or 'n' instead
 (defalias 'yes-or-no-p 'y-or-n-p)

 ;; Highlight the current line
 (global-hl-line-mode t)

 ;; nice scrolling
 (setq scroll-margin 0
	  scroll-conservatively 100000
	  scroll-preserve-screen-position t)

 ;; make buffer name unique with style
 (setq uniquify-buffer-name-style 'reverse
	  uniquify-separator "|"
	  uniquify-after-kill-buffer-p t
	  uniquify-ignore-buffers-re "^\\*")

GLOBAL BINDINGS

;; dependable keybindings
(global-set-key (kbd "C-c l") #'goto-line)
(global-set-key (kbd "\C-c n") #'rename-buffer)
(global-set-key (kbd "C-c w") #'whitespace-mode)
(global-set-key (kbd "<C-s-return>") #'toggle-frame-fullscreen)

PACKAGE MANAGER

(require 'package)
(setq package-check-signature nil)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

THEMING

(use-package doom-themes
  :ensure t
  :config
  (setq doom-themes-enable-bold nil
	    doom-themes-enable-italic nil)
  (load-theme 'doom-peacock t)
  (doom-themes-visual-bell-config)
  (doom-themes-org-config))

(use-package doom-modeline
  :ensure t
  :hook (after-init . doom-modeline-mode))

(use-package winum
  :ensure t
  :config (winum-mode))

(use-package all-the-icons
  :ensure t
  :config (setq inhibit-compacting-font-caches t))

OTHER DEFAULTS

;; default directory for dire-mode
(setq default-directory "~/")

;; don't backup please. I got this
(setq make-backup-files nil)

;; disable recentf
(recentf-mode nil)

;; activate column-number-mode
(column-number-mode t)
(setq-default indicate-buffer-boundaries 'right)

;; delete marked region with 'DEL' key or backspace
(delete-selection-mode t)

;; define abbrev file
(setq abbrev-file-name (expand-file-name "abbrev.el" user-emacs-directory))
(unless (file-exists-p abbrev-file-name)
  (write-region "" "" abbrev-file-name))

;; supress some warning
(setq ad-redefinition-action 'accept)

CURSOR STYLING

(setq-default cursor-type '(bar . 1)
	  blink-cursor-delay 0
	  blink-cursor-interval 0.4)

;; flashes the cursor's line switched buffer
(use-package beacon
  :ensure t
  :config
  (beacon-mode t)
  (setq beacon-color "#FB0320"))

WHICH-KEY

(use-package which-key
  :ensure t
  :custom
  (which-key-separator " ")
  (which-key-prefix-prefix "+")
  :config (which-key-mode t))

COUNSEL

(use-package amx :ensure t)
(use-package flx :ensure t)

(use-package counsel
  :ensure t
  :config
  (ivy-mode t)
  (setq ivy-use-virtual-buffers t
	    ivy-initial-inputs-alist nil
	    enable-recursive-minibuffers t
	    search-default-mode #'char-fold-to-regexp
	    ivy-re-builders-alist
	    '((ivy-switch-buffer . ivy--regex-plus)
	      (t . ivy--regex-fuzzy)))
  :bind (("C-s" . counsel-grep-or-swiper)
	     ("M-x" . counsel-M-x)
	     ("C-x C-m" . counsel-M-x)
	     ("C-x C-f" . counsel-find-file)))

(use-package avy-flycheck
  :ensure t
  :config
  (global-set-key (kbd "C-'") #'avy-flycheck-goto-error))

(use-package all-the-icons-ivy
  :ensure t
  :config (all-the-icons-ivy-setup))

ORG

   (use-package org
    :ensure org-plus-contrib
    :config (setq
	      org-src-fontify-natively t
	      org-src-tab-acts-natively t
	      org-todo-keywords '((sequence "BACKLOG(b)" "TODO(t)" "DOING(n)" "|" "DONE(d)")
				  (sequence "|"  "ONHOLD(h)" "CANCELED(c)"))
	      org-agenda-files '("~/.org/agenda.org")))


   (use-package restclient
     :ensure t
     :config (add-hook 'restclient-mode-hook 'company-restclient))

   (use-package company-restclient
     :ensure t
     :config
     (progn
	(add-hook 'restclient-mode-hook
		  (lambda ()
		    (set (make-local-variable 'company-backends)'(company-restclient))
		    (company-mode t)))))

   (use-package ob-restclient
     :ensure t
     :config 
     (org-babel-do-load-languages 'org-babel-load-languages '((restclient . t))))

ANSI-XTERM

   ;; (use-package xterm-color
   ;;   :config
   ;;   (setq comint-output-filter-functions
   ;; 	(remove 'ansi-color-process-output comint-output-filter-functions))

   ;;   (add-hook 'shell-mode-hook
   ;; 	    (lambda () (add-hook 'comint-preoutput-filter-functions
   ;; 				 'xterm-color-filter nil t))))


   ;; ANSI & XTERM 256 color support
   (use-package xterm-color
     :defines (compilation-environment
		eshell-preoutput-filter-functions
		eshell-output-filter-functions)
     :functions (compilation-filter my-advice-compilation-filter)
     :init
     ;; For shell and interpreters
     (setenv "TERM" "xterm-256color")
     (setq comint-output-filter-functions
	    (remove 'ansi-color-process-output comint-output-filter-functions))
     (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter)
     (add-hook 'shell-mode-hook
		(lambda ()
		  ;; Disable font-locking to improve performance
		  (font-lock-mode -1)
		  ;; Prevent font-locking from being re-enabled
		  (make-local-variable 'font-lock-function)
		  (setq font-lock-function #'ignore)))
     ;; For eshell
     (with-eval-after-load 'esh-mode
	(add-hook 'eshell-before-prompt-hook
		  (lambda ()
		    (setq xterm-color-preserve-properties t)))
	(add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter)
	(setq eshell-output-filter-functions
	      (remove 'eshell-handle-ansi-color eshell-output-filter-functions)))

     ;; For compilation buffers
     (setq compilation-environment '("TERM=xterm-256color"))
     (defun my-advice-compilation-filter (f proc string)
	(funcall f proc
		 (if (eq major-mode 'rg-mode) ; compatible with `rg'
		     string
		   (xterm-color-filter string))))
     (advice-add 'compilation-filter :around #'my-advice-compilation-filter)
     (advice-add 'gud-filter :around #'my-advice-compilation-filter))

PROJECTILE

(use-package projectile
  :ensure t
  :config (projectile-mode t))

(use-package counsel-projectile
  :ensure t
  :config
  (counsel-projectile-mode)
  (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map))

ESHELL

   (setenv "PAGER" "cat")

   (use-package shrink-path
     :ensure t)

   (use-package esh-autosuggest
     :ensure t
     :hook (eshell-mode . esh-autosuggest-mode))

   (use-package exec-path-from-shell
     :ensure t
     :if (memq window-system '(mac ns))
     :config
     (exec-path-from-shell-initialize)
     (exec-path-from-shell-copy-env "LANG")
     (exec-path-from-shell-copy-env "LC_CTYPE")
     (exec-path-from-shell-copy-env "LC_NUMERIC")
     (exec-path-from-shell-copy-env "LC_ALL")
     (exec-path-from-shell-copy-env "HOME")
     (exec-path-from-shell-copy-env "PERSONAL_ACCESS_TOKEN"))

   (use-package eshell
     :config
     (setq
      eshell-banner-message "...\n"
      eshell-hist-ignoredups t
      eshell-error-if-no-glob t
      eshell-cmpl-ignore-case t
      eshell-save-history-on-exit t
      eshell-history-size 1024
      eshell-prefer-lisp-functions nil
      eshell-destroy-buffer-when-process-dies t
      eshell-scroll-to-bottom-on-input 'all))

   (use-package eshell-fringe-status
     :config
     (add-hook 'eshell-mode-hook 'eshell-fringe-status-mode))

   (defun git-get-current-branch ()
     "Get git branch in the current directory."
     (when (and (eshell-search-path "git") (locate-dominating-file (eshell/pwd) ".git"))
	(s-trim (shell-command-to-string (concat "git rev-parse --abbrev-ref HEAD")))))

   (defun display-git-prompt-branch ()
     "Displays the git in the prompt."
     (if (not (null (git-get-current-branch))) (concat "│" (git-get-current-branch)) ""))


   (defun get-first-char (str)
     "Get first character of string STR."
     (if (zerop (length str)) "" (substring str 0 1)))

   (defun fill-window-with-char ()
     "Fill the window width with one character acting as a line."
     (concat (make-string (- (window-body-width) 1) ? ) "\n"))

   (defun pwd-shorten-dirs (pwd)
     "Shorten all directory names in PWD except the last two."
     (let ((path-items (split-string pwd "/")))
	(if (> (length path-items) 2)
	    (concat
	     (mapconcat 'get-first-char (butlast path-items 2) "/")
	     "/"
	     (mapconcat (lambda (item) item) (last path-items 2) "/"))
	  pwd)))

  (setq eshell-prompt-function
    (lambda nil
      (concat
       (propertize (make-string (window-body-width) ?─) 'face '(:foreground "#234768"))
       (propertize "\n" 'face nil)
       (propertize "╭⟢ " 'face '(:foreground "#FFDDD8"))
       (propertize (user-login-name) 'face '(:foreground "#FF85728"))
       (propertize "@" 'face '(:foreground "#FB0320F"))
       (propertize (system-name) 'face '(:foreground "#FFDDD"))
       (propertize " " 'face nil)
       (propertize (display-git-prompt-branch) 'face '(:foreground "#F1F5F9")) ""
       (propertize "" 'face nil)
       (propertize (pwd-shorten-dirs (abbreviate-file-name (eshell/pwd)))
                   'face '(:foreground "#74CAFF"))
       (propertize "\n" 'face nil)
       (propertize "╰🡢" 'face '(:foreground "#FFDDD8"))
       (propertize " " 'face nil))))

   (setq eshell-highlight-prompt nil)

   ;; Set this to match eshell-prompt-function
   (setq eshell-prompt-regexp "^╰🡢 ")

FLYCHECK

(use-package flycheck
  :ensure t
  :hook ((prog-mode . flycheck-mode))
  :config
  (setq flycheck-highlighting-mode 'lines))

COMPANY

(use-package company
  :ensure t
  :config
  (global-company-mode t)
  (setq company-global-modes '(not eshell-mode))
  (define-key company-active-map (kbd "M-n") nil)
  (define-key company-active-map (kbd "M-p") nil)
  (define-key company-active-map (kbd "C-n") 'company-select-next)
  (define-key company-active-map (kbd "C-p") 'company-select-previous)
  (define-key company-active-map (kbd "TAB") 'company-complete)
  (define-key company-active-map (kbd "<tab>") 'company-complete))

(use-package company-flx
  :ensure t
  :config (company-flx-mode t))

LSP

   (defun get-dart-path ()
     (string-trim-right
      (car
	(seq-filter
	 (lambda (str) (string-match "dart" str))
	 (split-string (getenv "PATH") ":")))
      "/bin"))

   (use-package lsp-mode
     :ensure t
     :hook (
	     (sh-mode . lsp)
	     (python-mode . lsp)
	     (dart-mode . lsp)
	     (js2-mode . lsp))
     :config
     (setq lsp-prefer-flymake nil
	    lsp-dart-sdk-dir (get-dart-path)
	    lsp-enable-on-type-formatting nil
	    lsp-log-max 10000))

   (use-package lsp-ui
     :ensure t
     :requires lsp-mode flycheck
     :config
     (setq lsp-ui-sideline-enable t
	    lsp-ui-sideline-show-symbol nil)
     :hook (lsp-mode . lsp-ui-mode))

   (use-package company-lsp
     :ensure t
     :requires company
     :config
     (push 'company-lsp company-backends))

   (use-package yasnippet
     :ensure t
     :diminish yas-minor-mode
     :config
     (use-package yasnippet-snippets :ensure t)
     (yas-global-mode t))

LANGUAGE UTILS

(use-package smartparens
  :ensure t
  :config (progn (show-smartparens-global-mode t))
  :hook (prog-mode . turn-on-smartparens-mode))

;; (use-package rainbow-delimiters
;;   :ensure t
;;   :hook (prog-mode . rainbow-delimiters-mode))

(use-package highlight-indent-guides
  :ensure t
  :hook (prog-mode . highlight-indent-guides-mode)
  :custom
  (highlight-indent-guides-character ?\│)
  (highlight-indent-guides-auto-odd-face-perc 2)
  (highlight-indent-guides-auto-even-face-perc 2)
  (highlight-indent-guides-auto-character-face-perc 8)
  (highlight-indent-guides-method 'character)
  (highlight-indent-guides-responsive 'character)
  (highlight-indent-guides-delay 0))

LANGUAGES

CLOJURE

(use-package clojure-mode
  :ensure t
  :config (yas-global-mode t))

(use-package flycheck-joker
  :ensure t)

(use-package lsp-mode
  :ensure t
  :commands lsp
  :config
  (add-to-list 'lsp-language-id-configuration '(clojure-mode . "clojure-mode"))
  (add-to-list 'lsp-language-id-configuration '(clojurescript-mode . "clojure-mode"))
  :init
  (setq lsp-enable-indentation nil)
  (add-hook 'clojure-mode-hook #'lsp)
  (add-hook 'clojurec-mode-hook #'lsp)
  (add-hook 'clojurescript-mode-hook #'lsp))

PYTHON

(use-package lsp-python-ms
  :ensure t
  :config
  (add-to-list 'lsp-language-id-configuration '(python-mode . "python"))
  :hook (python-mode . (lambda () (require 'lsp-python-ms) (lsp))))

;; (use-package pyenv-mode :ensure t)

;; (use-package pyenv-mode-auto :ensure t)

;; (use-package blacken
;; :after python
;; :hook (python-mode . blacken-mode))

DART

   (defun flutter-lsp-save ()
     "Upgrade save in flutter to do formatting and hot-reload"
     (interactive)
     (lsp-format-buffer)
     (save-buffer)
     (if (flutter--running-p)
	   (flutter-hot-reload)))


   (use-package dart-mode
     :ensure t
     :config
     (add-to-list 'lsp-language-id-configuration '(dart-mode . "dart"))
     (with-eval-after-load "projectile"
	 (add-to-list 'projectile-project-root-files-bottom-up "pubspec.yaml")
	 (add-to-list 'projectile-project-root-files-bottom-up "build")))

   (use-package flutter
     :ensure t
     :after dart-mode
     ;; :custom (flutter-sdk-path "/Applications/flutter/")
     :bind (:map dart-mode-map ("C-x C-s" . #'flutter-lsp-save)))

LUA

(use-package lua-mode
  :ensure t)

GROOVY

(use-package groovy-mode
  :ensure t
  :mode "\\.groovy\\'\\|\\.gradle\\'")

RUST

(use-package toml-mode
  :ensure t)

(use-package rust-mode
  :ensure t
  :init
  (setq rust-format-on-save t)
  :hook (rust-mode . lsp))

(use-package cargo
  :ensure t
  :hook (rust-mode . cargo-minor-mode))

(use-package flycheck-rust
  :ensure t
  :after (rust-mode)
  :hook ((rust-mode . flycheck-rust-setup)
	      (flycheck-mode . flycheck-rust-setup)))

JAVASCRIPT

(use-package json-mode
  :ensure t
  :mode (("\\.json\\'" . json-mode)
	      ("\\.tmpl\\'" . json-mode)
	      ("\\.eslintrc\\'" . json-mode))
  :config (setq-default js-indent-level 2))

(use-package json-reformat
  :ensure t
  :after json-mode
  :bind (("C-c r" . json-reformat-region)))

(use-package js2-mode 
  :ensure t
  :mode "\\.js\\'"
  :config (setq js-indent-level 2)
  :hook (js2-mode . lsp))

(use-package prettier-js
  :ensure t
  :after js2-mode
  :init 
  (add-hook 'js2-mode-hook 'prettier-js-mode))
  (add-hook 'web-mode-hook 'prettier-js-mode)

CLI CLIENTS

GIT

   (use-package magit
     :ensure t
     :init (magit-auto-revert-mode -1)
     :bind ("C-x g" . magit-status))

   (if (display-graphic-p)
	 (use-package git-gutter-fringe
	   :ensure t
	   :init (global-git-gutter-mode))
     (use-package git-gutter
	 :ensure t
	 :init (global-git-gutter-mode)))

DOCKER

(use-package dockerfile-mode :ensure t)
(use-package docker-compose-mode :ensure t)
(use-package docker-tramp :ensure t)

CUSTOM.EL CONFIG FILE

  (add-hook
   'after-init-hook
   (lambda ()
     (let ((custom-file
	      (expand-file-name "custom.el" user-emacs-directory)))
	 (unless (file-exists-p custom-file)
	   (write-region "" "" custom-file))
	 (load custom-file))))

REDUCE GARBAGE COLLECTION

;; Make gc pauses faster by decreasing the threshold.
(setq gc-cons-threshold (* 16 1000 1000))