Skip to content

Latest commit

 

History

History
816 lines (775 loc) · 27.5 KB

Emacs.org

File metadata and controls

816 lines (775 loc) · 27.5 KB

Emacs

use-package

Check if use-package is installed and always ensure t.

(require 'use-package-ensure)
(setq use-package-always-ensure nil)

Defaults

Variables

(setq org-directory "~/.org/")
(setq config-directory "~/.emacs.d/")

Open Files From Home Directory

When opening a file, start searching at the user’s home directory.

(setq default-directory "~/")

Increase GC Threshold

Allow 20MB of memory (instead of 0.76MB) before calling garbage collection. This means GC runs less often, which speeds up some operations.

(setq gc-cons-threshold 2000000000)

Single Space After Periods

WTF?

(setq sentence-end-double-space nil)

Ensure That Files End With Newline

If you save a file that doesn’t end with a newline, automatically append one.

(setq require-final-newline t)

Make Dired File Sizes Human Readable

Add file sizes in human-readable units (KB, MB, etc) to dired buffers.

(setq-default dired-listing-switches "-alh")

Shorten Yes Or No

Don’t ask `yes/no?’, ask `y/n?’.

(fset 'yes-or-no-p 'y-or-n-p)

Always Highlight Code

Turn on syntax highlighting whenever possible.

(global-font-lock-mode t)

Set Default Line Length To 80

(setq-default fill-column 80)

Packages

Evil

Evil is an extensible vi layer for Emacs. It provides Vim features like Visual selection and text objects, and is the successor to the now-obsolete Vimpulse and vim-mode.

(use-package evil
  :init
  (setq evil-want-abbrev-expand-on-insert-exit nil
        evil-want-keybinding nil)
  :hook
  (add-hook 'git-commit-mode-hook 'evil-insert-state)
  :config
  (evil-mode 1)
  (evil-define-key 'normal 'global (kbd "<RET>") 'org-ctrl-c-ctrl-c)
  (evil-define-key 'normal ‘global “gd” ’dumb-jump-go)
  (setq-default evil-kill-on-visual-paste nil)
  (evil-set-undo-system 'undo-tree))

Evil Collection

This is a collection of Evil bindings for the parts of Emacs that Evil does not cover properly by default, such as help-mode, M-x calendar, Eshell and more.

(use-package evil-collection
  :after evil
  :config
  (evil-collection-init))

Evil Org

(use-package evil-org
  :after org
  :config
  (add-hook 'org-mode-hook 'evil-org-mode)
  (add-hook 'evil-org-mode-hook
            (lambda () (evil-org-set-key-theme)))
  (require 'evil-org-agenda)
  (evil-org-agenda-set-keys))

Evil Leader

Evil Leader provides the <leader> feature from Vim that provides an easy way to bind keys under a variable prefix key. For an experienced Emacs User it is nothing more than a convoluted key map, but for a Evil user coming from Vim it means an easier start.

(use-package evil-leader
  :config
  (global-evil-leader-mode)
  (evil-leader/set-leader "<SPC>")
  (evil-leader/set-key "<RET>" 'bookmark-jump)
  ;; p - Project
  (evil-leader/set-key "pp" 'projectile-switch-project)
  (evil-leader/set-key "pf" 'counsel-git)
  (evil-leader/set-key "pa" 'projectile-add-known-project)
  (evil-leader/set-key "pd" 'projectile-remove-known-project)
  (evil-leader/set-key "pD" 'projectile-discover-projects-in-search-path)
  (evil-leader/set-key "ps" 'counsel-git-grep)
  ;; b - Buffer
  (evil-leader/set-key "bb" 'counsel-switch-buffer)
  (evil-leader/set-key "bs" 'save-buffer)
  (evil-leader/set-key "bS" 'projectile-save-project-buffers)
  (evil-leader/set-key "bp" 'previous-buffer)
  (evil-leader/set-key "bi" 'ibuffer)
  (evil-leader/set-key "bk" 'kill-buffer)
  ;; f - Find
  (evil-leader/set-key "fp" 
    (lambda () 
      (interactive) 
      (siatwe/find-file-in-directory config-directory)))
  (evil-leader/set-key "fs" 
    (lambda () 
      (interactive) 
      (siatwe/find-string-in-directory config-directory)))
  ;; o - Open
  (evil-leader/set-key "oe" 
    (lambda () 
      (interactive) 
      (siatwe/open-command-in-split-window "projectile-run-eshell")))
  (evil-leader/set-key "oE" 
    (lambda () 
      (interactive) 
      (siatwe/open-command-in-split-window "eshell")))
  (evil-leader/set-key "od" 'dired)
  (evil-leader/set-key "op" 'treemacs)
  (evil-leader/set-key "ot" 
    (lambda () 
      (interactive) 
      (siatwe/open-command-in-split-window "projectile-run-vterm")))
  (evil-leader/set-key "oT" 
    (lambda () 
      (interactive) 
      (siatwe/open-command-in-split-window "vterm")))
  (evil-leader/set-key "os" 'siatwe/org-edit-or-exit-special)
  ;; n - Notes
  (evil-leader/set-key "nf" 
    (lambda () 
      (interactive) 
      (siatwe/find-file-in-directory org-directory)))
  (evil-leader/set-key "na" 'org-agenda)
  (evil-leader/set-key "ne" 'org-decrypt-entry)
  (evil-leader/set-key "ns" 
    (lambda () 
      (interactive) 
      (siatwe/find-string-in-directory org-directory)))
  ;; g - maGit
  (evil-leader/set-key "gg" 'magit)
  ;; w - Window
  (evil-leader/set-key "ws" 'evil-window-split)
  (evil-leader/set-key "wv" 'evil-window-vsplit)
  ;; h - Help
  (evil-leader/set-key "hv" 'describe-variable)
  (evil-leader/set-key "hf" 'describe-function)
  (evil-leader/set-key "hk" 'describe-key)
  (evil-leader/set-key "hm" 'describe-mode))

Evil Matchit

(use-package evil-matchit
  :config
  (global-evil-matchit-mode 1))

Evil Multiedit

This plugin was an answer to the lack of proper multiple cursor support in Emacs+evil. It allows you to select and edit matches interactively, integrating iedit-mode into evil-mode with an attempt at sensible defaults.

(use-package evil-multiedit
  :config
  (define-key evil-visual-state-map "R" 'evil-multiedit-match-all)
  (define-key evil-normal-state-map (kbd "M-d") 'evil-multiedit-match-and-next)
  (define-key evil-visual-state-map (kbd "M-d") 'evil-multiedit-match-and-next)
  (define-key evil-insert-state-map (kbd "M-d") 'evil-multiedit-toggle-marker-here)
  (define-key evil-normal-state-map (kbd "M-D") 'evil-multiedit-match-and-prev)
  (define-key evil-visual-state-map (kbd "M-D") 'evil-multiedit-match-and-prev)
  (define-key evil-visual-state-map (kbd "C-M-D") 'evil-multiedit-restore)
  (define-key evil-multiedit-state-map (kbd "C-n") 'evil-multiedit-next)
  (define-key evil-multiedit-state-map (kbd "C-p") 'evil-multiedit-prev)
  (define-key evil-multiedit-insert-state-map (kbd "C-n") 'evil-multiedit-next)
  (define-key evil-multiedit-insert-state-map (kbd "C-p") 'evil-multiedit-prev)
  (evil-ex-define-cmd "ie[dit]" 'evil-multiedit-ex-match))

Evil Commentary

evil-commentary is an Emacs package for evil-mode that intends to make it easy to comment out (lines of) code.

(use-package evil-commentary
  :config
  (evil-commentary-mode))

Evil Org

(use-package evil-org
  :after org
  :hook (org-mode . (lambda () evil-org-mode))
  :config
  (require 'evil-org-agenda)
  (evil-org-agenda-set-keys))

Undo Tree

(use-package undo-tree)
(global-undo-tree-mode 1)

Key Chord

In this package, a “key chord” is two keys pressed simultaneously, or a single key quickly pressed twice.

(use-package key-chord
  :config
  (setq key-chord-two-keys-delay 0.5)
  (key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
  (key-chord-define evil-insert-state-map "kk" 'yas-expand)
  (key-chord-define evil-normal-state-map "ge" 'next-error)
  (key-chord-define evil-normal-state-map "gE" 'previous-error)             
  (key-chord-mode 1))

Git Gutter

(use-package git-gutter
  :config
  (global-git-gutter-mode +1)
  (custom-set-variables
   '(git-gutter:update-interval 2)))

Tramp

TRAMP (Transparent Remote Access, Multiple Protocols) is a package for editing remote files. (Needed for helm-projectile commands)

(use-package tramp)

Magit

Magit is an interface to the version control system Git, implemented as an Emacs package. Magit aspires to be a complete Git porcelain. While we cannot (yet) claim that Magit wraps and improves upon each and every Git command, it is complete enough to allow even experienced Git users to perform almost all of their daily version control tasks directly from within Emacs. While many fine Git clients exist, only Magit and Git itself deserve to be called porcelains.

(use-package magit)

Emmet Mode

zencoding-mode is a minor mode providing support for Zen Coding by producing HTML from CSS-like selectors.

(use-package emmet-mode
  :config
  (emmet-mode 1)
  (define-key emmet-mode-keymap [tab] 'emmet-expand-line)
  (add-hook 'php-mode-hook 'emmet-mode)
  (add-hook 'web-mode-hook 'emmet-mode)
  (add-hook 'html-mode-hook 'emmet-mode)
  (add-hook 'css-mode-hook  'emmet-mode))

Ivy and Counsel

(use-package ivy
  :diminish
  :bind (("C-s" . swiper)
         :map ivy-minibuffer-map
         ("C-j" . ivy-next-line)
         ("C-k" . ivy-previous-line)
         :map ivy-switch-buffer-map
         ("C-j" . ivy-next-line)
         ("C-k" . ivy-previous-line)
         :map ivy-reverse-i-search-map
         ("C-j" . ivy-next-line)
         ("C-k" . ivy-previous-line))
  :config
  (setq ivy-use-selectable-prompt t)
  (ivy-mode 1))

(use-package ivy-rich
  :init
  (ivy-rich-mode 1))

(use-package counsel
  :custom
  (counsel-linux-app-format-function #'counsel-linux-app-format-function-name-only)
  :config
  (setq counsel-find-file-ignore-regexp "\\.log\\'")
  (counsel-mode 1))

(use-package flx
  :config
  (setq ivy-re-builders-alist
        '((t . ivy--regex-plus)))
  (setq ivy-re-builders-alist
        '((ivy-switch-buffer . ivy--regex-plus)
          (t . ivy--regex-fuzzy))))

Helpful

(use-package helpful
  :custom
  (counsel-describe-function-function #'helpful-callable)
  (counsel-describe-variable-function #'helpful-variable)
  :bind
  ([remap describe-function] . counsel-describe-function)
  ([remap describe-command] . helpful-command)
  ([remap describe-variable] . counsel-describe-variable)
  ([remap describe-key] . helpful-key))

Company

Company is a text completion framework for Emacs. The name stands for “complete anything”. It uses pluggable back-ends and front-ends to retrieve and display completion candidates.

(use-package company
  :bind (:map company-active-map
              ("RET" . siatwe/company-complete-selection)
              ("C-n" . company-select-next)
              ("C-p" . company-select-previous))
  :config
  (setq company-minimum-prefix-length 1
        company-idle-delay 0.0))

(add-hook 'after-init-hook 'global-company-mode)

Treemacs

(use-package treemacs
  :config
  (treemacs-git-mode 'simple)
  (treemacs-filewatch-mode t))
(use-package treemacs-evil
  :ensure t
  :after treemacs)
(use-package treemacs-projectile
  :ensure t
  :after treemacs)

LSP

Emacs client/library for the Language Server Protocol.

https://emacs-lsp.github.io/lsp-mode/tutorials/how-to-turn-off/

(use-package lsp-mode
  :commands (lsp lsp-deferred)
  :config
  (setq lsp-enable-file-watchers 1)
  (setq lsp-file-watch-threshold '99999)
  (setq lsp-headerline-breadcrumb-enable nil)
  ;; (setq lsp-ui-doc-enable nil)
  (lsp-enable-which-key-integration t))

(use-package lsp-ui)

LSP Treemacs

(use-package lsp-treemacs
  :config
  (lsp-treemacs-sync-mode 1))

Yasnippet

YASnippet is a template system for Emacs. It allows you to type an abbreviation and automatically expand it into function templates. Bundled language templates include: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more.

(use-package yasnippet
  :config
  (yas-global-mode 1)
  (define-key yas-minor-mode-map (kbd "<tab>") nil)
  (define-key yas-minor-mode-map (kbd "TAB") nil))

All The Icons

A utility package to collect various Icon Fonts and propertize them within Emacs.

(use-package all-the-icons)

Projectile

Projectile is a project interaction library for Emacs. Its goal is to provide a nice set of features operating on a project level without introducing external dependencies (when feasible). For instance - finding project files has a portable implementation written in pure Emacs Lisp without the use of GNU find (but for performance sake an indexing mechanism backed by external commands exists as well).

(use-package projectile
  :diminish projectile-mode
  :config
  (projectile-mode)
  (setq projectile-project-search-path '("/data/55/" "/data/53/" "/data/Projects/"))
  :custom ((projectile-completion-system 'ivy))
  :init
  (setq projectile-switch-project-action #'projectile-dired))

(use-package counsel-projectile
  :config (counsel-projectile-mode))

Doom Modline

A fancy and fast mode-line inspired by minimalism design.

(use-package doom-modeline
  :init
  (doom-modeline-mode 1))

Theme

Dracula can’t stand the light.

(use-package doom-themes
  :config
  (setq doom-themes-enable-bold t
        doom-themes-enable-italic t)
  (load-theme 'doom-dracula t)
  (doom-themes-visual-bell-config)
  (setq doom-themes-treemacs-theme "doom-colors")
  (doom-themes-treemacs-config)
  (doom-themes-org-config))

(defvar siatwe/frame-transparency '(95 . 95))

(set-frame-parameter (selected-frame) 'alpha siatwe/frame-transparency)
(add-to-list 'default-frame-alist `(alpha . ,siatwe/frame-transparency))

Hl Todo

Highlight TODO and similar keywords in comments and strings

(use-package hl-todo
  :config
  (add-hook 'prog-mode-hook 'hl-todo-mode))

Org-bullets

Utf-8 bullets for org-mode.

(use-package org-bullets
  :after org
  :hook (org-mode . org-bullets-mode)
  :custom
  (org-bullets-bullet-list '("" "" "" "" "" "" "")))

Which Key

Emacs package that displays available keybindings in popup.

(use-package which-key
  :config
  (which-key-mode))

Eshell

(use-package eshell
  :init
  (setq eshell-scroll-to-bottom-on-input 'all
        eshell-error-if-no-glob t
        eshell-hist-ignoredups t
        eshell-save-history-on-exit t
        eshell-prefer-lisp-functions nil
        eshell-destroy-buffer-when-process-dies t)
  :config
  (setq eshell-prompt-function
        (lambda ()
          (concat (eshell/pwd) " λ ")))
  (add-hook 'eshell-exit-hook 'eshell-pop--kill-and-delete-window))

(defun eshell/close ()
  (delete-window))

(defun eshell/clear ()
  (let ((inhibit-read-only t))
    (erase-buffer)))

(defun eshell-pop--kill-and-delete-window ()
  (unless (one-window-p)
    (delete-window)))

(use-package eshell-up
  :commands eshell-up eshell-up-peek)

(use-package eshell-did-you-mean
  :after esh-mode ; Specifically esh-mode, not eshell
  :config
  (eshell-did-you-mean-setup)
  ;; HACK There is a known issue with `eshell-did-you-mean' where it does not
  ;;      work on first invocation, so we invoke it once manually by setting the
  ;;      last command and then calling the output filter.
  (setq eshell-last-command-name "catt")
  (eshell-did-you-mean-output-filter "catt: command not found"))

Scratch

Scratch is an extension to Emacs that enables one to create scratch buffers that are in the same mode as the current buffer. This is notably useful when working on code in some language; you may grab code into a scratch buffer, and, by virtue of this extension, do so using the Emacs formatting rules for that language.

(use-package scratch
  :ensure t)

Rainbow Delimiters

rainbow-delimiters is a “rainbow parentheses”-like mode which highlights delimiters such as parentheses, brackets or braces according to their depth. Each successive level is highlighted in a different color. This makes it easy to spot matching delimiters, orient yourself in the code, and tell which statements are at a given depth.

(use-package rainbow-delimiters)
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)

Tree Sitter

(use-package tree-sitter-langs
  :ensure t)
(use-package tree-sitter
  :ensure t
  :config
  (require 'tree-sitter)
  (require 'tree-sitter-langs)
  (global-tree-sitter-mode)
  (add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))

Git Auto Commit Mode

(use-package git-auto-commit-mode
  :config
  (setq-default gac-automatically-add-new-files-p t)
  (setq-default gac-automatically-push-p t))

Visual Fill Column

(use-package visual-fill-column)

Writeroom Mode

(use-package writeroom-mode)

Vterm

(use-package vterm)

Functions

Minify JS and LESS

(defun minify-js-or-less ()
  (interactive)
  (save-window-excursion
    ;; LESS
    (when (string= (file-name-extension buffer-file-name) "less")
      (async-shell-command
       (concat "lessc --no-color " (projectile-project-root) "webroot/less/main.less "  (projectile-project-root) "webroot/less/main.css")))
    ;; JS
    (when (string= (file-name-extension buffer-file-name) "js")
      (async-shell-command
       (concat "yui-compressor " (projectile-project-root) "webroot/js/main.js -o "  (projectile-project-root) "webroot/js/main.min.js")))))

Indent/Format Whole Buffer

(defun format-and-indent-buffer ()
  "Indent whole buffer and delete trailing whitespace."
  (interactive)
  (save-excursion
    (indent-region (point-min) (point-max) nil)
    (delete-trailing-whitespace)
    ;; PHP
    (when (string= (file-name-extension buffer-file-name) "php")
      (lsp-format-buffer))
    ;; org
    (when (string= (file-name-extension buffer-file-name) "org")
      (org-fill-paragraph))))

Copy Current File Path With Line Number To Kill Ring

(defun position-to-kill-ring ()
  "Copy to the kill ring a string in the format \"file-name::line-number\"
   for the current buffer's file name, and the line number at point."
  (interactive)
  (kill-new
   (format "%s::%d" (buffer-file-name) (save-restriction
                                         (widen) (line-number-at-pos)))))

Open commands in split window (for eshell/vterm)

Thanks to abrochard.

(defun siatwe/open-command-in-split-window (term-command)
  (interactive)
  (let* ((height (/ (window-total-height) 3)))
    (split-window-vertically (- height))
    (other-window 1)
    (funcall (intern term-command))))

Functions to sort

(defun siatwe/find-file-in-directory (directory)
  "Find file in DIRECTORY."
  (interactive)
  (if (file-directory-p directory)
      (counsel-find-file nil directory)
    (message (format "Directory %s not found!" directory))))

(defun siatwe/find-string-in-directory (directory)
  "Find string in DIRECTORY."
  (interactive)
  (if (file-directory-p directory)
      (counsel-git-grep nil directory nil)
    (message (format "Directory %s not found!" directory))))

(defun siatwe/org-edit-or-exit-special ()
  "Edit source block in language-mode when in org-mode. Otherwise exit
language-mode and return to org-mode."
  (interactive)
  (if(string= "emacs-lisp-mode" major-mode)
      (org-edit-src-exit)
    (org-edit-special)))


(defun siatwe/company-complete-selection ()
  "Insert the selected candidate or the first if none are selected."
  (interactive)
  (if company-selection
      (company-complete-selection)
    (company-complete-number 1)))

Misc

Customization

Space over tabs

(setq-default indent-tabs-mode nil)

Disable mini-buffer start-up message

(defun display-startup-echo-area-message ()(message ""))

Eww as default browser

(setq browse-url-browser-function 'browse-url-default-browser)

Disable GUI elements.

(menu-bar-mode -1)
(toggle-scroll-bar -1)
(tool-bar-mode -1)

Hide mouse while typing.

;;(mouse-avoidance-mode)

Show matching parens.

(show-paren-mode 1)

When on, typing any left bracket automatically insert the right matching bracket

(electric-pair-mode 1)

Enable line numbers and prog-mode in all programming modes and org mode.

(global-display-line-numbers-mode t)

(dolist (mode '(org-mode-hook
                term-mode-hook
                shell-mode-hook
                vterm-mode-hook
                treemacs-mode-hook
                eshell-mode-hook))
  (add-hook mode (lambda () (display-line-numbers-mode 0))))

Highlight current line.

(global-hl-line-mode +1)

Wrap lines at the 80th column.

(add-hook 'text-mode-hook 'auto-fill-mode)
(add-hook 'org-mode-hook 'auto-fill-mode)
(setq-default fill-column 80)

Show column number

(column-number-mode 1)

Set font.

(defvar siatwe/default-font-size 140)
(defvar siatwe/default-variable-font-size 140)
(set-face-attribute 'default nil :font "Hack" :height siatwe/default-font-size)

Disable mini buffer position.

(set-window-scroll-bars (minibuffer-window) nil nil)

Set visual bell.

(setq visible-bell t)

Disable backup und auto save files.

(setq make-backup-files nil)
(setq auto-save-default nil)

Disable startup-screen.

(setq inhibit-startup-screen t)
(let ((inhibit-message nil)))

Always start emacs in fullscreen mode

(toggle-frame-maximized)

Optimization for LSP.

(setq read-process-output-max (* 3072 3072)) ;; 3mb

Garbage-collect on focus out

(add-hook 'focus-out-hook #'garbage-collect)

UTF-8 everywhere

(prefer-coding-system       'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)

Auto save visited

;; (setq auto-save-visited-interval 1)
;; (auto-save-visited-mode 1)

Org

Fix for opening Org links in external apps

(setq process-connection-type nil)

Don’t ask for evaluation

(setq org-confirm-babel-evaluate nil)

Disable Org Indent Mode.

(org-indent-mode)

Ellipsis

(setq org-ellipsis "")

Disable Indention on RET

;;(add-hook 'org-mode-hook (lambda () (electric-indent-mode -1)))

To Sort

;; for completeness sake
(defun +eshell--current-git-branch ()
  (let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
                           when (string-match "^\*" match)
                           collect match))))
    (if (not (eq branch nil))
        (concat " [" (substring branch 2) "]")
      "")))

(setq warning-minimum-level :emergency)
(global-set-key (kbd "C-SPC") 'company-capf)
(setq org-agenda-files '("~/.org/people.org"
                         "~/.org/timer.org"))

(setq initial-scratch-message "")

(use-package shrink-path)

(setq eshell-prompt-regexp "^.* λ "
      eshell-prompt-function #'+eshell/prompt)

(defun +eshell/prompt ()
  (let ((base/dir (shrink-path-prompt default-directory)))
    (concat (propertize (car base/dir)
                        'face 'font-lock-comment-face)
            (propertize (cdr base/dir)
                        'face 'font-lock-constant-face)
            (propertize (+eshell--current-git-branch)
                        'face 'font-lock-function-name-face)
            (propertize " λ" 'face 'eshell-prompt-face)
            ;; needed for the input text to not have prompt face
            (propertize " " 'face 'default))))j


(use-package eshell-syntax-highlighting
  :after esh-mode
  :config
  (eshell-syntax-highlighting-global-mode +1))