Skip to content

Instantly share code, notes, and snippets.

@dylan-sessler
Created August 24, 2022 19:01
Show Gist options
  • Save dylan-sessler/c6046ab2d69e7f61ccf4a918e2971b2d to your computer and use it in GitHub Desktop.
Save dylan-sessler/c6046ab2d69e7f61ccf4a918e2971b2d to your computer and use it in GitHub Desktop.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customizations set through customize-x workflow ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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-enabled-themes (quote (sanityinc-tomorrow-night)))
'(custom-safe-themes
(quote
("0ef45881430abc4d09bf62e3e3c06225735edd090e5b32f84808ec9829d371f6" "c10cb7942e036c177a63dd3c42fcf964b1caee538c524a6441b8871da43b2e00" "09b6b0fcc8ac9c6ee8f60fd033d7e0f3022363cc2581fe1e92d468e807d57383" "89f67f468a5c5654742b4cc3bd45b6eb3b423e7d4dc12668844881b68c9c0836" "06f0b439b62164c6f8f84fdda32b62fb50b6d00e8b01c2208e55543a6337433a" default)))
'(package-selected-packages
(quote
(git-gutter-fringe helm-ag rainbow-mode treemacs-projectile treemacs yaml-mode yagist xclip which-key web-mode use-package undo-tree tern-auto-complete term-keys smartparens slime rjsx-mode rainbow-delimiters pdf-tools org-download monokai-theme lsp-ui load-theme-buffer-local json-mode js2-refactor helm-projectile gist expand-region evil-surround emojify elpy diff-hl command-log-mode color-theme-sanityinc-tomorrow color-theme-buffer-local centaur-tabs all-the-icons ac-js2))))
(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.
'(centaur-tabs-selected-modified ((t (:foreground "#51afef"))))
'(centaur-tabs-unselected-modified ((t (:background "#21242b" :foreground "#51afef"))))
'(doom-modeline-buffer-modified ((t (:inherit bold :foreground "#51afef"))))
'(js2-object-property-access ((t nil))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;
;; Packages ;;
;;;;;;;;;;;;;;
(progn
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(package-initialize)
) ;; Package.el setup
(progn
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
(require 'bind-key)
) ;; use-package setup
(use-package evil
:ensure t
:init
;; Enable evil keybindings in the minibuffer, must be before evil is loaded
(setq evil-want-minibuffer t)
(evil-mode 1)
;; Whenever using evil-mode, add turn on undo-tree-mode to get working undo/redo behavior
(use-package undo-tree
:ensure t ;;installs the package if it is not already on your machine
:config ;; Executes code after a package is loaded
(global-undo-tree-mode)
)
:custom
(evil-auto-indent nil "don't auto indent when 'l'")
(evil-emacs-state-modes nil "make evil normal state the initial state always")
(evil-insert-state-modes nil "make evil normal state the initial state always")
(evil-motion-state-modes nil "make evil normal state the initial state always")
(evil-shift-width 2)
(evil-undo-system (quote undo-tree))
:bind (
:map evil-motion-state-map
;;;;; BASE BINDINGS ;;;;;
("y" . evil-previous-visual-line)
("n" . evil-next-visual-line)
("o" . evil-backward-char)
("h" . evil-forward-char)
("k" . clipboard-kill-ring-save)
("<home>" . beginning-of-line)
("<select>" . end-of-line) ; select is the end key in emacs
;;;;; ALT BINDINGS ;;;;;
("M-c" . comment-dwim)
("M-b" . comment-box)
("M-i" . indent-region)
("M-e" . other-window)
("M-d" . other-window)
("M-j" . evil-join) ; kind of like an inverse return in that it slurps a newline
;;;;; CTRL OPERATORS ;;;;;
("C-r" . revert-buffer)
("C-y" . evil-redo)
("C-z" . evil-undo)
("C-f" . evil-search-forward) ; C+f to search just like on the web
("C-h" . backward-kill-word) ; so that ctrl+backspace deletes words
("C-w" . evil-delete-buffer) ; kill current buffer
("C-v" . clipboard-yank)
("C-n" . evil-force-normal-state)
;;;;; SPC COMMANDS ;;;;;
("SPC" . nil) ; nil-ing this out so that my SPC keybindings work
;; Saving
("SPC s s" . save-buffer)
("SPC s q" . save-buffers-kill-emacs)
;; Line stuff, maybe delete if I ever need room
("SPC l" . newline) ; useful when converting emacs notes -> anki cards
;; Code folding and narrowing
("SPC f f" . folding-everywhere) ; Code folding basic
("SPC f h" . global-hide-everywhere) ; Code folding basic
("SPC f s" . global-show-everywhere) ; Code folding basic
("SPC f z" . narrow-or-widen-dwim)
;; Jumping
("SPC j j" . evil-jump-backward) ; default action is to jump backwards but can go forward as well
("SPC j p" . evil-jump-backward)
("SPC j n" . evil-jump-forward)
;; Evaluate
("SPC e f" . eval-defun)
("SPC e e" . eval-expression)
;; Working with outlines
("SPC h u" . outline-up-heading)
("SPC h n" . outline-next-visible-heading)
("SPC h y" . outline-previous-visible-heading)
;;;;; NILS ;;;;;
("TAB" . nil) ;; Don't shadow tab for auto-complete
("<tab>" . nil)
;;;;; CTRL NILS ;;;;;
("C-z" . nil) ; Turn off emacs state
("C-x C-z" . nil)
("C-x m" . nil)
("C-M-h" . nil) ; old help command
:map evil-normal-state-map
;;;;; BASE BINDINGS ;;;;;
("y" . evil-previous-visual-line)
("Y" . move-5-up)
("n" . evil-next-visual-line)
("N" . move-5-down)
("o" . evil-backward-char)
("h" . evil-forward-char)
("l" . evil-open-below)
("L" . evil-open-above)
("j" . evil-search-next)
("J" . evil-search-previous)
;;;;; CTRL BINDINGS ;;;;;
("C-r" . revert-buffer)
("C-b" . evil-visual-block)
("C-n" . evil-force-normal-state)
("C-v" . clipboard-yank)
("C-q" . evil-record-macro)
;;;;; META BINDINGS ;;;;;
("M-y" . meta-up-dwim)
("M-n" . meta-down-dwim)
;;;;; NILS ;;;;;
("q" . nil) ; to be able to q out of pop-ups
("M-." . nil) ; un-mask xref-find-definitions
("C-z" . nil) ; turn off emacs mode
:map evil-visual-state-map
;;;;; BASE BINDINGS ;;;;;
("y" . evil-previous-visual-line)
("n" . evil-next-visual-line)
("Y" . move-5-up) ; No clue why this doesn't work in visual line mode
("N" . move-5-down) ; No clue why this doesn't work in visual line mode
("o" . evil-backward-char)
("h" . evil-forward-char)
("k" . clipboard-kill-ring-save)
("$" . end-of-line-dwim)
;;;;; ADDITIONAL BINDINGS ;;;;;
("C-n" . evil-force-normal-state)
;;;;; NILS ;;;;;
("C-z" . nil) ; turn off emacs mode
:map evil-insert-state-map
("<select>" . end-of-line) ; <select> is what the terminal interprets as END
("M-j" . evil-join) ; kind of like an inverse return in that it slurps a newline
;;;;; CTRL BINDINGS ;;;;;
("C-r" . revert-buffer)
("C-y" . evil-redo)
("C-z" . evil-undo)
("C-h" . backward-kill-word) ; so that ctrl+backspace deletes words
("C-v" . clipboard-yank)
("C-n" . evil-force-normal-state)
("C-z" . nil) ; Turn off emacs state switching
:map evil-operator-state-map
("C-n" . evil-force-normal-state)
("C-z" . nil) ; Turn off emacs state switching
:map evil-replace-state-map
("C-n" . evil-force-normal-state)
("C-z" . nil) ; Turn off frame suspension
)
)
(use-package org
:ensure t
:custom
;; for exporting pretty powerpoints from org-mode
(user-full-name "Dylan Sessler")
(org-export-with-toc nil)
(org-export-with-sub-superscripts nil)
(org-insert-mode-line-in-empty-file 1) ; If call org-mode on a file auto-set the file for future opens
(org-emphasis-alist
(quote
(("*" bold)
("/" italic)
("" underline)
("=" org-verbatim verbatim)
("~" org-code verbatim)
("+"
(:strike-through t)))))
(org-support-shift-select (quote always))
:config
(use-package org-download
;; Allows me to insert images in org-mode!
:ensure t ;;installs the package if it is not already on your machine
:custom ;; The :custom keyword allows customization of package custom variables.
(org-download-image-dir "/home/dylan/Pictures/org-mode-images")
(org-download-abbreviate-filename-function 'expand-file-name)
(org-display-inline-images)
)
(set 'org-todo-keywords '((sequence "TODO(t)" "WAITING(w)" "NEXT(n)" "ACTIVE(a)" "|" "DONE(d)")))
(set 'org-log-done 'time)
(set 'org-export-backends (quote (beamer html latex)))
:bind (
:map evil-motion-state-map
("SPC o l" . org-store-link)
("SPC o a" . org-agenda)
("SPC o c" . org-capture)
("SPC o o" . org-open-at-point-global)
:map org-mode-map
("C-a" . nil) ; to prevent select all masking in org-mode
("<S-iso-lefttab>" . nil) ; to prevent yas-prev-field masking in org-mode
("C-c f" . org-match-sparse-tree) ; for filtering based on tags in task management system
("C-c p" . org-export-dispatch) ; Like printing
("C-c t" . org-todo) ; Needs to be here so it doesn't prevent me from entering SPC!
("C-c r" . org-refile) ; This is almost exclusively done on TODOs, so makes sense here
("C-c k" . org-insert-link)
("C-c v" . org-download-clipboard)
("C-c o" . org-open-at-point)
("C-c u" . outline-up-heading)
("M-h" . org-metaright)
("M-H" . org-shiftmetaright)
("M-o" . org-metaleft)
("M-O" . org-shiftmetaleft) ; MAYBE blocks use of arrow keys in org-mode
)
)
(use-package helm
:ensure t
:init
(helm-mode 1)
:config
(use-package projectile
:ensure t ;;installs the package if it is not already on your machine
:init ;; Executes code before a package is loaded AND IS ALWAYS RUN
(projectile-global-mode)
:custom ;; The :custom keyword allows customization of package custom variables.
(setprojectile-completion-system 'helm)
(projectile-switch-project-action 'helm-projectile) ; Allows you to open files in other projects without leaving current project
)
(helm-projectile-on)
:custom
(helm-M-x-fuzzy-match t "optional fuzzy matching for helm-M-x")
(helm-buffers-fuzzy-matching t)
(helm-recentf-fuzzy-match t)
:bind
(
("M-x" . helm-M-x) ; replace M-x with helm way
("C-x b" . helm-mini) ; replace buffer switching with helm way
("C-g" . helm-keyboard-quit)
("<C-backspace>" . backward-kill-word)
:map helm-find-files-map
("<C-backspace>" . helm-find-files-up-one-level)
:map evil-normal-state-map
("C-o" . helm-find-files)
("C-t" . helm-projectile) ; Open a new tab by searching for files using helm + projectile
:map evil-insert-state-map
("C-o" . helm-find-files)
("C-t" . helm-projectile) ; Open a new tab by searching for files using helm + projectile
)
)
(use-package yasnippet
;; SNIPPETS
:ensure t ;;installs the package if it is not already on your machine
:init
(yas-global-mode 1)
:custom
(yas-new-snippet-default nil "Makes new snippets empty")
:bind
(
:map yas/keymap
("C-d" . nil) ; null out C-d so that my tab navigation doesn't break
:map evil-motion-state-map
("SPC y e" . yas-visit-snippet-file)
("SPC y n" . yas-new-snippet)
("SPC y a" . yas-new-snippet) ; redundant as an alias
("SPC y y" . yas-describe-tables) ; default behavior should be to look at available snippets
("SPC y d" . yas-describe-tables) ; alias for describe tables
("SPC y r" . yas-reload-all) ; For some reason this produces an error. You need to define it here or you get SPC eaten
)
)
(use-package which-key
:ensure t
:config (which-key-mode)
)
(use-package company
:ensure t ;;installs the package if it is not already on your machine
:hook (prog-mode . company-mode)
:custom(
(company-minimum-prefix-length 1 "So company starts suggesting options right away")
(company-idle-delay 0.6 "trying to make this long enough so it doesn't try to complete before I can fire off a snippet")
(company-dabbrev-downcase nil "when working with a case-sensitive lang you really want to preserve the case-sensitivity on completions")
(company-dabbrev-ignore-case nil "when working with a case-sensitive lang you really want to preserve the case-sensitivity on completions")
)
:bind
(
:map company-active-map
;; ("TAB" . nil) ; TAB is for yasnippet - don't shadow it.
;; ("<tab>" . nil) ; TAB is for yasnippet - don't shadow it.
("TAB" . yas-next-field-or-maybe-expand) ; TAB is for yasnippet - don't shadow it.
("<tab>" . yas-next-field-or-maybe-expand) ; TAB is for yasnippet - don't shadow it.
("M-r" . company-show-doc-buffer)
("ESC" . company-abort)
:map evil-motion-state-map
("C-SPC" . company-complete) ; Manually ask for auto-complete mode
("M-r" . company-show-doc-buffer) ; Manually ask for auto-complete mode
:map evil-normal-state-map
("C-SPC" . company-complete) ; Manually ask for auto-complete mode
("M-r" . company-show-doc-buffer) ; Manually ask for auto-complete mode
:map evil-insert-state-map
("C-SPC" . company-complete) ; Manually ask for auto-complete mode
("M-r" . company-show-doc-buffer) ; Manually ask for auto-complete mode
)
)
(use-package rjsx-mode
:ensure t ;;install
:config ;; Executes code after a package is loaded
(add-to-list 'auto-mode-alist '("components/*.js" . rjsx-mode))
(add-to-list 'auto-mode-alist '("Components/*.js" . rjsx-mode))
:bind ;; Binds keys to global keymap and takes a cons or a list of conses
("C-c j" . rjsx-jump-tag)
(
:map evil-motion-state-map
("SPC j t" . rjsx-jump-tag)
)
)
(use-package slime
:ensure t ;;installs the package if it is not already on your machine
:init ;; Executes code before a package is loaded
;; Require Common Lisp Libraries
;; (Used in SLIME functions)
(require 'cl-lib)
;; Makes slime the default lisp program
;; https://lisp-lang.org/learn/getting-started/
(setq inferior-lisp-program "sbcl")
:bind ;; Binds keys to global keymap and takes a cons or a list of conses
("C-l" . slime-repl-clear-buffer)
:custom
(slime-load-failed-fasl 'never)
)
(use-package emojify
:custom
(emojify-composed-text-p nil)
:hook (after-init . global-emojify-mode)
)
(use-package evil-surround
:ensure t
:config
(global-evil-surround-mode 1)
:custom
(evil-surround-pairs-alist
(quote
((40 "(" . ")")
(91 "[" . "]")
(123 "{" . "}")
(41 "(" . ")")
(93 "[" . "]")
(125 "{" . "}")
(35 "#{" . "}")
(98 "(" . ")")
(66 "{" . "}")
(62 "<" . ">")
(116 . evil-surround-read-tag)
(60 . evil-surround-read-tag)
(102 . evil-surround-function)))
"removes default extra space around the parens and brackets")
)
(use-package pdf-tools
:ensure t ;;installs the package if it is not already on your machine
:init ;; Executes code before a package is loaded
(pdf-loader-install)
:config ;; Executes code after a package is loaded
(define-key pdf-view-mode-map [remap evil-next-visual-line] 'pdf-view-next-line-or-next-page)
(define-key pdf-view-mode-map [remap evil-previous-visual-line] 'pdf-view-previous-line-or-previous-page)
(define-key pdf-view-mode-map [remap fast-scroll-down] 'pdf-view-next-page)
(define-key pdf-view-mode-map [remap fast-scroll-up] 'pdf-view-previous-page)
(define-key pdf-view-mode-map [remap evil-previous-line-first-non-blank] 'pdf-view-shrink)
(define-key pdf-view-mode-map [remap evil-next-line-first-non-blank] 'pdf-view-enlarge)
)
(use-package expand-region
:ensure t ;;installs the package if it is not already on your machine
:bind (
:map evil-normal-state-map
("M-w" . er/expand-region)
("M-s" . er/contract-region)
)
)
(use-package js2-mode
:ensure t ;;installs the package if it is not already on your machine
:init ;; Executes code before a package is loaded AND IS ALWAYS RUN
(add-to-list 'auto-mode-alist '(".*\.js$" . js2-mode))
:config
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(use-package js2-refactor
:ensure t ;;installs the package if it is not already on your machine
:bind
(:map evil-motion-state-map
("SPC r e e" . js2r-expand-node-at-point)
("SPC r c c" . js2r-contract-node-at-point)
("SPC r e f" . js2r-extract-function) ; not currently working for some reason
("SPC r t f" . js2r-toggle-function-expression-and-declaration)
("SPC r t a" . js2r-toggle-arrow-function-and-expression)
)
)
:bind (
:map evil-normal-state-map
("SPC j d" . js2-jump-to-definition)
)
:custom
(js-indent-align-list-continuation nil)
(js-indent-level 2)
(js2-highlight-level 3)
(js2-include-node-externs t)
(js2-missing-semi-one-line-override t)
(js2-strict-missing-semi-warning nil)
:custom-face
;; (js2-error ((t (:underline "#cc6666"))))
;; (js2-warning ((t nil)))
(js2-object-property-access ((t nil)))
)
(use-package yagist
:ensure t ;;installs the package if it is not already on your machine
:custom ;; The :custom keyword allows customization of package custom variables.
(yagist-github-token "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")
)
(use-package rainbow-delimiters
:ensure t ;;installs the package if it is not already on your machine
:hook (prog-mode . rainbow-delimiters-mode)
)
(use-package command-log-mode
:ensure t ;;installs the package if it is not already on your machine
)
(use-package xclip
;; integrate clipboard with x11 clipboard
:ensure t ;;installs the package if it is not already on your machine
:init ;; Executes code before a package is loaded AND IS ALWAYS RUN
(xclip-mode 1)
:custom ;; The :custom keyword allows customization of package custom variables.
(x-select-enable-clipboard t)
)
(use-package doom-modeline
:ensure t ;;installs the package if it is not already on your machine
:custom
(doom-modeline-buffer-encoding (quote nondefault) "only show buffer encoding (eg. UTF-8), when non default")
(doom-modeline-buffer-file-name-style (quote relative-from-project) "Shows project root and everything after")
(doom-modeline-buffer-modification-icon nil "don't show the save icon")
(doom-modeline-continuous-word-count-modes nil "no need for word count on modeline")
(doom-modeline-vcs-max-length 100 "So I can see the full name of the git branch I'm on")
:custom-face
(doom-modeline-buffer-modified ((t (:inherit bold :foreground "#51afef"))))
:hook (after-init . doom-modeline-mode)
)
(use-package hl-todo
;; highlights todo text
:ensure t ;;installs the package if it is not already on your machine
:init
(global-hl-todo-mode 1)
)
(use-package treemacs
:ensure t
:config
(use-package treemacs-projectile
:after treemacs projectile
:ensure t)
)
;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;; Other config ;;
;;;;;;;;;;;;;;;;;;
(progn
;; Run ispell before each save in contexts where I am not writing code.
;; If you run into modes that you don't want to save, just add a short-circuit
;; cond statement!
(add-hook 'before-save-hook '(lambda ()
(cond ((derived-mode-p 'prog-mode) nil)
((derived-mode-p 'conf-mode) nil)
((derived-mode-p 'yaml-mode) nil)
((string-match-p "addp-hunk-edit.diff" buffer-file-name) nil)
((string-match-p ".env" buffer-file-name) nil)
((string-match-p ".json" buffer-file-name) nil)
((string-match-p ".pdf" buffer-file-name) nil)
(t (ispell)))))
;; Custom ispell region skips so that I don't pull my hair out with false positives.
;; Something really important to note here is that the skips happen
;; sequentially to how they are registered on the alist. So whatever we register
;; last will be run first! This effectively removes regions from the file to be
;; ispelled, so it is important that we don't introduce any rules that could
;; sabotage other rules! Eg. if I had a rule to skip any ~...~ regions and I
;; had an unbalanced ~ somewhere in the file it would fuck up the skipping for
;; that rule as well as any regions that skip after! If you are running into
;; weirdness where rules aren't executing as expected you likely have a bad
;; regex for a rule. You can easily troubleshoot this by going to your file and
;; using either the re-builder or re-search-forward commands.
;; Don't spell-check words 35 chars or over like git sha1s
;;(this may interere with long urls so make sure this is lower in alist)
(add-to-list 'ispell-skip-region-alist '("\\b\\w\\{35,\\}\\b"))
;; Don't spell-check org-definition lines
;; (may be masking over the BEGIN_SRC and END_SRC blocks so make sure this is lower in alist)
(add-to-list 'ispell-skip-region-alist '("#\\+.+$"))
(add-to-list 'ispell-skip-region-alist '("[[:space:]^]:[^[:space:]]+")) ; Don't spell check :definitions
; Don't spell-check in-line code snippets. The ? is to make the .+ not greedy
; for cases where you have multiple inline code snippets on the same line
(add-to-list 'ispell-skip-region-alist '("~.+?~"))
(add-to-list 'ispell-skip-region-alist '("[^[:space:]]+\\.[^[:space:]]+")) ; Don't spell-check word with a '.' in it
(add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_SRC" . "^#\\+END_SRC")) ; Don't spell-check within source blocks
;; The default ispell program in emacs is aspell, which is a command line
;; utility. One of aspell's options is --camel-case which enables support for
;; camelCase spell checking.
;; This also works for PascalCase which is awesome!
(setq ispell-extra-args '("--camel-case"))
) ;; Ispell config
(progn
(global-set-key (kbd "C-M-h") 'help-command) ; needs to be in global - maybe for the rest of its bindings?
(global-set-key (kbd "C-M-h a") 'helm-apropos) ; much better apropro and needs to be linked to the same root as the help-command
(global-set-key (kbd "C-a") 'mark-whole-buffer)
(global-set-key (kbd "C-s") 'save-buffer)
(global-set-key (kbd "C-z") 'evil-undo)
) ;; Global keybindings
(progn
(menu-bar-mode -1) ; turns off the emacs menu bar
(tool-bar-mode -1) ; turns off the emacs tool bar
(scroll-bar-mode -1) ; turns off the emacs scroll bar
(electric-pair-mode) ;; Auto-pair brackets
) ;; Turn on and off modes
(progn
(setq inhibit-splash-screen t) ; turns off the annoying emacs splash screen
(set 'same-window-regexps '("*")) ;; Make all buffer pop-ups open in the same window
;; register major modes with specific file types
(add-to-list 'auto-mode-alist '(".bash" . sh-mode))
(add-to-list 'auto-mode-alist '(".env" . sh-mode))
(add-to-list 'auto-mode-alist '("emacs" . emacs-lisp-mode))
(add-to-list 'auto-mode-alist '(".psqlrc" . sql-mode))
;; auto-save backups to a single directory
(setq backup-directory-alist
`((".*" . ,(concat user-emacs-directory "backups/"))))
(setq auto-save-file-name-transforms
`((".*" ,(concat user-emacs-directory "backups/") t)))
(setq hs-hide-comments-when-hiding-all nil) ;; Don't fold comments on global folds
(setq css-indent-offset 2) ;; css mode offset
(setq vc-follow-symlinks nil) ;; don't prompt to go to the root file every time
) ;; Set variables and UI customization
(progn
(defun config ()
"Open the config file for emacs"
(interactive)
(find-file "~/.emacs"))
(defun set-fill-column ()
(cond ((string-match-p "COMMIT" buffer-file-name) ; Regex to match on git commit buffers to get the right reflow
(setq fill-column 72))
(t
(setq fill-column 80))) ; general case
)
(defun narrow-or-widen-dwim ()
"If the buffer is narrowed, it widens. Otherwise, it narrows to region, or Org subtree."
(interactive)
(cond ((buffer-narrowed-p) (widen))
((region-active-p) (narrow-to-region (region-beginning) (region-end)))
((equal major-mode 'org-mode) (org-narrow-to-subtree))
(t (error "Please select a region to narrow to"))))
(defun meta-up-dwim ()
(interactive)
(cond
((equal major-mode 'org-mode) ( org-metaup ))
(t (execute-kbd-macro (symbol-function 'move-line-up)))))
(defun meta-down-dwim ()
(interactive)
(cond
((equal major-mode 'org-mode) (org-metadown))
(t (execute-kbd-macro (symbol-function 'move-line-down)))))
(defun unfill-paragraph (&optional region)
"Takes a multi-line paragraph and makes it into a single line of text.
I use this all the time when translating from emacs ⇒ Anki"
(interactive (progn (barf-if-buffer-read-only) '(t)))
(let ((fill-column (point-max))
;; This would override `fill-column' if it's an integer.
(emacs-lisp-docstring-fill-column t))
(fill-paragraph nil region)))
(defun archive ()
"archive the subtree to the standard location"
(interactive)
(org-archive-subtree-default)) ;; Unsed when cleaning out org-mode files of done tasks
(defun archive-all-done-subtree ()
(interactive)
(org-map-entries
(lambda ()
(org-archive-subtree)
(setq org-map-continue-from (org-element-property :begin (org-element-at-point))))
"/DONE" 'tree))
(defun command-log ()
"enables the command log minor mode and opens a buffer to display it's output
http://ergoemacs.org/emacs/emacs_show_key_and_command.html"
(interactive)
(command-log-mode)
(global-command-log-mode)
(clm/open-command-log-buffer))
;; Sensible code folding with hide-show
(defun toggle-fold ()
"Sensible code folding with hide-show. Makes it so if you're at the beinning
of a line when you go to toggle hiding you move to the end of the line (putting
yourself in the block on that line) before folding. This make more sense
intuitively."
(interactive)
(save-excursion
(end-of-line)
(hs-toggle-hiding)))
(defun folding-everywhere ()
(interactive)
(cond
((equal mode-name "Org") (org-cycle))
(t (toggle-fold))))
(defun global-hide-everywhere ()
(interactive)
(cond
((equal mode-name "Org") (org-overview))
(t (hs-hide-all))))
(defun global-show-everywhere ()
(interactive)
(cond
((equal mode-name "Org")
( outline-show-all ))
(t (hs-show-all))))
) ;; User defined functions
(progn
(add-hook 'text-mode-hook 'auto-fill-mode) ;; Turn on auto-fill mode on all text-mode derived buffers
(add-hook 'find-file-hook 'set-fill-column) ;; Determine the fill-column var after visiting a file
;; So Emacs doesn't create lockfiles while working on any programming files
;; This makes it so the test-runner doesn't re-run
(add-hook 'prog-mode-hook (lambda () (setq create-lockfiles nil)))
;; Hooks for setting the evil shift width to mode-driven amount
(add-hook 'python-mode-hook
(function (lambda ()
(setq evil-shift-width python-indent))))
(add-hook 'js-mode-hook
(function (lambda ()
(setq evil-shift-width js-indent-level))))
(add-hook 'css-mode-hook
(function (lambda ()
(setq evil-shift-width css-indent-offset))))
(add-hook 'prog-mode-hook 'hs-minor-mode) ;;; Enable hide-show minor mode
;; hooks for auto-hiding all on file open
(add-hook 'projectile-find-file-hook 'hs-hide-all)
(add-hook 'find-file-hook 'hs-hide-all)
(add-hook 'before-save-hook 'delete-trailing-whitespace) ;; Delete all trailing whitespace on file save
;; When opening multiple files from a script only open in a single window
;; Basically makes it so that when a new window tries to spawn it gets killed
(add-hook 'window-setup-hook 'delete-other-windows)
) ;; Hooks
(progn
(fset 'end-of-line-dwim
[?\M-x ?e ?n ?d ?- ?o ?f ?- ?l ?i ?n ?e return])
(fset 'move-line-up
[?d ?d ?y ?L ?\C-v ?\C-n ?d ?d ?y])
(fset 'move-line-down
[?d ?d ?l ?\C-v ?\C-n ?d ?d ?y])
(fset 'move-5-up
[?y ?y ?y ?y ?y])
(fset 'move-5-down
[?n ?n ?n ?n ?n])
) ;; Macros
(if window-system
(progn
(use-package doom-themes
:ensure t
:config
(load-theme 'my-doom-one)
;; Enable flashing mode-line on errors
(doom-themes-visual-bell-config)
;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config)
:custom
(doom-themes-enable-bold t "if nil, bold is universally disabled")
(doom-themes-enable-italic t "if nil, italics is universally disabled")
)
;; TABS
;; Icons for tabs to make it a little more obvious where your files are
(use-package all-the-icons :ensure t)
;; May need to run `M-x all-the-icons-install-fonts` on a new machine to get this to work
(use-package centaur-tabs
:init
(centaur-tabs-mode t) ;; always be in centaur-tabs-mode
:ensure t
:custom
(centaur-tabs-set-icons t "turn on icons from all-the-icons")
(centaur-tabs-set-close-button nil "get rid of the close tab mouse UI")
(centaur-tabs-show-new-tab-button nil "get rid of new tab mouse UI")
(centaur-tabs-set-modified-marker t "adds a marker to modified files")
(centaur-tabs-modified-marker "+" "makes the modified marker a + sign")
(centaur-tabs-cycle-scope 'tabs)
:custom-face
(centaur-tabs-selected-modified ((t (:foreground "#51afef"))))
(centaur-tabs-unselected-modified ((t (:background "#21242b" :foreground "#51afef"))))
:config
(defun centaur-tabs-buffer-groups ()
"`centaur-tabs-buffer-groups' control buffers' group rules."
(list (cond ((string-equal "*" (substring (buffer-name) 0 1)) "emacs")
((eq major-mode 'dired-mode) "emacs")
((string-equal "*terminal*" (buffer-name)) "user")
(t "user")
(centaur-tabs-get-group-name (current-buffer)))))
:bind (("C-l" . centaur-tabs--copy-file-name-to-clipboard)
:map evil-motion-state-map
("C-d" . centaur-tabs-backward)
("C-e" . centaur-tabs-forward)
("C-M-d" . centaur-tabs-move-current-tab-to-left)
("C-M-e" . centaur-tabs-move-current-tab-to-right)
("SPC C-e" . centaur-tabs-forward-group) ; Cycle groups
:map evil-insert-state-map
("C-d" . centaur-tabs-backward)
("C-e" . centaur-tabs-forward)
("C-M-d" . centaur-tabs-move-current-tab-to-left)
("C-M-e" . centaur-tabs-move-current-tab-to-right)
)
))
(progn
(use-package color-theme-sanityinc-tomorrow
:ensure t
:config
(color-theme-sanityinc-tomorrow-night)
)
)
) ;; GUI vs terminal settings
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; New stuff to be put in the right spot after I know it works ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (use-package lsp-mode
;; :hook ((js2-mode) . lsp-deferred)
;; :custom
;; (lsp-headerline-breadcrumb-enable nil "Prevents feature breaking centaur tabs. Not sure what breadcrumbs do.")
;; :commands lsp
;; :bind (:map evil-motion-state-map
;; ("SPC j d" . lsp-find-definition)
;; ("SPC j r" . lsp-find-references)
;; ("SPC r r v" . lsp-rename)
;; )
;; )
;; (use-package lsp-ui
;; :commands lsp-ui-mode
;; :config
;; ;; (setq lsp-ui-doc-enable nil)
;; ;; (setq lsp-ui-doc-header t)
;; ;; (setq lsp-ui-doc-include-signature t)
;; ;; (setq lsp-ui-doc-border (face-foreground 'default))
;; ;; (setq lsp-ui-sideline-show-code-actions t)
;; ;; (setq lsp-ui-sideline-delay 0.05)
;; )
;;; LSP-mode for fancy static analysis and UI https://emacs-lsp.github.io/lsp-mode/
;; (use-package lsp-mode :ensure t)
;; (use-package lsp-ui :ensure t)
;; (use-package dash :ensure t)
;; (add-hook 'js2-mode-hook #'lsp)
;; (use-package auto-complete
;; :ensure t ;;installs the package if it is not already on your machine
;; :init ;; Executes code before a package is loaded AND IS ALWAYS RUN
;; (ac-config-default) ;; Optimizes sources for auto-complete
;; :custom
;; (ac-auto-start nil)
;; :bind
;; (
;; :map evil-motion-state-map
;; ("C-SPC" . ac-start) ; Manually ask for auto-complete mode
;; ("<backtab>" . ac-start) ; Manually ask for auto-complete mode
;; :map evil-normal-state-map
;; ("C-SPC" . ac-start) ; Manually ask for auto-complete mode
;; ("<backtab>" . ac-start) ; Manually ask for auto-complete mode
;; :map evil-insert-state-map
;; ("C-SPC" . ac-start) ; Manually ask for auto-complete mode
;; ("<backtab>" . ac-start) ; Manually ask for auto-complete mode
;; )
;; )
(use-package rainbow-mode
:ensure t ;;installs the package if it is not already on your machine
:hook (prog-mode . rainbow-mode)
)
(use-package helm-ag
:ensure t ;;installs the package if it is not already on your machine
:bind
("C-S-f" . helm-projectile-ag)
)
;;; https://ianyepan.github.io/posts/emacs-git-gutter/
;;; not working atm due to missing fxn
;; (use-package git-gutter
;; :ensure t
;; :hook (prog-mode . git-gutter-mode)
;; :config
;; (setq git-gutter:update-interval 0.02)
;; )
;; (use-package git-gutter-fringe
;; :ensure t
;; :config
;; (define-fringe-bitmap 'git-gutter-fr:added [224] nil nil '(center repeated))
;; (define-fringe-bitmap 'git-gutter-fr:modified [224] nil nil '(center repeated))
;; (define-fringe-bitmap 'git-gutter-fr:deleted [128 192 224 240] nil nil 'bottom)
;; )
;; (use-package tern
;; :ensure t ;;installs the package if it is not already on your machine
;; :init
;; (add-hook 'js-mode-hook (lambda () (tern-mode t)))
;; :config
;; (use-package tern-auto-complete :ensure t)
;; (tern-ac-setup)
;; ;; Sometimes when you have just added .tern-project file or edit the file but
;; ;; Tern does not auto reload, you need to manually kill Tern server. This
;; ;; little piece of code does the trick.
;; (defun delete-tern-process ()
;; (interactive)
;; (delete-process "Tern"))
;; :bind (:map evil-motion-state-map
;; ("SPC j d" . tern-find-definition)
;; ("SPC j f" . tern-pop-find-definition)
;; ("SPC r r v" . tern-rename-variable)
;; )
;; )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment