home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

init.el (9952B)


      1 ;;; init.el --- init configuration file -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (c) 2020-2023  Vincent Demeester <vincent@sbr.pm>
      4 
      5 ;; Author: Vincent Demeester <vincent@sbr.pm>
      6 ;; URL: https://git.sr.ht/~vdemeester/home
      7 ;; Version: 0.1.0
      8 ;; Package-Requires: ((emacs "29.1"))
      9 
     10 ;; This file is NOT part of GNU Emacs.
     11 
     12 ;; This file is free software: you can redistribute it and/or modify it
     13 ;; under the terms of the GNU General Public License as published by the
     14 ;; Free Software Foundation, either version 3 of the License, or (at
     15 ;; your option) any later version.
     16 ;;
     17 ;; This file is distributed in the hope that it will be useful, but
     18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
     19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     20 ;; General Public License for more details.
     21 ;;
     22 ;; You should have received a copy of the GNU General Public License
     23 ;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
     24 
     25 ;;; Commentary:
     26 
     27 ;; See my dotfiles: https://git.sr.ht/~vdemeester/home
     28 
     29 ;;; Code:
     30 
     31 
     32 (defconst emacs-start-time (current-time))
     33 
     34 (let ((minver 28))
     35   (unless (>= emacs-major-version minver)
     36     (error "Your Emacs is too old -- this configuration requires v%s or higher" minver)))
     37 
     38 (add-to-list 'load-path (concat user-emacs-directory "/lisp/"))
     39 
     40 (setq inhibit-default-init t)           ; Disable the site default settings
     41 
     42 (setq confirm-kill-emacs #'y-or-n-p)
     43 (setq initial-major-mode 'fundamental-mode
     44       initial-scratch-message nil)
     45 
     46 (prefer-coding-system 'utf-8)
     47 (set-default-coding-systems 'utf-8)
     48 (set-language-environment 'utf-8)
     49 (set-selection-coding-system 'utf-8)
     50 (set-terminal-coding-system 'utf-8)
     51 
     52 (unless noninteractive
     53   (defconst font-height 130
     54     "Default font-height to use.")
     55   ;; 2024-10-05: Switching from Ubuntu Mono to Cascadia Mono
     56   ;; 2024-96-06: Switching from Cascadia Mono to JetBrains Mono
     57   (defconst font-family-mono "JetBrains Mono"
     58     "Default monospace font-family to use.")
     59   (defconst font-family-sans "Ubuntu Sans"
     60     "Default sans font-family to use.")
     61   ;; Middle/Near East: שלום, السّلام عليكم
     62   (when (member "Noto Sans Arabic" (font-family-list))
     63     (set-fontset-font t 'arabic "Noto Sans Arabic"))
     64   (when (member "Noto Sans Hebrew" (font-family-list))
     65     (set-fontset-font t 'arabic "Noto Sans Hebrew"))
     66   ;; Africa: ሠላም
     67   (when (member "Noto Sans Ethiopic" (font-family-list))
     68     (set-fontset-font t 'ethiopic "Noto Sans Ethiopic"))
     69 
     70   ;; If font-family-mono or font-family-sans are not available, use the default Emacs face
     71     (set-face-attribute 'default nil
     72 			:family font-family-mono
     73 			:height font-height
     74 			:weight 'regular)
     75     (set-face-attribute 'fixed-pitch nil
     76 			:family font-family-mono
     77 			:weight 'medium
     78 			:height font-height)
     79     (set-face-attribute 'variable-pitch nil
     80 			:family font-family-sans
     81 			:weight 'regular)
     82 
     83   (set-fontset-font t 'symbol "Apple Color Emoji")
     84   (set-fontset-font t 'symbol "Noto Color Emoji" nil 'append)
     85   (set-fontset-font t 'symbol "Segoe UI Emoji" nil 'append)
     86   (set-fontset-font t 'symbol "Symbola" nil 'append)
     87 
     88 (defvar contrib/after-load-theme-hook nil
     89   "Hook run after a color theme is loaded using `load-theme'.")
     90 
     91 (defun contrib/run-after-load-theme-hook (&rest _)
     92   "Run `contrib/after-load-theme-hook'."
     93   (run-hooks 'contrib/after-load-theme-hook))
     94 
     95 (mapc
     96  (lambda (string)
     97    (add-to-list 'load-path (locate-user-emacs-file string)))
     98  '("lisp" "config"))
     99 
    100 (advice-add #'load-theme :after #'contrib/run-after-load-theme-hook)
    101 
    102 (require 'modus-themes)
    103 (setq modus-themes-to-toggle '(modus-operandi modus-vivendi)
    104       modus-themes-slanted-constructs nil
    105       modus-themes-italic-constructs nil
    106       modus-themes-bold-constructs nil
    107       modus-themes-mixed-fonts t
    108       modus-themes-subtle-diffs t
    109       modus-themes-fringes 'subtle ; {nil,'subtle,'intense}
    110       modus-themes-headings '((0 . (variable-pitch semilight 1.5))
    111 			      (1 . (regular 1.4))
    112 			      (2 . (regular 1.3))
    113 			      (3 . (regular 1.2))
    114 			      (agenda-structure . (variable-pitch light 2.2))
    115 			      (agenda-date . (variable-pitch regular 1.3))
    116 			      (t . (regular 1.15)))
    117       modus-themes-intense-paren-match t
    118       modus-themes-completions '(opinionated) ; {nil,'moderate,'opinionated}
    119       modus-themes-diffs 'desaturated ; {nil,'desaturated,'fg-only}
    120       modus-themes-org-blocks 'gray-background
    121       modus-themes-paren-match '(subtle-bold)
    122       modus-themes-variable-pitch-headings nil
    123       modus-themes-rainbow-headings t
    124       modus-themes-section-headings nil
    125       modus-themes-scale-headings t
    126       )
    127 (define-key global-map (kbd "C-<f5>") #'modus-themes-toggle)
    128 
    129 (load-theme 'modus-operandi :no-confirm))
    130 
    131 (require 'init-func)
    132 
    133 (defconst *sys/gui*
    134   (display-graphic-p)
    135   "Are we running on a GUI Emacs ?")
    136 (defconst *sys/linux*
    137   (eq system-type 'gnu/linux)
    138   "Are we running on a GNU/Linux system?")
    139 (defconst *sys/mac*
    140   (eq system-type 'darwin)
    141   "Are we running on a Mac system?")
    142 (defconst *sys/root*
    143   (string-equal "root" (getenv "USER"))
    144   "Are you a ROOT user?")
    145 (defconst *nix*
    146   (executable-find "nix")
    147   "Do we have nix? (aka are we running in NixOS or a system using nixpkgs).")
    148 (defconst *rg*
    149   (executable-find "rg")
    150   "Do we have ripgrep?")
    151 (defconst *gcc*
    152   (executable-find "gcc")
    153   "Do we have gcc?")
    154 (defconst *git*
    155   (executable-find "git")
    156   "Do we have git?")
    157 
    158 (defvar *sys/full*
    159   (member (vde/short-hostname) '("wakasu" "naruhodo"))
    160   "Is it a full system ?")
    161 (defvar *sys/light*
    162   (not *sys/full*)
    163   "Is it a light system ?")
    164 
    165 ;; (require 'package)
    166 ;; (setq package-archives nil) ;; To rely only on packages from nix
    167 ;; (setq package-archives
    168 ;;       '(("melpa" . "http://melpa.org/packages/")
    169 ;;         ("org" . "https://orgmode.org/elpa/")
    170 ;;         ("gnu" . "https://elpa.gnu.org/packages/")
    171 ;; 	("nongnu" . "https://elpa.nongnu.org/nongnu/")))
    172 ;; 
    173 ;; (setq package-archive-priorities
    174 ;;       '(("melpa" .  4)
    175 ;;         ("org" . 3)
    176 ;;         ("gnu" . 2)
    177 ;; 	("non-gnu" . 1)))
    178 
    179 ;; (require 'tls)
    180 ;; 
    181 ;; ;; From https://github.com/hlissner/doom-emacs/blob/5dacbb7cb1c6ac246a9ccd15e6c4290def67757c/core/core-packages.el#L102
    182 ;; (setq gnutls-verify-error (not (getenv "INSECURE")) ; you shouldn't use this
    183 ;;       tls-checktrust gnutls-verify-error
    184 ;;       tls-program (list "gnutls-cli --x509cafile %t -p %p %h"
    185 ;;                         ;; compatibility fallbacks
    186 ;;                         "gnutls-cli -p %p %h"
    187 ;;                         "openssl s_client -connect %h:%p -no_ssl2 -no_ssl3 -ign_eof"))
    188 
    189 ;; Initialise the packages, avoiding a re-initialisation.
    190 ;; (unless (bound-and-true-p package--initialized)
    191 ;;   (setq package-enable-at-startup nil)
    192 ;;   (package-initialize))
    193 
    194 (setq load-prefer-newer t)              ; Always load newer compiled files
    195 (setq ad-redefinition-action 'accept)   ; Silence advice redefinition warnings
    196 
    197 ;; Init `delight'
    198 ;; (unless (package-installed-p 'delight)
    199 ;;   (package-refresh-contents)
    200 ;;   (package-install 'delight))
    201 
    202 ;; Configure `use-package' prior to loading it.
    203 (eval-and-compile
    204   (setq use-package-always-ensure nil)
    205   (setq use-package-always-defer nil)
    206   (setq use-package-always-demand nil)
    207   (setq use-package-expand-minimally nil)
    208   (setq use-package-enable-imenu-support t))
    209 
    210 ;; (unless (package-installed-p 'use-package)
    211 ;;   (package-refresh-contents)
    212 ;;   (package-install 'use-package))
    213 
    214 (eval-when-compile
    215   (require 'use-package))
    216 
    217 (setenv "SSH_AUTH_SOCK" "/run/user/1000/gnupg/S.gpg-agent.ssh")
    218 
    219 (defconst vde/custom-file (locate-user-emacs-file "custom.el")
    220   "File used to store settings from Customization UI.")
    221 
    222 ;; Remove built-in org-mode
    223 (require 'cl-seq)
    224 (setq load-path
    225       (cl-remove-if
    226        (lambda (x)
    227          (string-match-p "org$" x))
    228        load-path))
    229 
    230 ;; 2024-07-12: I wonder if I should be explicit instead, as using
    231 ;; `require' explicitly. The benefit would be that I decide the order
    232 ;; they load instead of relying on file-system.
    233 ;; (vde/el-load-dir (concat user-emacs-directory "/config/"))
    234 (require 'org-func)
    235 (require 'project-func)
    236 
    237 ;; Make native compilation silent and prune its cache.
    238 (when (native-comp-available-p)
    239   (setq native-comp-async-report-warnings-errors 'silent) ; Emacs 28 with native compilation
    240   (setq native-compile-prune-cache t)) ; Emacs 29
    241 
    242 ;; Refactor this completely. Reduce to the minimum.
    243 (require '00-base)
    244 (require '00-clean) ;; Maybe refactor no-littering
    245 (unless noninteractive
    246   (require 'config-appearance)
    247   (require 'config-buffers)
    248   (require 'config-compile)
    249   (require 'config-completion)
    250   (require 'config-dired)
    251   (require 'config-mouse)
    252   (require 'config-navigating)
    253   (require 'config-org)
    254   (require 'config-programming)
    255   (require 'config-projects)
    256   (require 'config-search)
    257   (require 'config-shells)
    258   (require 'config-vcs)
    259   (require 'config-web)
    260   (require 'config-windows)
    261   (require 'programming-config)
    262   (require 'programming-containers)
    263   (require 'programming-cue)
    264   (require 'programming-elisp)
    265   (require 'programming-eglot)
    266   (require 'programming-go)
    267   (require 'programming-js)
    268   (require 'programming-nix)
    269   (require 'programming-treesitter)
    270   (require 'programming-web))
    271 (require 'config-editing)
    272 (require 'config-files)
    273 (require 'config-keybindings)
    274 (require 'config-misc)
    275 
    276 (if (file-exists-p (downcase (concat user-emacs-directory "/hosts/" (vde/short-hostname) ".el")))
    277     (load-file (downcase (concat user-emacs-directory "/hosts/" (vde/short-hostname) ".el"))))
    278 
    279 (let ((elapsed (float-time (time-subtract (current-time)
    280                                           emacs-start-time))))
    281   (message "Loading %s...done (%.3fs)" load-file-name elapsed))
    282 
    283 (add-hook 'after-init-hook
    284           `(lambda ()
    285              (let ((elapsed
    286                     (float-time
    287                      (time-subtract (current-time) emacs-start-time))))
    288                (message "Loading %s...done (%.3fs) [after-init]"
    289                         ,load-file-name elapsed))) t)