Skip to content

Instantly share code, notes, and snippets.

@oliverepper
Created May 20, 2023 23:20
Show Gist options
  • Save oliverepper/7e86f010ce3db21cb5862fa0b75d8166 to your computer and use it in GitHub Desktop.
Save oliverepper/7e86f010ce3db21cb5862fa0b75d8166 to your computer and use it in GitHub Desktop.

Start

This is the literate programming version of my Emacs config. Blocks are tangled into XDG compatible config files in init.el. See Auto-tangle.

Generate init.el Header

(eval buffer-file-name)
(eval (concat (format "Emacs version: %s\n" (emacs-version))
              (format "Org version: %s" (org-version))))
;; This file is generated from <<filename()>>
;; <<version_info()>>

Start Message

(message "Loading %s" (or load-file-name buffer-file-name))

Basic Setup

Custom file (never loaded)

(setq custom-file (locate-user-emacs-file "custom.el"))

Font & Line-Spacing

(set-face-attribute 'default nil :font "JetBrains Mono:size=14")
(set-face-attribute 'fixed-pitch nil :font (face-attribute 'default :font))
(setq-default line-spacing 0.25)

Window Layout

(require 'cl-lib)
(dolist (elem
	   '(
	     (width			.	0.9)
	     (height			.	0.95)

	     (user-position		.	t)
	     (left			.	0.5)
	     (top			.	0.5)

	     (ns-transparent-titlebar	.	t)

	     (left-fringe		.	16)
	     (right-fringe		.	16)
	     ))
  (cl-pushnew elem default-frame-alist))

(tool-bar-mode	-1)
(scroll-bar-mode	-1)

package & use-package

(require 'package)
(with-eval-after-load 'package
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")))

(unless package-archive-contents
  (package-refresh-contents))

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(require 'use-package-ensure)
(setq use-package-always-ensure t)

visual-line-mode

(use-package emacs
  :config
  (global-visual-line-mode t))

global-auto-revert-mode

Automatically revert buffers when file changes on disk.

(global-auto-revert-mode t)

calendar-week-day-start

(setq calendar-week-day-start 1)

Additional Key Bindings

Some more are implemented where needed, use isearch to see them all.

Modus Themes

Setup

 (use-package modus-themes
   :demand
   :custom
   (modus-themes-to-toggle		'(modus-operandi modus-vivendi))
   (modus-themes-disable-other-themes	t)

   (modus-themes-italic-constructs	t)
   (modus-themes-variable-pitch-ui	t)
   (modus-themes-mixed-fonts		t)

   (modus-themes-prompts		'(bold))
   (modus-themes-org-blocks		'tinted-background)

   (modus-themes-headings
    '(
      (1			. (1.215))
      (2			. (1.138))
      (3			. (1.076))
      (4			. (1.0))
      (5			. (0.937))

      (agenda-date		. (variable-pitch italic 1.138))
      (agenda-structure	. (variable-pitch light 1.215))
      (t . (medium))
      ))

   (modus-themes-common-palette-overrides
    '(
      (border-mode-line-active		bg-mode-line-active)
      (border-mode-line-inactive	bg-mode-line-inactive)
      ))
   :bind ("<f5>" . modus-themes-toggle)
   :config
   (let ((last (expand-file-name "selected-theme.el" user-emacs-directory)))
     (if (file-exists-p last)
	  (load last)
	(load-theme (car modus-themes-to-toggle) :no-confirm))))

 (defun oe/save-selected-theme (theme)
   (with-temp-file (expand-file-name "selected-theme.el" user-emacs-directory)
     (insert (format "(load-theme '%s :no-confirm)\n" theme))))

Shuffle through all Modus-Themes

(defun oe/rotate-list (list)
  (when list
    (append (cdr list) (list (car list)))))

(defun oe/cycle-themes (theme-list)
  (load-theme (car theme-list) :no-confirm)
  (oe/rotate-list theme-list))

(defun oe/cycle-themes-and-print-log-msg ()
  (interactive)
  (defvar modus-themes--cycle modus-themes-items)
  (setq modus-themes--cycle (oe/cycle-themes modus-themes--cycle))
  (let ((selected-theme (car (reverse modus-themes--cycle))))
    (message "Theme: %s selected" (car (reverse modus-themes--cycle)))
    (oe/save-selected-theme selected-theme)))

(global-set-key (kbd "<f4>") #'oe/cycle-themes-and-print-log-msg)

Do Things Only When on macOS

Start Condition – macOS

(when (memq window-system '(mac ns))

Use gls instead of ls in dired

(if (executable-find "gls")
    (setq insert-directory-program "gls")
  (message "Please install GNU coreutils via `brew install coreutils`"))

Move Files to Trash

(setq delete-by-moving-to-trash			t)
(setq mac-system-move-file-to-trash-use-finder	t)

Reveal in Finder

(use-package reveal-in-osx-finder
  :commands reveal-in-osx-finder 
  :bind ("C-c f" . reveal-in-osx-finder))

End Condition - macOS

)

windmove

(global-set-key (kbd "A-<left>") #'windmove-left)
(global-set-key (kbd "A-<up>") #'windmove-up)
(global-set-key (kbd "A-<right>") #'windmove-right)
(global-set-key (kbd "A-<down>") #'windmove-down)

recentf-mode

(use-package emacs
:custom
(recentf-max-menu-items 25)
(recentf-max-saved-items 25)
:config
(recentf-mode t)
:bind ("C-c r" . #'recentf-open-files))

delight

(use-package delight
  :demand)

dumb-jump

(use-package dumb-jump
  :commands dumb-jump-xref-activate
  :init
  (add-hook 'xref-backend-functions #'dumb-jump-xref-activate))

which-key

which-key

(use-package which-key
  :demand
  :custom
  (which-key-idle-delay 0.3)
  :delight
  :config
  (which-key-mode)
  )

display-line-numbers

(use-package emacs
  :custom
  (display-line-numbers	'visual)
  (display-line-numbers-width	3))

rainbow-delimiters

rainbow-delimiters

(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))

adaptive wrap

(use-package adaptive-wrap
:custom
(adaptive-wrap-extra-indent 3)
:hook (text-mode . adaptive-wrap-prefix-mode))

vertio

(use-package vertico
  :init
  (vertico-mode))

marginalia-mode

(use-package marginalia
  :bind (:map minibuffer-local-map
		("M-A" . marginalia-cycle))
  :init
  (marginalia-mode))

Org Mode

(use-package org
  :custom 
  (org-return-follows-link	t)
  :commands (org-mode arg-agenda)
  :config
  (progn
    (require 'org-mouse))
  )

Org - Structure Templates

(with-eval-after-load 'org
  (require 'org-tempo)

  (add-to-list 'org-structure-template-alist '("el"		.	"src emacs-lisp"))
  (add-to-list 'org-structure-template-alist '("sh"		.	"src shell"))
  (add-to-list 'org-structure-template-alist '("clang"	.	"src C :includes '(stdio.h) :flags -std=c90"))
  (add-to-list 'org-structure-template-alist '("cpp"		.	"src C++ :includes '(iostream) :flags -std=c++20"))
  (add-to-list 'org-structure-template-alist '("sw"		.	"src swift"))
  (add-to-list 'org-structure-template-alist '("swui"		.	"src swiftui"))
  (add-to-list 'org-structure-template-alist '("py"		.	"src python"))
  )

Org – Auto Tangle

(defun oe/org-babel-tangle-config ()
  (let ((file-dir (file-name-directory (buffer-file-name))))
    (when (or (string-prefix-p (expand-file-name user-emacs-directory) file-dir)
              (string-prefix-p (expand-file-name "~/dotfiles/emacs/.config/emacs/") file-dir))
      (let ((org-confirm-babel-evaluate nil))
        (org-babel-tangle)))))

(add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook #'oe/org-babel-tangle-config)))

Generate init.el Footer

Done Message

(message "Done loading: %s" (or load-file-name buffer-file-name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment