Created
January 9, 2024 15:15
-
-
Save dsalychev/085400b673c5f3c070683f987c14e118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ----------------- 1. Startup and Runtime Performance ------------------------ | |
;; NOTE: https://config.daviwil.com/emacs | |
;; Make startup faster by reducing the frequency of garbage collection and then | |
;; use a hook to measure Emacs startup time. | |
;; The default is 800 kilobytes. Measured in bytes. | |
(setq gc-cons-threshold (* 50 1000 1000)) | |
;; Profile emacs startup | |
(add-hook 'emacs-startup-hook | |
(lambda () | |
(message "Emacs loaded in %s with %d garbage collections." | |
(format "%.2f seconds" | |
(float-time | |
(time-subtract after-init-time before-init-time))) | |
gcs-done))) | |
;; Dial the GC threshold back down so that garbage collection happens more | |
;; frequently but in less time. | |
;; Make gc pauses faster by decreasing the threshold. | |
(setq gc-cons-threshold (* 2 1000 1000)) | |
;; ----------------- 2. Package Management ------------------------------------- | |
;; Initialize package repositories | |
(require 'package) | |
(setq package-archives '( | |
("melpa" . "https://melpa.org/packages/") | |
("melpa-stable" . "https://stable.melpa.org/packages/") | |
("org" . "https://orgmode.org/elpa/") | |
("elpa" . "https://elpa.gnu.org/packages/") | |
) | |
) | |
(package-initialize) | |
;; Initialize use-package | |
(unless (package-installed-p 'use-package) | |
(package-refresh-contents) | |
(package-install 'use-package)) | |
(eval-when-compile | |
(require 'use-package)) | |
;; Setting use-package-always-ensure to "true" saves us the trouble of having | |
;; to specify :ensure t in any future packages we’d like to declare and install. | |
;; | |
;; The :ensure macro basically makes sure that the packages are correctly | |
;; installed at every startup, and automatically installs the missing ones | |
;; for you. This is extremely useful when you frequently move between different | |
;; machines and need to port your entire Emacs config over to a new setup. | |
(eval-and-compile | |
(setq use-package-always-ensure t | |
use-package-expand-minimally t)) | |
;; Uncomment this to get a reading on packages that get loaded at startup | |
;;(setq use-package-verbose t) | |
;; ----------------- 3. Keep .emacs.d clean ------------------------------------ | |
;; 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)) | |
;; Use no-littering to automatically set common paths to the new user-emacs-directory | |
(use-package no-littering) | |
;; Keep customization settings in a temporary file (thanks Ambrevar!) | |
;; (setq custom-file | |
;; (if (boundp 'server-socket-dir) | |
;; (expand-file-name "custom.el" server-socket-dir) | |
;; (expand-file-name (format "emacs-custom-%s.el" (user-uid)) temporary-file-directory))) | |
;; (load custom-file t) | |
;; ----------------- 4. Update Load Path --------------------------------------- | |
;; Add my library path to load-path | |
(push "~/.emacs.d/elisp" load-path) | |
;; FreeBSD-specific path | |
(push "/usr/local/share/emacs/site-lisp" load-path) | |
;; ----------------- 5. Default Coding System ---------------------------------- | |
(set-default-coding-systems 'utf-8) | |
;; ----------------- 6. Server Mode -------------------------------------------- | |
;; Start the Emacs server from this instance so that all emacsclient calls are | |
; routed here. | |
(server-start) | |
;; ----------------- 7. Packages Configuration --------------------------------- | |
(use-package highlight-parentheses) | |
(use-package dracula-theme) | |
(use-package magit | |
:defer 10) | |
(use-package unicode-fonts) | |
(use-package persistent-soft ; to cache fonts and reduce load time | |
:after unicode-fonts | |
:config | |
(unicode-fonts-setup)) | |
(use-package nhexl-mode) | |
(use-package all-the-icons) | |
;; Say I want to turn on the visualization of matching parentheses. That is, | |
;; when my cursor stops at a parenthesis/bracket/brace, the matching instance on | |
;; the other end is highlighted. | |
;; | |
;; This requires tweaking the “paren” package, which is a built-in package in | |
;; Emacs already. To prevent use-package from looking for the paren package in | |
;; the internet archives, we turn off the :ensure flag. Then, in | |
;; the :config section, we specify the desired show-paren-mode. | |
(use-package paren | |
:ensure nil ;; built-in package, don't search in the repos | |
:config | |
(show-paren-mode +1)) | |
;; OpenBSD KNF style for C/C++: https://github.com/hogand/openbsd-knf-emacs | |
(use-package openbsd-knf-style | |
:ensure nil ;; no package in the public repos yet :( | |
:config | |
(c-add-style "OpenBSD" openbsd-knf-style) | |
(setq c-default-style '((c-mode . "OpenBSD"))) | |
;; In the modeline, show which function you're currently in. | |
(add-hook 'c-mode-common-hook | |
(lambda () | |
(when (derived-mode-p 'c-mode 'c++-mode 'java-mode) | |
(which-function-mode 1))))) | |
;; Jornaling with org-journal: https://github.com/bastibe/org-journal | |
(use-package org-journal | |
:ensure t | |
:defer t | |
:init | |
;; Change default prefix key; needs to be set before loading org-journal | |
(setq org-journal-prefix-key "C-c j ") | |
:config | |
(setq org-journal-dir "~/journal/")) | |
;; Configure whitespace package. | |
(use-package whitespace | |
:ensure nil ;; built-in package, don't search in the repos | |
:config | |
(setq-default show-trailing-whitespace t)) | |
;; Single Dired buffer: https://github.com/crocket/dired-single | |
(use-package dired-single | |
:config | |
(defun my-dired-init () | |
"Bunch of stuff to run for dired, either immediately or when it's | |
loaded." | |
;; <add other stuff here> | |
(define-key dired-mode-map [remap dired-find-file] | |
'dired-single-buffer) | |
(define-key dired-mode-map [remap dired-mouse-find-file-other-window] | |
'dired-single-buffer-mouse) | |
(define-key dired-mode-map [remap dired-up-directory] | |
'dired-single-up-directory)) | |
;; if dired's already loaded, then the keymap will be bound | |
(if (boundp 'dired-mode-map) | |
;; we're good to go; just add our bindings | |
(my-dired-init) | |
;; it's not loaded yet, so add our bindings to the load-hook | |
(add-hook 'dired-load-hook 'my-dired-init))) | |
;; Emacs Neotree config: https://github.com/jaypei/emacs-neotree | |
(use-package neotree | |
:config | |
(global-set-key [f8] 'neotree-toggle) | |
(setq neo-theme (if (display-graphic-p) 'icons 'arrow))) | |
(use-package helm | |
:init | |
(setq helm-command-prefix-key "C-c h") | |
(setq helm-semantic-fuzzy-match t | |
helm-imenu-fuzzy-match t) | |
(setq helm-candidate-number-limit 1000) | |
:config | |
;; (define-key helm-map (kbd "C-c h o") 'helm-semantic-or-imenu) | |
(helm-mode 1)) | |
;; GNU GLOBAL helm interface: https://github.com/emacsorphanage/helm-gtags | |
(use-package helm-gtags | |
:after helm | |
:init | |
(setq helm-gtags-ignore-case t | |
helm-gtags-auto-update t | |
helm-gtags-use-input-at-cursor t | |
helm-gtags-pulse-at-cursor t | |
helm-gtags-prefix-key "\C-cg" | |
helm-gtags-suggested-key-mapping t) | |
(add-hook 'dired-mode-hook 'helm-gtags-mode) | |
(add-hook 'eshell-mode-hook 'helm-gtags-mode) | |
(add-hook 'c-mode-hook 'helm-gtags-mode) | |
(add-hook 'c++-mode-hook 'helm-gtags-mode) | |
(add-hook 'asm-mode-hook 'helm-gtags-mode) | |
:config | |
(define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function) | |
(define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select) | |
(define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim) | |
(define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack) | |
(define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history) | |
(define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history)) | |
;; fill-column-indicator: https://www.emacswiki.org/emacs/FillColumnIndicator | |
(use-package fill-column-indicator | |
:config | |
(setq fci-rule-column 80) | |
(setq fci-rule-color "#373844") | |
(define-globalized-minor-mode global-fci-mode fci-mode | |
(lambda () | |
(if (and | |
(not (string-match "^\*.*\*$" (buffer-name))) | |
(not (eq major-mode 'dired-mode)) | |
(not (eq major-mode 'neotree-mode)) | |
(not (eq major-mode 'magit-mode))) | |
(fci-mode 1)))) | |
(global-fci-mode 1)) | |
;; ibuffer-vc: https://github.com/purcell/ibuffer-vc | |
(use-package ibuffer-vc | |
:config | |
(global-set-key (kbd "C-x C-b") 'ibuffer) | |
(add-hook 'ibuffer-hook | |
(lambda () | |
(ibuffer-vc-set-filter-groups-by-vc-root) | |
(unless (eq ibuffer-sorting-mode 'alphabetic) | |
(ibuffer-do-sort-by-alphabetic))))) | |
;; centaur-tabs: https://github.com/ema2159/centaur-tabs | |
;; (use-package centaur-tabs | |
;; :config | |
;; (centaur-tabs-mode t) | |
;; (centaur-tabs-headline-match) | |
;; (global-set-key (kbd "C-<prior>") 'centaur-tabs-backward) | |
;; (global-set-key (kbd "C-<next>") 'centaur-tabs-forward) | |
;; (setq centaur-tabs-style "bar") | |
;; (setq centaur-tabs-height 28) | |
;; (setq centaur-tabs-set-icons t) | |
;; (setq centaur-tabs-gray-out-icons 'buffer) | |
;; (setq centaur-tabs-set-modified-marker t) | |
;; (setq centaur-tabs-modified-marker "*") | |
;; (setq centaur-tabs-set-close-button nil) | |
;; (put 'upcase-region 'disabled nil) | |
;; (put 'downcase-region 'disabled nil)) | |
;; searching options: https://www.djcbsoftware.nl/code/mu/mu4e/Searching.html | |
;; mu4e-headers-results-limit (default: 500) | |
;; mu4e-headers-full-search (or mu4e-headers-toggle-property) | |
(use-package mu4e | |
:ensure nil ; installed using FreeBSD's pkg | |
:defer 5 ; postpone loading by 5s | |
:init | |
(setq mu4e-view-show-images nil) | |
:config | |
;; Load org-mode integration | |
(require 'org-mu4e) | |
;; Refresh mail using isync every 30 minutes | |
(setq mu4e-update-interval (* 30 60)) | |
(setq mu4e-index-update-in-background t) | |
(setq mu4e-get-mail-command "mbsync -a") | |
(setq mu4e-maildir "~/mail") | |
;; prefer plain text during rendering | |
(setq mu4e-view-prefer-html nil) | |
;; w3m should be installed beforehand | |
(setq mu4e-html2text-command "w3m -dump -T text/html -o display_link_number=true") | |
(setq mu4e-view-html-plaintext-ratio-heuristic most-positive-fixnum) | |
;; Do NOT render HTML colors | |
(setq shr-use-colors nil) | |
;; Make sure that moving a message (like to Trash) causes the | |
;; message to get a new file name. This helps to avoid the | |
;; dreaded "UID is N beyond highest assigned" error. | |
;; See this link for more info: https://stackoverflow.com/a/43461973 | |
(setq mu4e-change-filenames-when-moving t) | |
;; Show all search results (not only limited by default) | |
;;(setq mu4e-headers-full-search t) | |
;; Configure the function to use for sending mail | |
;; NOTE: mail/msmtp installed using FreeBSD's pkg | |
(setq sendmail-program "/usr/local/bin/msmtp" | |
message-sendmail-f-is-evil t ;; needed to determine correct account | |
message-sendmail-extra-arguments '("--read-envelope-from") | |
send-mail-function 'smtpmail-send-it | |
message-send-mail-function 'message-send-mail-with-sendmail) | |
;; The following code overwrites "d" in mu4e-headers-mode to only move the | |
;; message to the trash folder and do not mark it as deleted (no T flag). | |
;; See https://github.com/djcb/mu/issues/1136 | |
(setf (alist-get 'trash mu4e-marks) | |
(list :char '("d" . "▼") | |
:prompt "dtrash" | |
:dyn-target (lambda (target msg) | |
(mu4e-get-trash-folder msg)) | |
:action (lambda (docid msg target) | |
;; Here's the main difference to the regular trash mark, | |
;; no +T before -N so the message is not marked as | |
;; IMAP-deleted: | |
;;(mu4e~proc-move docid (mu4e~mark-check-target target) "-N")))) | |
(mu4e--server-move docid (mu4e--mark-check-target target) "-N")))) | |
;; Signature | |
(setq mu4e-compose-signature "https://wiki.freebsd.org/DmitrySalychev") | |
;; Set up contexts for email accounts | |
;; ... | |
(setq mu4e-context-policy 'pick-first) | |
;; Display options | |
(setq mu4e-view-show-images nil) | |
(setq mu4e-view-show-addresses 't) | |
;; Composing mail | |
(setq mu4e-compose-dont-reply-to-self t) | |
;; ;; Signing messages (use mml-secure-sign-pgpmime) | |
;; (setq mml-secure-openpgp-signers '("...")) | |
;; ;; (See the documentation for `mu4e-sent-messages-behavior' if you have | |
;; ;; additional non-Gmail addresses and want assign them different | |
;; ;; behavior.) | |
;; setup some handy shortcuts | |
;; ... | |
;; don't keep message buffers around | |
(setq message-kill-buffer-on-exit t) | |
;; Use fancy characters for threads | |
(setq mu4e-use-fancy-chars nil) | |
(setq mu4e-headers-thread-child-prefix '("├> " . "├▶ ")) | |
(setq mu4e-headers-thread-last-child-prefix '("└> " . "└▶ ")) | |
(setq mu4e-headers-thread-connection-prefix '("│ " . "│ ")) | |
(setq mu4e-headers-thread-orphan-prefix '("┬> " . "┬▶ ")) | |
(setq mu4e-headers-thread-single-orphan-prefix '("─> " . "─▶ ")) | |
;; Start mu4e in the background so that it syncs mail periodically | |
(mu4e t)) | |
;; A new Org link type for mu4e to form a dashboard | |
;; (use-package mu4e-dashboard | |
;; :ensure nil ;; no package in the repos yet :( | |
;; :after mu4e) | |
;; (use-package mu4e-alert | |
;; :after mu4e | |
;; :config | |
;; ;; Show unread emails from MCUSim inbox. | |
;; (setq mu4e-alert-interesting-mail-query "maildir:/MCUSim/INBOX") | |
;; ;; Show notifications for mails already notified. | |
;; (setq mu4e-alert-notify-repeated-mails nil) | |
;; (mu4e-alert-enable-notifications)) | |
;; A plain-text personal knowledge management system: https://www.orgroam.com/ | |
(use-package org-roam | |
:ensure t | |
:init | |
(setq org-roam-v2-ack t) | |
:custom | |
(org-roam-directory "~/org-roam") | |
(org-roam-completion-everywhere t) | |
:bind (("C-c n l" . org-roam-buffer-toggle) | |
("C-c n f" . org-roam-node-find) | |
("C-c n i" . org-roam-node-insert) | |
("C-c n g" . org-roam-graph) | |
("C-c n c" . org-roam-capture) | |
:map org-mode-map | |
("C-M-i" . completion-at-point)) | |
:config | |
(org-roam-setup)) | |
;; ----------------- 8. General Configuration ---------------------------------- | |
(setq inhibit-startup-message t) | |
;; https://www.masteringemacs.org/article/demystifying-emacs-window-manager | |
;; | |
;; The function set-window-dedicated-p handles the dedicating. Unfortunately | |
;; it’s not exposed to users by default, so let’s fix that by making a little | |
;; elisp helper that toggles dedication in the selected window: | |
(defun mp-toggle-window-dedication () | |
"Toggles window dedication in the selected window." | |
(interactive) | |
(set-window-dedicated-p (selected-window) | |
(not (window-dedicated-p (selected-window))))) | |
;; Frame opacity | |
;; (set-frame-parameter (selected-frame) 'alpha '(90 . 50)) | |
;; (add-to-list 'default-frame-alist '(alpha . (90 . 50))) | |
;; Show line numbers the easy way. | |
;; See https://www.emacswiki.org/emacs/LineNumbers#toc1 for details. | |
;; (when (version<= "26.0.50" emacs-version) | |
;; (global-display-line-numbers-mode)) | |
;; Show line numbers in the programming modes only. | |
(add-hook 'prog-mode-hook 'display-line-numbers-mode) | |
;; General tweaks. | |
(menu-bar-mode -1) | |
(tool-bar-mode -1) | |
(scroll-bar-mode -1) | |
(set-face-attribute 'default nil :height 105) | |
(semantic-mode 1) | |
(set-default 'semantic-case-fold t) | |
(desktop-save-mode 1) | |
(set-mouse-color "white") | |
;; ----------------- 9. Custom Configuration (auto-generated) ----------------- | |
(custom-set-variables | |
;; custom-set-variables was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
'(custom-enabled-themes '(dracula)) | |
'(mml-secure-openpgp-sign-with-sender t) | |
'(neo-theme 'icons) | |
'(neo-window-width 70) | |
'(package-selected-packages | |
'(ement use-package unicode-fonts org-journal no-littering neotree mu4e-alert magit ibuffer-vc highlight-parentheses helm-gtags fill-column-indicator dracula-theme dired-single centaur-tabs all-the-icons))) | |
(custom-set-faces | |
;; custom-set-faces was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
'(default ((t (:height 105 :family "Hack")))) | |
'(tab-line-tab ((t (:background "#282a36" :foreground "#ff79c6" :box (:line-width 3 :color "#282a36")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment