326 lines
12 KiB
Org Mode
326 lines
12 KiB
Org Mode
#+TITLE: Emacs configuration
|
|
#+PROPERTY: header-args:emacs-lisp :tangle init.el
|
|
|
|
* Preface
|
|
|
|
GNU Emacs isn't a text editor, it's the ultimate productivity environment for hackers.
|
|
This document contains the core parts of my Emacs configuration which drive the workflow
|
|
I use every day.
|
|
|
|
This Emacs configuration file does use =setup.el= for package management.
|
|
|
|
* Default themes and faces
|
|
|
|
Default theme. It is needed by =early-init.el= too. In this case we have nice themed
|
|
emacs even only early-init does exist.
|
|
|
|
** Face extensions
|
|
|
|
*** Common face definitions
|
|
|
|
#+begin_src emacs-lisp :tangle ~/.emacs.d/lisp/themes/r2849-faces.el :mkdirp true
|
|
;;; -*- lexical-binding: t -*-
|
|
;;; Do not edit by hand! It is generated from readme.org.
|
|
|
|
;; -------------------------------------------------------------------------------------------------
|
|
;; common face definitions
|
|
;; -------------------------------------------------------------------------------------------------
|
|
(defface mr:operator-face
|
|
'((t (:foreground "red")))
|
|
"Face used to highlight operator characters like +, -"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:relop-face
|
|
'((t (:foreground "dodgerblue1")))
|
|
"Face used to highlight relational operator characters like <, >="
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:paren-face
|
|
'((t (:foreground "indianred")))
|
|
"Face used to highlight parentheses characters like (, ]"
|
|
:group 'mr:faces)
|
|
|
|
(defvar mr:operator-face 'mr:operator-face )
|
|
(defvar mr:relop-face 'mr:relop-face )
|
|
(defvar mr:paren-face 'mr:paren-face )
|
|
#+end_src
|
|
|
|
*** Assembly mode face definitions
|
|
|
|
#+begin_src emacs-lisp :tangle ~/.emacs.d/lisp/themes/r2849-faces.el
|
|
;; -------------------------------------------------------------------------------------------------
|
|
;; assembly mode face definitions
|
|
;; -------------------------------------------------------------------------------------------------
|
|
(defface mr:asm-comment2-face
|
|
'((t (:foreground "gray50")))
|
|
"Face used to highlight comments beginnig with ;;"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-comment3-face
|
|
'((t (:foreground "gray50")))
|
|
"Face used to highlight comments beginnig with ;;;"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-glabel-face
|
|
'((t (:foreground "sienna3")))
|
|
"Face used to highlight global labels"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-label-face
|
|
'((t (:foreground "sienna1")))
|
|
"Face used to highligh labels"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-delim-face
|
|
'((t (:foreground "firebrick")))
|
|
"Face used to highlight delimiters"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-inst-face
|
|
'((t (:foreground "DodgerBlue3")))
|
|
"Face used to highlight mnemonics"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-reg-face
|
|
'((t (:foreground "DeepSkyBlue3")))
|
|
"Face used to highlight register names"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-dir-face
|
|
'((t (:foreground "brown")))
|
|
"Face used to highlight assembler directives"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-op-face
|
|
'((t (:foreground "firebrick")))
|
|
"Face used to highlight operators"
|
|
:group 'mr:faces)
|
|
|
|
(defface mr:asm-op2-face
|
|
'((t (:foreground "CadetBlue3")))
|
|
"Face used to highlight text operators"
|
|
:group 'mr:faces)
|
|
|
|
(defvar mr:asm-comment2-face 'mr:asm-comment2-face )
|
|
(defvar mr:asm-comment3-face 'mr:asm-comment3-face )
|
|
(defvar mr:asm-glabel-face 'mr:asm-glabel-face )
|
|
(defvar mr:asm-label-face 'mr:asm-label-face )
|
|
(defvar mr:asm-delim-face 'mr:asm-delim-face )
|
|
(defvar mr:asm-inst-face 'mr:asm-inst-face )
|
|
(defvar mr:asm-reg-face 'mr:asm-reg-face )
|
|
(defvar mr:asm-dir-face 'mr:asm-dir-face )
|
|
(defvar mr:asm-op-face 'mr:asm-op-face )
|
|
(defvar mr:asm-op2-face 'mr:asm-op2-face )
|
|
#+end_src
|
|
|
|
*** Provide face
|
|
#+begin_src emacs-lisp :tangle ~/.emacs.d/lisp/themes/r2849-faces.el
|
|
(provide 'r2849-faces)
|
|
#+end_src
|
|
|
|
** Default theme
|
|
|
|
#+begin_src emacs-lisp :tangle "~/.emacs.d/lisp/themes/r2849-theme.el" :mkdirp yes
|
|
;;; -*- lexical-binding: t -*-
|
|
;;; Do not edit by hand! It is generated from readme.org.
|
|
|
|
(deftheme r2849
|
|
"Created 2023-04-13.")
|
|
|
|
(custom-theme-set-variables
|
|
'r2849
|
|
'(inhibit-startup-message t)
|
|
'(scroll-step 1)
|
|
'(truncate-lines t)
|
|
'(tool-bar-mode nil)
|
|
'(scroll-bar-mode nil)
|
|
'(column-number-mode t)
|
|
'(size-indication-mode t)
|
|
'(display-time-24hr-format t)
|
|
'(display-time-day-and-date t)
|
|
'(tab-always-indent nil)
|
|
'(scroll-bar-mode nil)
|
|
'(visible-bell nil))
|
|
|
|
(custom-set-faces
|
|
'(default
|
|
((t
|
|
(
|
|
:inherit nil
|
|
:family "RobotoMono Nerd Font Mono"
|
|
:foundry "monotype"
|
|
:stipple nil
|
|
:background "black"
|
|
:foreground "gray70"
|
|
:height 140
|
|
:weight normal
|
|
))))
|
|
|
|
;; org mode faces
|
|
'(org-document-title ((t (:height 1.50 :bold t :italic nil ))))
|
|
'(org-level-1 ((t (:height 1.20 :bold t :italic nil ))))
|
|
'(org-level-2 ((t (:height 1.10 :bold nil :italic t ))))
|
|
'(org-level-3 ((t (:height 1.05 ))))
|
|
'(org-level-4 ((t (:height 1.00 ))))
|
|
'(org-level-5 ((t (:height 1.00 ))))
|
|
'(org-level-6 ((t (:height 1.00 ))))
|
|
'(org-level-7 ((t (:height 1.00 ))))
|
|
'(org-level-8 ((t (:height 1.00 ))))
|
|
|
|
|
|
;; modeline
|
|
'(mode-line-emphasis ((t (:italic t :bold nil))))
|
|
|
|
;; doom modeline
|
|
'(doom-modeline-persp-name ((t (:inherit mode-line-emphasis :foreground "dark orange" :italic t))))
|
|
|
|
;; common progmode faces
|
|
'(font-lock-comment-face ((t (:foreground "gray50" ))))
|
|
'(font-lock-function-name-face ((t (:foreground "deep pink" ))))
|
|
'(font-lock-keyword-face ((t (:foreground "dark orange" ))))
|
|
'(font-lock-string-face ((t (:foreground "dark sea green" ))))
|
|
|
|
;; current line and line number faces
|
|
'(line-number-current-line ((t (:foreground "white" :italic nil :bold nil ))))
|
|
'(line-number ((t (:foreground "gray50" :italic nil :bold nil ))))
|
|
'(hl-line ((t (:background "gray10" ))))
|
|
)
|
|
|
|
;; Local Variables:
|
|
;; no-byte-compile: t
|
|
;; End:
|
|
|
|
(provide-theme 'r2849)
|
|
#+end_src
|
|
|
|
* Early init
|
|
|
|
Most customizations for Emacs should be put in the normal init file. However, it is sometimes
|
|
necessary to have customizations take effect during Emacs startup earlier than the normal init
|
|
file is processed. Such customizations can be put in the early init file. This file is loaded
|
|
before the package system and GUI is initialized, so in it you can customize variables that
|
|
affect the package initialization process, such as =package-enable-at-startup=, =package-load-list=,
|
|
and =package-user-dir=.
|
|
|
|
#+begin_src emacs-lisp :tangle early-init.el
|
|
;;; -*- lexical-binding: t -*-
|
|
;;; Do not edit by hand! It is generated from readme.org.
|
|
|
|
;;; Disable package.el in favor of straight.el
|
|
;;; Do not allow loading from the package cache.
|
|
(setq package-enable-at-startup nil)
|
|
(setq package-quickstart nil)
|
|
|
|
;;; Make startup faster by reducing the frequency of garbage collection and then use a hook to
|
|
;;; measure Emacs startup time. After init, restore the default garbage collection parameters.
|
|
(let ((default-gc-threshold gc-cons-threshold)
|
|
(default-gc-percentage gc-cons-percentage))
|
|
(setq gc-cons-threshold most-positive-fixnum
|
|
gc-cons-percentage 0.8)
|
|
(add-hook 'after-init-hook
|
|
(lambda ()
|
|
(setq gc-cons-percentage default-gc-percentage
|
|
gc-cons-threshold default-gc-threshold))))
|
|
|
|
;;; profile emacs startup
|
|
(add-hook 'emacs-startup-hook
|
|
(lambda ()
|
|
(message "*** Emacs loaded in %s seconds with %d garbage collections."
|
|
(emacs-init-time "%.2f")
|
|
gcs-done)))
|
|
|
|
;;; Prevent unwanted runtime builds in gccemacs (native-comp); packages are compiled
|
|
;;; ahead-of-time when they are installed and site files are compiled when gccemacs
|
|
;;; is installed.
|
|
(setq comp-deferred-compilation nil)
|
|
|
|
;;; Prevent the glimpse of un-styled Emacs by disabling these UI elements early.
|
|
(push '(menu-bar-lines . 0) default-frame-alist)
|
|
(push '(tool-bar-lines . 0) default-frame-alist)
|
|
(push '(vertical-scroll-bars) default-frame-alist)
|
|
|
|
;;; Resizing the Emacs frame can be a terribly expensive part of changing the font. By inhibiting
|
|
;;; this, we easily halve startup times with fonts that are larger than the system default.
|
|
(setq frame-inhibit-implied-resize t)
|
|
|
|
;;; disable GUI elements
|
|
(menu-bar-mode -1)
|
|
(tool-bar-mode -1)
|
|
(scroll-bar-mode -1)
|
|
|
|
(setq inhibit-splash-screen t)
|
|
(setq use-file-dialog nil)
|
|
|
|
;;; Default coding system
|
|
(prefer-coding-system 'utf-8)
|
|
(set-default-coding-systems 'utf-8)
|
|
(set-terminal-coding-system 'utf-8)
|
|
(set-keyboard-coding-system 'utf-8)
|
|
(setq buffer-file-coding-system 'utf-8)
|
|
|
|
;;; Default frame size
|
|
(add-to-list 'default-frame-alist '(height . 45))
|
|
(add-to-list 'default-frame-alist '(width . 160))
|
|
|
|
;;; Include paths
|
|
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp" ))
|
|
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/themes" ))
|
|
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/progmodes" ))
|
|
|
|
;;; Theme paths
|
|
(add-to-list 'custom-theme-load-path
|
|
(expand-file-name "~/.emacs.d/lisp/themes"))
|
|
|
|
;;; tab-bar-mode is incompatible with perspective (as of 2023-05) so do not enable it.
|
|
;;; (setq tab-bar-format '(tab-bar-format-global))
|
|
;;; (tab-bar-mode)
|
|
|
|
(setq tab-width 4)
|
|
|
|
;;; Do not appear a bunch of transient files as untracked in the Git/Plastic repo so
|
|
;;; move them all to another location.
|
|
;;;
|
|
;;; Change the user-emacs-directory to keep unwanted things out of ~/.emacs.d
|
|
(setq user-emacs-directory (expand-file-name "~/.cache/emacs/")
|
|
url-history-file (expand-file-name "url/history" user-emacs-directory))
|
|
|
|
;;; Set the cache folder for native compiled files.
|
|
(when (boundp 'native-comp-eln-load-path)
|
|
(startup-redirect-eln-cache (expand-file-name "eln-cache" user-emacs-directory)))
|
|
|
|
;;; Bootstrap feature =straight= to install no-littering which is needed to keep clean .emacs.d
|
|
;;; It should install itself into the redefined user-emacs-directory !
|
|
|
|
(unless (featurep 'straight)
|
|
;; Bootstrap straight.el
|
|
(defvar bootstrap-version)
|
|
(let ((bootstrap-file
|
|
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
|
|
(bootstrap-version 5))
|
|
(unless (file-exists-p bootstrap-file)
|
|
(with-current-buffer
|
|
(url-retrieve-synchronously
|
|
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
|
|
'silent 'inhibit-cookies)
|
|
(goto-char (point-max))
|
|
(eval-print-last-sexp)))
|
|
(load bootstrap-file nil 'nomessage)))
|
|
|
|
;;; Use straight.el for use-package expressions
|
|
(straight-use-package 'use-package)
|
|
|
|
;;; Use no-littering to automatically set common paths to the new user-emacs-directory.
|
|
;;; Load the feature =no-littering= as early as possible. Make sure it is loaded at least
|
|
;;; before any path variables are changed using some other methods.
|
|
(straight-use-package 'no-littering)
|
|
(require 'no-littering)
|
|
|
|
;;; Customizations must be in a separate file not in the user initialization script (init.el).
|
|
(setq custom-file (locate-user-emacs-file "custom.el"))
|
|
(load custom-file 'noerror 'nomessage)
|
|
|
|
;;; Load theme as soon as possible
|
|
(setq custom-safe-themes t)
|
|
(load-theme 'r2849)
|
|
#+end_src
|