emacs/config/defaults.org

7.4 KiB

Emacs Config Defaults

  (setq custom-file (locate-user-emacs-file "custom.el"))
  (when (and custom-file (file-exists-p custom-file))
    (load custom-file nil 'nomessage))

  (setq user-full-name "Evie Litherland-Smith"
        user-mail-address "evie@xenia.me.uk"
        use-short-answers t
        load-prefer-newer t
        indent-tabs-mode nil
        even-window-sizes t
        global-auto-revert-non-file-buffers t
        dired-auto-revert-buffer t
        dired-dwim-target t
        tab-always-indent t
        completion-cycle-threshold nil
        completions-detailed t
        xref-show-definitions-function #'xref-show-definitions-completing-read
        kill-do-not-save-duplicates t
        auto-window-vscroll nil
        fast-but-imprecise-scrolling t
        scroll-conservatively 101
        scroll-margin 0
        scroll-preserve-screen-position 1)


  ;; Bind normal forward/back buttons on mouse to next/previous buffer respectively
  (keymap-global-set "<mouse-8>" #'previous-buffer)
  (keymap-global-set "<mouse-9>" #'next-buffer)

  (set-default-coding-systems 'utf-8)
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8)

  (global-auto-revert-mode +1)
  (delete-selection-mode +1)

  ;; No tabs
  (customize-set-variable 'indent-tabs-mode nil)

  ;; Only display async output buffer when there's something to show
  (customize-set-variable 'async-shell-command-display-buffer nil)

  ;; Make shebang (#!) file executable when saved
  (add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)

  ;; Scroll compilation buffer output
  (customize-set-variable 'compilation-scroll-output t)

Auto-save file settings

  (setq backup-directory-alist '(("." . "~/.local/state/emacs/backups"))
        tramp-backup-directory-alist backup-directory-alist
        tramp-auto-save-directory (cdr (assoc "." tramp-backup-directory-alist)))

  (savehist-mode +1)

Recent files

  (use-package recentf
    :config
    (run-at-time nil (* 5 60) 'recentf-save-list)
    (recentf-mode +1)
    :custom
    (recentf-max-saved-items 2048))

Frequent buffer shortcuts

  ;; Config file shortcut
  (defun my/open-init-file ()
    "Open emacs init file"
    (interactive)
    (find-file (locate-user-emacs-file "init.el")))
  (keymap-global-set "C-c w c" #'my/open-init-file)

  ;; Scratch buffer shortcut
  (keymap-global-set "C-c w x" #'scratch-buffer)

  ;; Org directory shortcut
  (with-eval-after-load 'org
    (defun my/open-org-directory ()
      (interactive)
      (find-file org-directory))
    (keymap-global-set "C-c w o" #'my/open-org-directory))

package-archive with priorities

  (when (require 'package nil :noerror)
    (add-to-list 'package-archives '("stable" . "https://stable.melpa.org/packages/"))
    (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))

    (setq package-archive-priorities '(("gnu" . 99)
                                       ("nongnu" . 80)
                                       ("stable" . 70)
                                       ("melpa" . 0))))

diminish modes

  (use-package diminish :ensure t)

Authentication

  (when (require 'auth-source nil :noerror)
    (setq auth-sources '("secrets:Login"))
    (when (require 'auth-source-pass nil :noerror)
      (auth-source-pass-enable)))

Helpful

  ;; Make `describe-*' screens more helpful
  (use-package helpful
    :ensure t
    :bind (("<remap> <describe-command>" . helpful-command)
           ("<remap> <describe-function>" . helpful-callable)
           ("<remap> <describe-key>" . helpful-key)
           ("<remap> <describe-symbol>" . helpful-symbol)
           ("<remap> <describe-variable>" . helpful-variable)
           ("C-h F" . helpful-function)
           :map helpful-mode-map
           ("<remap> <revert-buffer>" . helpful-update)))

  ;; Bind extra `describe-*' commands
  (keymap-global-set "C-h K" #'describe-keymap)

Spell checking

  ;; turn on spell checking, if available.
  (when (and (require 'ispell nil :noerror) (executable-find ispell-program-name))
    (use-package flyspell
      :ensure t
      :diminish
      :hook ((text-mode . flyspell-mode)
             (prog-mode . flyspell-prog-mode))
      :custom
      (flyspell-mode-line-string nil)
      (flyspell-use-meta-tab nil))
    (use-package flyspell-correct
      :ensure t
      :diminish
      :after flyspell
      :bind ( :map flyspell-mode-map
              ("C-;" . flyspell-correct-wrapper)))
    (use-package consult-flyspell
      :ensure t
      :diminish
      :after (consult flyspell)
      :bind ( :map flyspell-mode-map
              ("C-c s ;" . consult-flyspell))
      :config
      (setq consult-flyspell-always-check-buffer t)))

ibuffer

  (use-package ibuffer
    :ensure t
    :bind (("C-c b" . ibuffer)))

  (use-package ibuffer-project
    :ensure t
    :after ibuffer
    :hook ((ibuffer . (lambda ()
                        (setq ibuffer-filter-groups (ibuffer-project-generate-filter-groups))
                        (unless (eq ibuffer-sorting-mode 'project-file-relative)
                          (ibuffer-do-sort-by-project-file-relative))))))

whitespace-mode

  (use-package whitespace
    :custom
    (whitespace-action '(report-on-bogus
                         cleanup
                         warn-if-read-only))
    (whitespace-style '(face
                        trailing
                        tabs
                        spaces
                        lines-tail
                        newline
                        missing-newline-at-eof
                        empty
                        indentation
                        big-indent
                        space-after-tab
                        space-before-tab
                        space-mark
                        tab-mark
                        newline-mark)))

Link hint keymaps

  (use-package link-hint
    :ensure t
    :bind (("C-c l o" . link-hint-open-link)
           ("C-c l c" . link-hint-copy-link)
           ("C-c l C-o" . link-hint-open-all-link)
           ("C-c l C-c" . link-hint-copy-all-link)))

Avy keymaps

  (use-package avy
    :ensure t
    :diminish
    :bind (("C-c j j" . avy-goto-char-2)
           ("C-c j w" . avy-goto-word-0)
           ("C-c j c" . avy-goto-char)
           ("C-c j l" . avy-goto-line)))

which-func config

  (use-package which-func
    :ensure t
    :init (which-function-mode))

Shells and terminals

  (use-package shell
    :bind (("C-c t s" . shell)))

  (use-package eshell
    :bind (("C-c t e" . eshell)))

Web browser

  (use-package eww
    :defer t
    :diminish
    :custom
    (browse-url-browser-function 'browse-url-default-browser)
    (browse-url-new-window-flag t)
    (eww-default-download-directory "~/Downloads/")
    (eww-auto-rename-buffer 'title)
    (eww-browse-url-new-window-is-tab nil))