Skip to content

Latest commit

 

History

History
343 lines (257 loc) · 8.51 KB

wal-settings.org

File metadata and controls

343 lines (257 loc) · 8.51 KB

Settings

Set things up.

Confer also the eponymous functionality package if custom functionality is used.

Header

;;; wal-settings.el --- Settings. -*- lexical-binding: t -*-

;;; Commentary:
;;
;; The global settings.

;;; Code:

(eval-when-compile
  (require 'wal-useful nil t))

(declare-function scroll-bar-mode "scroll-bar.el")
(declare-function tool-bar-mode "tool-bar.el")
(declare-function wal-bytes-per-mb "wal-useful.el")
(declare-function wal-create-non-existent-directory "wal-useful.el")
(declare-function wal-increase-gc-cons-threshold "wal-useful.el")
(declare-function wal-insert "wal-useful.el")
(declare-function wal-modern-emacs-p "wal-useful.el")
(declare-function wal-persist-scratch "wal-key-bindings.el")
(declare-function wal-rehydrate-scratch "wal-key-bindings.el")
(declare-function wal-then-add-delete-trailing-whitespace-hook "wal-useful.el")
(declare-function wdb-faraway "wal-useful.el")

(defvar debugger-bury-or-kill)
(defvar display-time-default-load-average)
(defvar display-time-format)
(defvar native-comp-async-report-warnings-errors)
(defvar package-native-compile)
(defvar recentf-filename-handlers)
(defvar recentf-max-saved-items)
(defvar savehist-additional-variables)
(defvar so-long-action)
(defvar use-package-always-defer)
(defvar use-package-always-ensure)
(defvar use-package-compute-statistics)
(defvar use-package-defaults)
(defvar wal-ensure)
(defvar wal-minimal)
(defvar wal-scratch-persist--marker)
(defvar xref-search-program)

(defgroup wal-settings nil
  "Change core settings."
  :group 'wal
  :tag "Settings")

;;;; Customization:

(defcustom wal-site-lisp-directory (expand-file-name "site-lisp" user-emacs-directory)
  "Directory of site Lisp packages.

Needs to be an existing directory."
  :type 'string
  :group 'wal-settings)

(defcustom wal-scratch-persist-file (expand-file-name ".wal-scratch-persist" user-emacs-directory)
  "The file to persist the *scratch* buffer's content in."
  :type 'string
  :group 'wal-settings)

(defcustom wal-prefer-tabs nil
  "Whether tabs are preferred for indentation."
  :type 'boolean
  :group 'wal-settings)

(defcustom wal-maximize-new-frames t
  "Whether to maximize new frames by default."
  :type 'boolean
  :group 'wal-settings)

(defcustom wal-ack-warnings nil
  "Acknowledge all warnings."
  :type 'boolean
  :group 'wal-settings)

Start-Up

Customize start-up.

;; Maximize frame.
(setq frame-resize-pixelwise t)
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
(when wal-maximize-new-frames
  (add-to-list 'default-frame-alist '(fullscreen . maximized)))

;; No splash.
(setq inhibit-startup-message t)

;; Accept redefinitions.
(setq ad-redefinition-action 'accept)

;; Warn Mac/Windows users.
(unless (or (eq system-type 'gnu/linux) wal-ack-warnings)
  (warn "\
     Warning: Config only tested on Linux. The configuration may
     not work correctly on your system.

     Set `wal-ack-warnings' to t to ignore this warning."))

Packages

Add MELPA to the package archives. Most (if not all) packages will be installed from there.

;; Always defer, maybe ensure.
(setq use-package-always-defer t)

(when (or wal-flag-ensure (bound-and-true-p wal-ensure))
  (message "Ensuring packages")
  (setq use-package-always-ensure t))

(when wal-flag-doctor
  (message "Computing package statistics")
  (setq use-package-compute-statistics t)

  (declare-function use-package-report "ext:use-package.el")

  (add-hook 'after-init-hook #'use-package-report))

Directories

Prompt to ask directories if a file can’t be found.

(add-to-list 'find-file-not-found-functions #'wal-create-non-existent-directory)

Site-Lisp

Add all sub-directories of the site lisp directory to load path (and custom theme load path). I put non-MELPA packages here. You can also put additional initialization into a default.el here.

(when (and wal-site-lisp-directory
           (file-exists-p wal-site-lisp-directory))
  (let ((root (list wal-site-lisp-directory))
        (subdirs (directory-files wal-site-lisp-directory t "\\w+")))

    (dolist (project (append root subdirs))
      (when (file-directory-p project)
        (add-to-list 'load-path project)
        (add-to-list 'custom-theme-load-path project)))))

Saving and Backups

Don’t clutter up workspaces.

;; Store backups in backups folder and back up by copying.
(setq backup-directory-alist
      `(("." . ,(expand-file-name (concat user-emacs-directory "backups"))))
      backup-by-copying t)

;; Store autosaves in temp folder.
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))

;; We don't want this to mess with git.
(setq create-lockfiles nil)

Reasonable Values

Make things shorter and snappier. These settings don’t belong to packages.

(setq read-process-output-max (wal-bytes-per-mb 1)
      echo-keystrokes 0.2

      ;; Deletion.
      delete-by-moving-to-trash t

      ;; Undo limits.
      undo-limit (wal-bytes-per-mb 1)
      undo-strong-limit (wal-bytes-per-mb 1.5)
      undo-outer-limit (wal-bytes-per-mb 150)

      ;; Mouse.
      mouse-yank-at-point t

      ;; Native compilation.
      package-native-compile t
      native-comp-async-report-warnings-errors 'silent

      ;; Time.
      display-time-format " %H:%M"
      display-time-default-load-average nil
      save-interprogram-paste-before-kill t

      ;; Mark ring (halve it).
      mark-ring-max 8
      global-mark-ring-max 8

      ;; Search.
      isearch-lazy-count t
      isearch-allow-motion t
      isearch-allow-scroll t
      search-whitespace-regexp ".*?"

      ;; Parentheses.
      show-paren-delay 0.1
      show-paren-context-when-offscreen t ; New in Emacs 29.

      ;; Editing.
      backward-delete-char-untabify-method 'hungry

      ;; Recent files.
      recentf-max-saved-items 100

      ;; History.
      savehist-additional-variables '(kill-ring)

      ;; Autosaves.
      auto-save-timeout 10
      auto-save-interval 100

      ;; Buffers and windows.
      switch-to-buffer-in-dedicated-window 'prompt
      view-read-only t
      other-window-scroll-default 'wal-other-window-for-scrolling

      ;; Definitions.
      xref-search-program (if (executable-find "rg") 'ripgrep 'grep))

(setq-default tab-width 4
			  indent-tabs-mode wal-prefer-tabs)

Variables

(put 'find-sibling-rules 'safe-local-variable #'consp)

Global Modes

Any mode that should be on/off no matter what.

;; A bunch of useful modes.
(show-paren-mode 1)
(global-auto-revert-mode 1)
(save-place-mode 1)
(delete-selection-mode 1)
(column-number-mode 1)
(global-so-long-mode 1)
(savehist-mode 1)
(recentf-mode 1)
(repeat-mode 1)

;; No need for bars.
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)

;; Emacs 29.
(when (wal-modern-emacs-p 29)
  (pixel-scroll-precision-mode 1))

Garbage Collection

Increase the gc-cons-threshold after start-up.

(add-hook 'emacs-startup-hook #'wal-increase-gc-cons-threshold)

Scratch Buffer

Let’s keep the scratch contents.

(let ((package-count (length package-activated-list))
      (init-time (emacs-init-time))
      (date (format-time-string "%d/%m/%Y"))
      (marker wal-scratch-persist--marker))

  (setq initial-scratch-message (if (or wal-minimal wal-flag-mini)
                                    (format ";; Minimal %s (loaded %d packages in %s) on %s\n"
                                            marker package-count init-time date)
                                  (format ";; Normal %s on %s\n" marker date))))

(add-hook 'emacs-startup-hook #'wal-rehydrate-scratch)
(add-hook 'kill-emacs-hook #'wal-persist-scratch)

Minimize Annoyances

Make never leaving Emacs a priority.

(setq use-dialog-box nil
      disabled-command-function nil
      debugger-bury-or-kill 'kill
      use-short-answers t
      so-long-action 'so-long-minor-mode)

Buffer Display

(wdb-faraway "^\\*wal-async\\*")

Footer

(provide 'wal-settings)

;;; wal-settings.el ends here

Footnotes

[fn:1] Sometimes you have to play using other people’s rules. You can run add-dir-local-variable to do so.