Skip to content

Latest commit

 

History

History
373 lines (336 loc) · 13.6 KB

emacs.org

File metadata and controls

373 lines (336 loc) · 13.6 KB

Main Emacs Config

Use Package

Where possible I configure everything via the use-package macro. This helps to keep everything consistent and makes code execution order and dependencies between packages explicit. Also, I need as much help as I can get to keep things from getting all tangled up. We have to load it first…

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

(eval-when-compile (require 'use-package))
(setq use-package-always-ensure t)

General Configuration

It’s possible to use use-package to configure ‘emacs’ as it is defined as a feature. I use this to keep global settings together.

(use-package emacs
  :bind
  ("C-w" . backward-kill-word)
  ("C-x C-k" . kill-region)
  ("C-c C-k" . kill-region)
  ("C-x r" . query-replace-regexp)
  ("C-c b" . bury-buffer)
  ("C-c f" . revert-buffer)
  ("C-x C-m" . execute-extended-command)
  ("C-x f" . find-file)
Hooks

Always, always delete trailing whitespace

:hook (before-save . delete-trailing-whitespace)
Initial Setup

Don’t mess about with anything at start up - just start up. Put any custom variables in their own file. I don’t use custom on purpose but sometimes things end up in here by magic

:config
(setq inhibit-startup-message t)
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)
Personal Details

All about little ol’ me

(setq user-full-name "Matthew Ryall"
      user-mail-address "matthew@mexico86.co.uk")
Basic Editing
(setq split-width-threshold 120)
(setq-default fill-column 78)
(setq-default truncate-lines t)
(setq-default indent-tabs-mode nil)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
(setq select-enable-primary t)
(setq select-enable-clipboard t)
Backups and Autosaves

Keep both backup and autosave files in their own directories rather than in the directory of the file being edited

(setq backup-dir "~/.emacs.d/.backups/")
(make-directory backup-dir t)
(setq backup-directory-alist '(("." . "~/.emacs.d/.backups")))
(setq autosave-dir "~/.emacs.d/.autosaves/")
(make-directory autosave-dir t)
(setq auto-save-file-name-transforms `((".*" ,autosave-dir t)))
(setq delete-old-versions -1)
(setq version-control t)
Scrolling
(setq scroll-step 1)
(pixel-scroll-precision-mode)
Settings to Make Things a Bit Nicer
(setq ring-bell-function 'ignore)
(setq next-line-add-newlines t)
(setq sentence-end-double-space nil)
(setq confirm-kill-emacs 'yes-or-no-p)
(setq gc-cons-threshold 100000000)
(setq truncate-string-ellipsis "")
(setq help-window-select t)
(setq completions-detailed t)
(setq enable-recursive-minibuffers t)

(setq use-short-answers t)
(fset 'yes-or-no-p 'y-or-n-p)

(scroll-bar-mode -1)
(tool-bar-mode -1)
(menu-bar-mode -1)
(blink-cursor-mode -1)
(mouse-avoidance-mode 'exile)
(column-number-mode)
(line-number-mode)
(transient-mark-mode)
(global-font-lock-mode)
(show-paren-mode)
(global-auto-revert-mode)
(global-hl-line-mode)
(global-prettify-symbols-mode)
(global-subword-mode)
(minibuffer-depth-indicate-mode 1)

(global-unset-key "\C-z")
(global-unset-key "\C-x\C-z")
(global-unset-key (kbd "<left>"))
(global-unset-key (kbd "<right>"))
(global-unset-key (kbd "<up>"))
(global-unset-key (kbd "<down>"))
(global-unset-key (kbd "<C-left>"))
(global-unset-key (kbd "<C-right>"))
(global-unset-key (kbd "<C-up>"))
(global-unset-key (kbd "<C-down>"))
(global-unset-key (kbd "<M-left>"))
(global-unset-key (kbd "<M-right>"))
(global-unset-key (kbd "<M-up>"))
(global-unset-key (kbd "<M-down>"))
(global-unset-key (kbd "<C-wheel-down>"))
(global-unset-key (kbd "<C-wheel-up>"))

;; Colour fixes for terminal
(set-face-attribute 'line-number nil :foreground "#56697A" :background "#002b36" :weight 'normal)
(set-face-attribute 'markdown-code-face nil)
(set-face-attribute 'org-done nil :background "#002b36" :weight 'bold)
(set-face-attribute 'org-todo nil :foreground "#859900" :background "#002b36" :weight 'bold)
(set-face-attribute 'hl-line nil :background "#002b36"))

Text Editing

Amazingly useful unfill functions. I use these all the time to remove line breaks when writing in org-mode and then pasting into other systems like Slack

(use-package unfill)

Font and Display

(defun mjr/init-font-size (frame font value)
  (set-face-attribute 'default nil :height (* value 10))
  (set-frame-parameter frame 'font
                       (concat font "-" (number-to-string value))))

(defun dpi ()
  "The dots-per-inch of the display."
  (floor (/ (display-pixel-width) (/ (display-mm-width) 25.4))))

(defun mjr/set-font (size)
  (interactive "nSize: ")
  (mjr/init-font-size (selected-frame) "Iosevka" size)
  (when (fboundp 'kind-icon-reset-cache)
    (when (<= 96 (dpi))
      (setq kind-icon-default-style
            '(:padding -1 :stroke 0 :margin 0 :radius 0 :height 0.5 :scale 1.0)))
    (kind-icon-reset-cache)))

(defun mjr/appropriate-font-size ()
  (if (not (display-graphic-p))
      10
    (let ((dpi (dpi))
          (mm-width (cadr (assoc 'mm-size (car (display-monitor-attributes-list))))))
      (cond ((and (equal dpi 92) (and (< mm-width 300) (> mm-width 200))) 16)
            ((and (equal dpi 92) (and (< mm-width 610) (> mm-width 300))) 20)
            ((equal dpi 96) 12)
            ((equal dpi 209) 12)
            (12)))))

(use-package ligature
  :config
  (ligature-set-ligatures 't '("www"))
  (ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
                                       ":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
                                       "!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
                                       "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
                                       "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
                                       "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
                                       "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
                                       "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
                                       ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
                                       "<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
                                       "##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
                                       "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
                                       "\\\\" "://"))
  (global-ligature-mode t))

Environment Variables

(use-package exec-path-from-shell
  :config
  (dolist (var '("SSH_AUTH_SOCK"))
    (add-to-list 'exec-path-from-shell-variables var))
  (exec-path-from-shell-initialize))

MacOS Specific Configuration

(when (eq system-type 'darwin)
  (setq mac-command-modifier 'meta)
  (setq mac-option-modifier 'meta)
  (setq ns-pop-up-frames nil)
  (add-to-list 'default-frame-alist '(undecorated . t)))

Dired Configuration

(use-package dired
  :ensure nil
  :config
  (setq dired-create-destination-dirs 'ask
        dired-kill-when-opening-new-dired-buffer t
        dired-do-revert-buffer t
        dired-mark-region t))

Authentication

Use Pass to store all secrets

(use-package password-store :ensure t)
(use-package auth-source
  :config
  (setq auth-sources '(password-store "~/.authinfo")))

Mode line Configuration

Minor Modes
(use-package minions :config (minions-mode t))
Mood Line
(use-package mood-line
  :after minions
  :config
  (mood-line-mode)
  ;; Add minions mode
  (defun mood-line-segment-major-mode ()
    "Displays the current major mode in the mode-line."
    (concat (format-mode-line minions-mode-line-modes 'mood-line-major-mode) " "))
  (setq mood-line-show-cursor-point t
        mood-line-show-encoding-information t
        mood-line-show-eol-style t))

Help

(use-package helpful
  :bind (("C-h f" . helpful-callable)
         ("C-h v" . helpful-variable)
         ("C-h k" . helpful-key)
         ("C-c C-d" . helpful-at-point)))

Functional Area Configuration

I split up some more extensive configs into files for each functional area. These contain use-package declarations for loading and configuring packages and any other configuration code required. These files are also tangled and loaded by org-babel and a list is inserted into this file for reference

(defun mjr/load-literate-cfg ()
  "Load literate config files using org-babel.")
(let ((cfg-conf-dir "~/.emacs.d/cfg/"))
  (mapcar #'(lambda (conf-file)
              (org-babel-load-file conf-file))
          (directory-files-recursively cfg-conf-dir "^[^.]\.*.org")))

(defun mjr/insert-literate-config-file-list ()
  (interactive)
  (let ((cfg-conf-dir "~/.emacs.d/cfg/")
        (file-list nil))
    (setq file-list (directory-files-recursively cfg-conf-dir "^[^.]\.*.org"))
    (save-excursion
      (goto-char (point-min))
      (when (re-search-forward "[:]CFGLST:" (point-max) t)
        (let ((beg (point))
              (end
               (save-excursion
                 (when (search-forward-regexp "^\\*" (point-max))
                   (forward-line -1))
                 (end-of-line)
                 (point))))
          (delete-region beg end))
        (insert "\n")
        (insert "    Configuration files for more specific functional areas\n")
        (mapcar '(lambda (file) (insert (format "    - [[file:%s]]\n" (substring file 11)))) file-list)))))

Functional Area Configuration Files

Configuration files for more specific functional areas

Directory Environment

(use-package envrc
  :config
  (envrc-global-mode))

Footer

We thank you for your patience

(mjr/load-literate-cfg)