#+TITLE: General settings #+AUTHOR: MichaƂ Sapka (https://michal.sapka.me) #+DATE: 2024-02-08 #+STARTUP: showall indent logdone #+HUGO_SECTION: emacs/config #+EXPORT_FILE_NAME: configuration #+HUGO_BASE_DIR: ~/ghq/vcs.sapka.me/michal-sapka-me/ #+HUGO_WEIGHT: 10 #+HUGO_CATEGORIES: emacs emacs-config #+HUGO_MENU: :menu "emacs-config" :name "Genral settings" #+HUGO_CUSTOM_FRONT_MATTER: :abstract "My emacs config - general config" #+HUGO_CUSTOM_FRONT_MATTER: :menu-abstract "Just some basic stuff" This file sets generic things around my Emacs config. All other files rely on this. * Lexical binding #+BEGIN_SRC emacs-lisp ;;; -*- lexical-binding: t -*- #+END_SRC * Basic configuration I want to use UTF-8 everywhere #+BEGIN_SRC emacs-lisp (prefer-coding-system 'utf-8) (set-default-coding-systems 'utf-8) (set-language-environment "UTF-8") (setq require-final-newline t) #+END_SRC Emacs has this terrible habbit of wanting to write "yes" or "no" to confirm different things. This changes it to simple "y" and "n" #+begin_src emacs-lisp (setopt use-short-answers t) #+end_src I will save a lot files in my temporary filder. #+begin_src emacs-lisp (defvar mms-tmp-dir "~/tmp") (make-directory mms-tmp-dir t) #+end_src I don't want to pollute each and every one of my folders, so I'm keeping all backup files in one place. On each of my systems I have a =~/tmp= folder just for custom temporary file. #+begin_src emacs-lisp (setq backup-directory-alist `((".*" . ,mms-tmp-dir))) (setq auto-save-file-name-transforms `((".*" ,mms-tmp-dir t))) #+end_src Tramp can get /even slower/ with file locks, so I disable those Or at least this is what I've been told. #+begin_src emacs-lisp (setq remote-file-name-inhibit-locks t) #+end_src Tabs, what are they good for? Absolutelly nothing! Let's use spaces everywhere #+begin_src emacs-lisp (setq-default indent-tabs-mode nil) #+end_src Stop Emacs from using =audible bell= #+begin_src emacs-lisp (setq ring-bell-function (lambda () (let ((orig-fg (face-foreground 'mode-line))) (set-face-foreground 'mode-line "#F2804F") (run-with-idle-timer 0.1 nil (lambda (fg) (set-face-foreground 'mode-line fg)) orig-fg)))) #+end_src * Package management Recently, I have migrated to Elpaca. A lot of emacsers tend to use Straight, but Elpaca seems more modern with asynchronous loading of packages. This, of course, is a can of worms. #+BEGIN_SRC emacs-lisp (defvar elpaca-installer-version 0.7) (defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory)) (defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory)) (defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory)) (defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git" :ref nil :depth 1 :files (:defaults "elpaca-test.el" (:exclude "extensions")) :build (:not elpaca--activate-package))) (let* ((repo (expand-file-name "elpaca/" elpaca-repos-directory)) (build (expand-file-name "elpaca/" elpaca-builds-directory)) (order (cdr elpaca-order)) (default-directory repo)) (add-to-list 'load-path (if (file-exists-p build) build repo)) (unless (file-exists-p repo) (make-directory repo t) (when (< emacs-major-version 28) (require 'subr-x)) (condition-case-unless-debug err (if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*")) ((zerop (apply #'call-process `("git" nil ,buffer t "clone" ,@(when-let ((depth (plist-get order :depth))) (list (format "--depth=%d" depth) "--no-single-branch")) ,(plist-get order :repo) ,repo)))) ((zerop (call-process "git" nil buffer t "checkout" (or (plist-get order :ref) "--")))) (emacs (concat invocation-directory invocation-name)) ((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch" "--eval" "(byte-recompile-directory \".\" 0 'force)"))) ((require 'elpaca)) ((elpaca-generate-autoloads "elpaca" repo))) (progn (message "%s" (buffer-string)) (kill-buffer buffer)) (error "%s" (with-current-buffer buffer (buffer-string)))) ((error) (warn "%s" err) (delete-directory repo 'recursive)))) (unless (require 'elpaca-autoloads nil t) (require 'elpaca) (elpaca-generate-autoloads "elpaca" repo) (load "./elpaca-autoloads"))) (add-hook 'after-init-hook #'elpaca-process-queues) (elpaca `(,@elpaca-order)) #+end_src #+begin_src emacs-lisp (elpaca elpaca-use-package ;; Enable :elpaca use-package keyword. (elpaca-use-package-mode) ;; Assume :elpaca t unless otherwise specified. (setq elpaca-use-package-by-default t)) #+end_src We need to wait here for elpaca to actually load. We will see this pattern again. #+begin_src emacs-lisp (elpaca-wait) #+end_src * Auto-complete in minibuffer Having autocomplete in emacs is one of most important things. I've used =ido= before, but now I'm trying =vertico=. I don't want a big plugin here, like helm. I left the optional params here from the tutorial in case I want to get /fancy/. #+begin_src emacs-lisp (use-package vertico :init (vertico-mode) ;; Different scroll margin ;; (setq vertico-scroll-margin 0) ;; Show more candidates ;; (setq vertico-count 20) ;; Grow and shrink the Vertico minibuffer ;; (setq vertico-resize t) ) #+end_src Marginalia adds extra information to the list #+begin_src emacs-lisp (use-package marginalia :init (marginalia-mode)) #+end_src * Variables I use two machines on different OSes (personal on FreeBSD and work on MacOS). On a few occasions, I will use device to use correct behavior. #+begin_src emacs-lisp (setq mms-is-voyager (string= (system-name) "voyager.local")) (setq mms-is-mac (string= (system-name) "RN90Y7RDHT")) #+end_src * Line numbering Most of the time, I want my line numbers. I use Evil after all. But sometimes they are not needed. #+begin_src emacs-lisp (defun mms-hide-line-numbers() (interactive) (display-line-numbers-mode 0)) #+end_src * Allow for diminished mode Emacs is based od modes which may pollute the modeline. Dimish will hide them from the modeline, even if they are enabled. #+begin_src emacs-lisp (use-package diminish :ensure t) #+end_src * Transistent #+begin_src emacs-lisp (use-package transient :ensure t) #+end_src * Secrets #+begin_src emacs-lisp (setq auth-sources '((:source "~/.authinfo.gpg"))) #+end_src #+RESULTS: | :source | ~/.authinfo.gpg | * Tests #+begin_src emacs-lisp ;; (use-package ready-player ;; : ;; ensure t) #+end_src * * Dired #+begin_src emacs-lisp (setq dired-dwim-target "yes") #+end_src