Skip to content

Instantly share code, notes, and snippets.

@mikowl
Last active December 27, 2021 17:42
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 mikowl/db3e95ec9f9c91ed760501318e56ae4d to your computer and use it in GitHub Desktop.
Save mikowl/db3e95ec9f9c91ed760501318e56ae4d to your computer and use it in GitHub Desktop.
emacs config as of 12/08/20

Emacs configuration

Improve startup time

(setq gc-cons-threshold 402653184
      gc-cons-percentage 0.6)
(defvar doom--file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)
(setq package-enable-at-startup nil ; don't auto-initialize!
      ;; don't add that `custom-set-variables' block to my initl!
      package--init-file-ensured t)

Load some basic packages

;; auto-package-update
(use-package auto-package-update
   :ensure t
   :config
   (setq auto-package-update-delete-old-versions t
         auto-package-update-interval 4)
   (auto-package-update-maybe))

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

;; exec-path-from-shell
(use-package exec-path-from-shell
  :ensure t)
(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))

;; org-journal
(use-package org-journal
  :ensure t)

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

;; Evil mode
(use-package evil
  :ensure t
  :init
  (setq evil-want-keybinding nil)
  :config
  (evil-mode 1))

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

;; better defaults
(use-package better-defaults
  :ensure t)

;; neotree
(use-package neotree
  :ensure t)
(setq neo-smart-open t)

;; neotree evil mode
(add-hook 'neotree-mode-hook
    (lambda ()
    (define-key evil-normal-state-local-map (kbd "TAB") 'neotree-enter)
    (define-key evil-normal-state-local-map (kbd "SPC") 'neotree-quick-look)
    (define-key evil-normal-state-local-map (kbd "q") 'neotree-hide)
    (define-key evil-normal-state-local-map (kbd "RET") 'neotree-enter)
    (define-key evil-normal-state-local-map (kbd "g") 'neotree-refresh)
    (define-key evil-normal-state-local-map (kbd "n") 'neotree-next-line)
    (define-key evil-normal-state-local-map (kbd "p") 'neotree-previous-line)
    (define-key evil-normal-state-local-map (kbd "A") 'neotree-stretch-toggle)
    (define-key evil-normal-state-local-map (kbd "H") 'neotree-hidden-file-toggle)))

(setq neo-window-fixed-size nil)

;; Set the neo-window-width to the current width of the
;; neotree window, to trick neotree into resetting the
;; width back to the actual window width.
;; Fixes: https://github.com/jaypei/emacs-neotree/issues/262
(eval-after-load "neotree"
'(add-to-list 'window-size-change-functions
                (lambda (frame)
                (let ((neo-window (neo-global--get-window)))
                    (unless (null neo-window)
                    (setq neo-window-width (window-width neo-window)))))))

;; centaur tabs
(use-package centaur-tabs
   :demand
   :config
   (setq centaur-tabs-style "bar")
   (setq centaur-tabs-height 40)
   (setq centaur-tabs-set-icons t)
   (setq centaur-tabs-set-bar 'over)
   (setq centaur-tabs-set-modified-marker t)
   (centaur-tabs-headline-match)
   (centaur-tabs-mode t)
   :bind
   ("C-<prior>" . centaur-tabs-backward)
   ("C-<next>" . centaur-tabs-forward)
   ("C-c t" . centaur-tabs-counsel-switch-group)
   (:map evil-normal-state-map
    ("g t" . centaur-tabs-forward)
    ("g T" . centaur-tabs-backward)))


;; Markdown
(use-package markdown-mode
  :ensure t
  :commands (markdown-mode gfm-mode)
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "multimarkdown"))

;; Helm - auto complete and selection
(use-package helm
  :ensure t)

;; Ivy - another completion mechanism
(use-package ivy :ensure t
  :diminish (ivy-mode . "")
  :bind
  (:map ivy-mode-map
   ("C-'" . ivy-avy))
  :config
  (ivy-mode 1)
  ;; add ‘recentf-mode’ and bookmarks to ‘ivy-switch-buffer’.
  (setq ivy-use-virtual-buffers t)
  ;; number of result lines to display
  (setq ivy-height 15)
  ;; does not count candidates
  (setq ivy-count-format "")
  ;; no regexp by default
  (setq ivy-initial-inputs-alist nil)
  ;; configure regexp engine.
  (setq ivy-re-builders-alist
  ;; allow input not in order
        '((t   . ivy--regex-ignore-order))))

;; Icons in Ivy
(use-package all-the-icons-ivy
  :ensure t
  :config
  (all-the-icons-ivy-setup))
(setq all-the-icons-ivy-file-commands
  '(list-buffers find-file)) 

;; the super helpful which-key
(use-package which-key
  :ensure t
  :init (which-key-mode))

;; smartparens
(use-package smartparens
  :ensure t)

;; smartparens (config inspired by doom-emacs)
(use-package smartparens
  :init (smartparens-global-mode)
  :config
  (require 'smartparens-config)

  (setq sp-autowrap-region nil ; let evil-surround handle this
        sp-highlight-pair-overlay nil
        sp-cancel-autoskip-on-backward-movement nil
        sp-show-pair-delay 0
        sp-max-pair-length 3)

  ;; disable smartparens in evil-mode's replace state (they conflict)
  (add-hook 'evil-replace-state-entry-hook #'turn-off-smartparens-mode)
  (add-hook 'evil-replace-state-exit-hook  #'turn-on-smartparens-mode)

  (sp-local-pair '(xml-mode nxml-mode php-mode) "<!--" "-->"
                 :post-handlers '(("| " "SPC"))))

;; Flycheck 
(use-package flycheck
  :ensure t
  :init (global-flycheck-mode))

;; all the icons
(use-package all-the-icons
  :ensure t)

;; projectile
(use-package projectile
  :ensure t)
(projectile-mode +1)
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)

;; key-chord
(use-package key-chord
  :ensure t)

;; avy jump to things
(use-package avy
  :ensure t)

;; multiple cursors
(use-package multiple-cursors
  :ensure t)

(global-set-key (kbd "C-S-l") 'mc/edit-lines)
(global-set-key (kbd "s-d") 'mc/mark-next-like-this)
(global-set-key (kbd "s-S-d") 'mc/mark-previous-like-this)
(global-set-key (kbd "s-S-a") 'mc/mark-all-like-this)

;; osx clipboard
(use-package osx-clipboard
  :ensure t)

;; rainbow delimiters because why not  
(use-package rainbow-delimiters
  :ensure t)
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)

;; rainbow identifiers because why not
(use-package rainbow-identifiers
  :ensure t)
(add-hook 'prog-mode-hook 'rainbow-identifiers-mode)

Code related packages

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

Set some basic settings

(desktop-save-mode 1)

;; exec-path
;; (setq exec-path (append exec-path '("~/.nvm/versions/node/v6.3.0/bin")))

(setq
 inhibit-startup-message t         ; Don't show the startup message
 inhibit-startup-screen t          ; or screen
 echo-keystrokes 0.1               ; Show keystrokes right away, don't show the message in the scratch buffe
 initial-scratch-message nil       ; Empty scratch buffer
 sentence-end-double-space nil     ; Sentences should end in one space, come on!
 confirm-kill-emacs 'y-or-n-p      ; y and n instead of yes and no when quitting
)
(fset 'yes-or-no-p 'y-or-n-p)      ; y and n instead of yes and no everywhere else
(scroll-bar-mode -1)
(delete-selection-mode 1)
;; set back up directory so we don't see them
(setq backup-directory-alist `(("." . "~/.emacs.d/saves")))
;; and auto-saves as well
(setq backup-directory-alist
          `(("." . ,(concat user-emacs-directory "~/.emacs.d/saves"))))
;; global company mode
(add-hook 'after-init-hook 'global-company-mode)

;; No lockfiles
(setq create-lockfiles nil)

;; Only show menu bar in gui emacs

(if (display-graphic-p)
  (progn
    (menu-bar-mode 1))
  (menu-bar-mode -1))

Theme/Visual Stuff

Set the theme

;;(load-theme 'base16-atelier-lakeside t)

(use-package doom-themes
    ;;:init (load-theme 'doom-one t)
    :init 
    (if (display-graphic-p)
        (progn
            (load-theme 'doom-dracula t))
        (load-theme 'doom-spacegrey t))
    :config
    (progn
      ;; Enable flashing mode-line on errors
      (doom-themes-visual-bell-config)
      ;; Corrects (and improves) org-mode's native fontification.
      (doom-themes-org-config)
      ;; Enable custom treemacs theme (all-the-icons must be installed!)
      ;;(doom-themes-treemacs-config)
      ;; Enable custom neotree config
      (doom-themes-neotree-config)
))
      
(use-package solaire-mode
  :init
  (solaire-mode)
  :config
  (progn
    (add-hook 'after-change-major-mode-hook 'turn-on-solaire-mode))
    (solaire-mode-swap-bg))

Use spaces

(setq-default indent-tabs-mode nil)
(setq tab-width 2)

(setq js-indent-level 2)
(setq css-indent-offset 2)
(setq-default c-basic-offset 2)
(setq c-basic-offset 2)
(setq-default tab-width 2)
(setq-default c-basic-indent 2)

Doom modeline

(use-package doom-modeline
      :ensure t
      :hook (after-init . doom-modeline-mode)
      :config
      (setq doom-modeline-icon t)
      (setq doom-modeline-major-mode-color-icon t)
      (setq doom-modeline-buffer-state-icon t)
      (setq doom-modeline-enable-word-count t))

Line numbers

(setq-default display-line-numbers t
              display-line-numbers-width 3)

Font

;; Set font, with fallbacks
(cond 
      ((member "JetBrains Mono" (font-family-list))
       (set-face-attribute 'default nil 
         :family "IBM Plex Mono"
         :height 160
         :weight 'light
         :width 'normal))
      ((member "IBM Plex Mono" (font-family-list))
       (set-face-attribute 'default nil 
         :family "IBM Plex Mono"
         :height 160
         :weight 'light
         :width 'normal))
      ((member "Operator Mono Lig" (font-family-list))
       (set-face-attribute 'default nil 
         :font "Operator Mono Lig"
         :height 160
         :weight 'normal
         :width 'normal))
      ((member "SauceCodePro Nerd Font" (font-family-list))
       (set-face-attribute 'default nil 
         :font "SauceCodePro Nerd Font"
         :height 160
         :weight 'normal
         :width 'normal))
      ((member "Dank Mono" (font-family-list))
       (set-face-attribute 'default nil 
         :font "Dank Mono"
         :height 160
         :weight 'normal
         :width 'normal))
      ((member "Source Code Pro" (font-family-list))
       (set-face-attribute 'default nil 
         :font "Source Code Pro"
         :height 150
         :weight 'normal
         :width 'normal))
      ((member "Menlo" (font-family-list))
       (set-face-attribute 'default nil 
         :font "Menlo"
         :height 150
         :weight 'normal
         :width 'normal)))

Transparent titlebar

;;(dolist (x '((ns-transparent-titlebar . unbound)
;;		  (ns-appearance . unbound)))
;;   (add-to-list 'frameset-filter-alist x))
(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
(add-to-list 'default-frame-alist '(ns-appearance . dark))

Org mode stuff

Some basic stuff

(setq evil-want-C-i-jump nil)
(setq org-startup-with-inline-images t)

(use-package org-bullets
  :ensure t)
(if (display-graphic-p)
  (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
)
(add-hook 'org-mode-hook
          (lambda ()
        (define-key evil-normal-state-map (kbd "TAB") 'org-cycle))) 

;; Increase line spacing in org mode
(add-hook 'org-mode-hook (lambda () (setq line-spacing 0.15)))

;; Hide leading stars
(setq org-startup-indented t
      org-hide-leading-stars t)

;; Record time and note when a task is completed
;;(setq org-log-done 'note)

;; Enable visual-line-mode in org-mode
(with-eval-after-load 'org       
  (setq org-startup-indented t) ; Enable `org-indent-mode' by default
  (add-hook 'org-mode-hook #'visual-line-mode))

;; change time format to standard am/pm
(setq-default org-display-custom-times t)
(setq org-time-stamp-custom-formats '("<%a %m/%d/%y>" . "<%a %B, %d %Y @ %l:%M%p>"))

;; set header sizes
(custom-set-faces
 '(org-block ((t (:background "#292a32"))))
 '(org-link ((t (:foreground "#88c0d0" :underline t))))
 '(org-block-begin-line ((t (:background "#5e5773" :foreground "#ada6c0"))))
 '(org-headline-done ((t (:foreground "#78849d"))))
 '(org-hide ((t (:foreground "#10243d"))))
 '(org-level-1 ((t (:foreground "#95bfce" :weight normal :height 175 :background nil :box nil))))
 '(org-level-2 ((t (:inherit outline-2 :weight normal :height 170))))
 '(org-level-3 ((t (:foreground "#5b93da" :weight normal :height 165))))
 '(org-level-4 ((t (:inherit outline-4 :weight normal :height 165))))
 '(org-level-5 ((t (:inherit outline-5 :weight normal :height 160)))))

;; org-agenda
(setq org-agenda-files (list "~/Documents/Notes/"))

(setq org-agenda-custom-commands
      '(("c" "Simple agenda view"
         ((agenda "")
          (alltodo "")))))

;; languages
(org-babel-do-load-languages
  'org-babel-load-languages
  '(
    (emacs-lisp . t)
    (js . t)
))

(require 'ob-js)

(add-to-list 'org-babel-load-languages '(js . t))
(org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)
(add-to-list 'org-babel-tangle-lang-exts '("js" . "js"))

Keywords and sequences

(setq org-todo-keywords
'(
(sequence "-_TODO-" "-_IN_PROGRESS-" "-⚐_CODE_REVIEW-""-_BLOCKED-" "-_OPEN-" "-_QA-" "-_UAT-" "-_TO_BE_DEPLOYED-" "|" "-_DONE-" "-_CANCELLED-" "-_ON_HOLD-")

(sequence "TODO(t)" "TO_READ(tr)" "CODE(c)" "|" "DONE(d)")
))

(setq org-todo-keyword-faces
'(
("TODO" . (:foreground "#98bd78"))
("IN_PROGRESS" . (:background "#dfa185" :foreground "#22262f"))
("CODE_REVIEW" . (:background "#eb9d54" :foreground "#733d09"))
("BLOCKED" . (:background "#b7565f" :foreground "#22262f"))
("OPEN" . (:background "#f9c96f" :foreground "#22262f"))
("QA" . (:background "#55c3b5" :foreground "#22262f"))
("UAT" . (:background "#c491bb" :foreground "#22262f"))
("TO_BE_DEPLOYED" . (:background "#d5ed95" :foreground "#22262f"))
("CANCELLED" . (:foreground "#d3737d" :background "#4d4d4d"))
("DONE" . (:background "#22262f" :foreground "#FFFFFF"))
("ON_HOLD" . "#8799e8")
("CODE" . (:background "#f9c96f" :foreground "#22262f"))
("TO_READ" . "#d983dc")

("-_TODO-" . (:foreground "#98bd78" :background "#133560" :height 150))
("-_IN_PROGRESS-" . (:background "#2c7286" :foreground "#FFFFFF" :height 150))
("-⚐_CODE_REVIEW-" . (:background "#eb9d54" :foreground "#733d09" :height 150))
("-_BLOCKED-" . (:background "#b7565f" :foreground "#22262f" :height 150))
("-_OPEN-" . (:background "#f9c96f" :foreground "#22262f" :height 150))
("-_QA-" . (:background "#55c3b5" :foreground "#22262f" :height 150))
("-_UAT-" . (:background "#c491bb" :foreground "#22262f" :height 150))
("-_TO_BE_DEPLOYED-" . (:background "#c1d69f" :foreground "#22262f" :height 150))
("-_DONE-" . (:background "#091729" :foreground "#68765c" :height 150))
("-_CANCELLED-" . (:foreground "#d3737d" :background "#4d4d4d" :height 150))
("-_ON_HOLD-" . (:foreground "#FFFFFF" :background "#b6545d" :height 150))
))

;; alfred-org-mode
(defun make-orgcapture-frame ()
  "Create a new frame and run org-capture."
  (interactive)
  (make-frame '((name . "remember") (width . 80) (height . 16)
                (top . 400) (left . 300)
                (font . "-apple-Monaco-medium-normal-normal-*-13-*-*-*-m-0-iso10646-1")
                ))
  (select-frame-by-name "remember")
  (org-capture))

org-crypt

(require 'org-crypt)
; Encrypt all entries before saving
(org-crypt-use-before-save-magic)
(setq org-tags-exclude-from-inheritance (quote ("crypt")))
; GPG key to use for encryption
(setq org-crypt-key "1978")

Keyboard

Emacs control is Ctrl. Emacs Super is Command. Emacs Meta is Alt.

(setq mac-right-command-modifier 'super)
(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'super)

;; neotree
(global-set-key (kbd "s-\\") 'neotree-toggle)

;; avy-goto-char [[https://github.com/abo-abo/avy][avy]]
;; go to word
(global-set-key (kbd "C-:") 'avy-goto-word-1)
;; avy-goto-char-2
;;(global-set-key (kbd "C-'") 'avy-goto-char-2)
;; avy-goto-line
;;(global-set-key (kbd "M-g f") 'avy-goto-line)
;; avy-goto-word-1
;; (global-set-key (kbd "M-g w") 'avy-goto-word-1)
;;Exit insert mode by pressing j and then j quickly
(key-chord-mode 1)
(setq key-chord-two-keys-delay 0.5)
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)

Window

Enlarge the default window size

(if (display-graphic-p)
  (progn
    (setq initial-frame-alist
      '(
        (tool-bar-lines . 0)
        (background-color . "#10243d")
        (width . 146) ; chars
        (height . 47) ; lines
        (left . 0)
        (top . 0)))
      (setq default-frame-alist
        '(
          (tool-bar-lines . 0)
          (width . 146)
          (height . 47)
          (background-color . "#10243d")
          (left . 0)
          (top . 0))))
  (progn
    (setq initial-frame-alist '( (tool-bar-lines . 0)))
    (setq default-frame-alist '( (tool-bar-lines . 0)))))

;; visual-fill-column
(use-package visual-fill-column
  :ensure t)
(add-hook 'visual-line-mode-hook #'visual-fill-column-mode)

;; set fill-column width
(setq-default fill-column 120)

Fin

(setq gc-cons-threshold 16777216
       gc-cons-percentage 0.1)
 (setq file-name-handler-alist doom--file-name-handler-alist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment