From 4afbd35e1352138ee1ed40ac3fce41b19f720f69 Mon Sep 17 00:00:00 2001 From: Ray Andrew Date: Mon, 17 Feb 2025 12:21:40 -0600 Subject: [PATCH] add emacs --- src/home/default.nix | 2 +- src/home/{emacs.nix => emacs/default.nix} | 0 src/home/emacs/early-init.el | 8 + src/home/emacs/init.el | 497 ++++++++++++++++++++++ src/home/gui/zoom.nix | 6 +- 5 files changed, 509 insertions(+), 4 deletions(-) rename src/home/{emacs.nix => emacs/default.nix} (100%) create mode 100644 src/home/emacs/early-init.el create mode 100644 src/home/emacs/init.el diff --git a/src/home/default.nix b/src/home/default.nix index 86ecaa8..5a7a92d 100644 --- a/src/home/default.nix +++ b/src/home/default.nix @@ -7,7 +7,7 @@ }: { imports = [ - ./emacs.nix + ./emacs ./email ./impermanence.nix ./gui diff --git a/src/home/emacs.nix b/src/home/emacs/default.nix similarity index 100% rename from src/home/emacs.nix rename to src/home/emacs/default.nix diff --git a/src/home/emacs/early-init.el b/src/home/emacs/early-init.el new file mode 100644 index 0000000..ae5f4da --- /dev/null +++ b/src/home/emacs/early-init.el @@ -0,0 +1,8 @@ + ;; The default is 800 kilobytes. Measured in bytes. +(setq gc-cons-threshold (* 50 1000 1000)) + + +(setq menu-bar-mode nil) ;; Disable the menu bar +(setq scroll-bar-mode nil) ;; Disable the scroll bar +(setq tool-bar-mode nil) ;; Disable the tool bar +(setq inhibit-startup-screen t) ;; Disable welcome screen diff --git a/src/home/emacs/init.el b/src/home/emacs/init.el new file mode 100644 index 0000000..619a6e2 --- /dev/null +++ b/src/home/emacs/init.el @@ -0,0 +1,497 @@ +;; (defun start/org-babel-tangle-config () +;; "Automatically tangle our Emacs.org config file when we save it. Credit to Emacs From Scratch for this one!" +;; (when (string-equal (file-name-directory (buffer-file-name)) +;; (expand-file-name user-emacs-directory)) +;; ;; Dynamic scoping to the rescue +;; (let ((org-confirm-babel-evaluate nil)) +;; (org-babel-tangle)))) + +;; (add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook #'start/org-babel-tangle-config))) + +(require 'use-package-ensure) ;; Load use-package-always-ensure +(setq use-package-always-ensure t) ;; Always ensures that a package is installed +(setq package-archives '(("melpa" . "https://melpa.org/packages/") ;; Sets default package repositories + ("org" . "https://orgmode.org/elpa/") + ("elpa" . "https://elpa.gnu.org/packages/") + ("nongnu" . "https://elpa.nongnu.org/nongnu/"))) ;; For Eat Terminal + +(use-package evil + :init ;; Execute code Before a package is loaded + (evil-mode) + :config ;; Execute code After a package is loaded + (evil-set-initial-state 'eat-mode 'insert) ;; Set initial state in eat terminal to insert mode + :custom ;; Customization of package custom variables + (evil-want-keybinding nil) ;; Disable evil bindings in other modes (It's not consistent and not good) + (evil-want-C-u-scroll t) ;; Set C-u to scroll up + (evil-want-C-i-jump nil) ;; Disables C-i jump + (evil-undo-system 'undo-redo) ;; C-r to redo + (org-return-follows-link t) ;; Sets RETURN key in org-mode to follow links + ;; Unmap keys in 'evil-maps. If not done, org-return-follows-link will not work + :bind (:map evil-motion-state-map + ("SPC" . nil) + ("RET" . nil) + ("TAB" . nil))) + +(use-package evil-collection + :after evil + :config + ;; Setting where to use evil-collection + (setq evil-collection-mode-list '(dired ibuffer magit corfu vertico consult compile)) + (evil-collection-init)) + +(use-package general + :config + (general-evil-setup) + ;; Set up 'SPC' as the leader key + (general-create-definer start/leader-keys + :states '(normal insert visual motion emacs) + :keymaps 'override + :prefix "SPC" ;; Set leader key + :global-prefix "C-SPC") ;; Set global leader key + + (general-nmap + "g c c" '(comment-line :wk "[Un]Comment line") + "-" '(dired-jump :wk "Dired jump to current")) + + ;; Multi cursors + (general-nvmap + "C-q" '(evil-mc-undo-all-cursors :wk "[MC] Go to next cursor" :package evil-mc) + "C-n" '(evil-mc-make-and-goto-next-match :wk "[MC] Go to next cursor" :package evil-mc) + "C-d" '(evil-mc-make-and-goto-next-match :wk "[MC] Go to next cursor" :package evil-mc)) + + (general-vmap + "g c" '(comment-line :wk "[Un]Comment lines")) + + (start/leader-keys + ":" '(execute-extended-command :wk "Run Command") + "SPC" '(consult-buffer :wk "Switch buffer") + "p" '(projectile-command-map :wk "Projectile command map")) + + (start/leader-keys + "w" '(:ignore t :wk "Windows") + "w q" '(delete-window :wk "Quit Window") + "w v" '(split-window-horizontally :wk "Split Windows Vertically") + "w s" '(split-window-vertically :wk "Split Windows Horizontally") + "w h" '(windmove-left :wk "Move to left window") + "w l" '(windmove-right :wk "Move to right window") + "w k" '(windmove-up :wk "Move to upper window") + "w j" '(windmove-down :wk "Move to window below")) + + (general-nvmap + "C-h" '(windmove-left :wk "Move to left window") + "C-l" '(windmove-right :wk "Move to right window") + "C-k" '(windmove-up :wk "Move to upper window") + "C-j" '(windmove-down :wk "Move to window below") + "C-x o" '(ace-window :wk "Ace Window" :package ace-window)) + ;; "w h" '(tmux-pane-omni-window-left :wk "Move to left window" :package tmux-pane) + ;; "w l" '(tmux-pane-omni-window-right :wk "Move to right window" :package tmux-pane) + ;; "w k" '(tmux-pane-omni-window-up :wk "Move to upper window" :package tmux-pane) + ;; "w j" '(tmux-pane-omni-window-down :wk "Move to window below" :package tmux-pane)) + + (start/leader-keys + "f" '(:ignore t :wk "File") + "f f" '(find-file :wk "Find file") + "f s" '(save-buffer :wk "File save") + "f c" '((lambda () (interactive) (find-file "~/.config/emacs/init.el")) :wk "Edit emacs config")) + + (start/leader-keys + "b" '(:ignore t :wk "Buffer Bookmarks") + "b b" '(consult-buffer :wk "Switch buffer") + "b k" '(kill-this-buffer :wk "Kill this buffer") + "b i" '(ibuffer :wk "Ibuffer") + "b n" '(next-buffer :wk "Next buffer") + "b p" '(previous-buffer :wk "Previous buffer") + "b r" '(revert-buffer :wk "Reload buffer") + "b j" '(consult-bookmark :wk "Bookmark jump")) + + (start/leader-keys + "d" '(:ignore t :wk "Dired") + "d v" '(dired :wk "Open dired") + "d j" '(dired-jump :wk "Dired jump to current")) + + (start/leader-keys + "e" '(:ignore t :wk "Eglot Evaluate") + "e e" '(eglot-reconnect :wk "Eglot Reconnect") + "e f" '(eglot-format :wk "Eglot Format") + "e l" '(consult-flymake :wk "Consult Flymake") + "e b" '(eval-buffer :wk "Evaluate elisp in buffer") + "e r" '(eval-region :wk "Evaluate elisp in region")) + + (start/leader-keys + "g" '(:ignore t :wk "Git") + "g g" '(magit-status :wk "Magit status")) + + (start/leader-keys + "h" '(:ignore t :wk "Help") ;; To get more help use C-h commands (describe variable, function, etc.) + "h q" '(save-buffers-kill-emacs :wk "Quit Emacs and Daemon") + "h r" '((lambda () (interactive) + (load-file "~/.config/emacs/init.el")) + :wk "Reload Emacs config")) + + (start/leader-keys + "s" '(:ignore t :wk "Show") + "s r" '(consult-recent-file :wk "Recent files") + "s f" '(consult-fd :wk "Fd search for files") + "s g" '(consult-ripgrep :wk "Ripgrep search in files") + "s l" '(consult-line :wk "Find line") + "s i" '(consult-imenu :wk "Imenu buffer locations")) + + (start/leader-keys + "t" '(:ignore t :wk "Toggle") + "t e" '(eat :wk "Toggle Eat terminal") + "t t" '(visual-line-mode :wk "Toggle truncated lines (wrap)") + "t l" '(display-line-numbers-mode :wk "Toggle line numbers"))) + +;; (use-package compile +;; :config +;; (general-nvmap compilation-mode-map +;; "C-h" '(windmove-left :wk "Move to left window") +;; "C-l" '(windmove-right :wk "Move to right window") +;; "C-k" '(windmove-up :wk "Move to upper window") +;; "C-j" '(windmove-down :wk "Move to window below") +;; "C-x o" '(ace-window :wk "Ace Window" :package ace-window))) + +(use-package emacs + :custom + (delete-selection-mode t) ;; Select text and delete it by typing. + (electric-indent-mode nil) ;; Turn off the weird indenting that Emacs does by default. + (electric-pair-mode t) ;; Turns on automatic parens pairing + + (blink-cursor-mode nil) ;; Don't blink cursor + (global-auto-revert-mode t) ;; Automatically reload file and show changes if the file has changed + + ;;(dired-kill-when-opening-new-dired-buffer t) ;; Dired don't create new buffer + ;;(recentf-mode t) ;; Enable recent file mode + + ;;(global-visual-line-mode t) ;; Enable truncated lines + ;;(display-line-numbers-type 'relative) ;; Relative line numbers + (global-display-line-numbers-mode t) ;; Display line numbers + + (mouse-wheel-progressive-speed nil) ;; Disable progressive speed when scrolling + (scroll-conservatively 10) ;; Smooth scrolling + ;;(scroll-margin 8) + + (tab-width 4) + + (make-backup-files nil) ;; Stop creating ~ backup files + (auto-save-default nil) ;; Stop creating # auto save files + :hook + (prog-mode . (lambda () (hs-minor-mode t))) ;; Enable folding hide/show globally + :config + ;; Move customization variables to a separate file and load it, avoid filling up init.el with unnecessary variables + (setq custom-file (locate-user-emacs-file "custom-vars.el")) + (load custom-file 'noerror 'nomessage) + :bind ( + ([escape] . keyboard-escape-quit) ;; Makes Escape quit prompts (Minibuffer Escape) + ) + ;; Fix general.el leader key not working instantly in messages buffer with evil mode + :ghook ('after-init-hook + (lambda (&rest _) + (when-let ((messages-buffer (get-buffer "*Messages*"))) + (with-current-buffer messages-buffer + (evil-normalize-keymaps)))) + nil nil t) + ) + +;; (use-package gruvbox-theme +;; :config +;; (load-theme 'gruvbox-dark-medium t)) ;; We need to add t to trust this package + +(use-package gruber-darker-theme + :config + (load-theme 'gruber-darker t)) ;; We need to add t to trust this package + +(add-to-list 'default-frame-alist '(alpha-background . 90)) ;; For all new frames henceforth + +(set-face-attribute 'default nil + :font "Iosevka Nerd Font Mono" ;; Set your favorite type of font or download JetBrains Mono + :height 120 + :weight 'medium) +;; This sets the default font on all graphical frames created after restarting Emacs. +;; Does the same thing as 'set-face-attribute default' above, but emacsclient fonts +;; are not right unless I also add this method of setting the default font. + +(add-to-list 'default-frame-alist '(font . "Iosevka Nerd Font Mono")) ;; Set your favorite font +(setq-default line-spacing 0.12) + +(use-package emacs + :bind + ("C-+" . text-scale-increase) + ("C-_" . text-scale-decrease) + ("" . text-scale-increase) + ("" . text-scale-decrease)) + +;; (use-package doom-modeline +;; :init (doom-modeline-mode 1) +;; :custom +;; (doom-modeline-height 25) ;; Sets modeline height +;; (doom-modeline-bar-width 5) ;; Sets right bar width +;; (doom-modeline-persp-name t) ;; Adds perspective name to modeline +;; (doom-modeline-persp-icon t)) ;; Adds folder icon next to persp name + +(use-package projectile + :init + (projectile-mode) + :custom + (projectile-run-use-comint-mode t) ;; Interactive run dialog when running projects inside emacs (like giving input) + (projectile-switch-project-action #'projectile-dired) ;; Open dired when switching to a project + (projectile-project-search-path '("~/projects/" "~/work/" ("~/code" . 1)))) ;; . 1 means only search the first subdirectory level for projects +;; Use Bookmarks for smaller, not standard projects + +;;(use-package eglot +;; :ensure nil ;; Don't install eglot because it's now built-in +;; :hook ((c-mode c++-mode ;; Autostart lsp servers for a given mode +;; lua-mode) ;; Lua-mode needs to be installed +;; . eglot-ensure) +;; :custom +;; ;; Good default +;; (eglot-events-buffer-size 0) ;; No event buffers (Lsp server logs) +;; (eglot-autoshutdown t);; Shutdown unused servers. +;; (eglot-report-progress nil) ;; Disable lsp server logs (Don't show lsp messages at the bottom, java) +;; ;; Manual lsp servers +;; :config +;; (add-to-list 'eglot-server-programs +;; `(lua-mode . ("PATH_TO_THE_LSP_FOLDER/bin/lua-language-server" "-lsp"))) ;; Adds our lua lsp server to eglot's server list +;; ) + +(use-package yasnippet-snippets + :hook (prog-mode . yas-minor-mode)) + +(use-package org + :ensure nil + :custom + (org-edit-src-content-indentation 4) ;; Set src block automatic indent to 4 instead of 2. + + :hook + (org-mode . org-indent-mode) ;; Indent text + ;; The following prevents <> from auto-pairing when electric-pair-mode is on. + ;; Otherwise, org-tempo is broken when you try to " "S-")) + + ;; For some commands and buffer sources it is useful to configure the + ;; :preview-key on a per-command basis using the `consult-customize' macro. + ;; (consult-customize + ;; consult-theme :preview-key '(:debounce 0.2 any) + ;; consult-ripgrep consult-git-grep consult-grep + ;; consult-bookmark consult-recent-file consult-xref + ;; consult--source-bookmark consult--source-file-register + ;; consult--source-recent-file consult--source-project-recent-file + ;; :preview-key "M-." + ;; :preview-key '(:debounce 0.4 any)) + + ;; By default `consult-project-function' uses `project-root' from project.el. + ;; Optionally configure a different project root function. + ;;;; 1. project.el (the default) + ;; (setq consult-project-function #'consult--default-project--function) + ;;;; 2. vc.el (vc-root-dir) + ;; (setq consult-project-function (lambda (_) (vc-root-dir))) + ;;;; 3. locate-dominating-file + ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git"))) + ;;;; 4. projectile.el (projectile-project-root) + (autoload 'projectile-project-root "projectile") + (setq consult-project-function (lambda (_) (projectile-project-root))) + ;;;; 5. No project support + ;; (setq consult-project-function nil) + ) + +;; (use-package tmux-pane +;; :config +;; (tmux-pane-mode)) + +(use-package diminish) + +(use-package rainbow-delimiters + :hook (prog-mode . rainbow-delimiters-mode)) + +(use-package which-key + :init + (which-key-mode 1) + :diminish + :custom + (which-key-side-window-location 'bottom) + (which-key-sort-order #'which-key-key-order-alpha) ;; Same as default, except single characters are sorted alphabetically + (which-key-sort-uppercase-first nil) + (which-key-add-column-padding 1) ;; Number of spaces to add to the left of each column + (which-key-min-display-lines 6) ;; Increase the minimum lines to display, because the default is only 1 + (which-key-idle-delay 0.8) ;; Set the time delay (in seconds) for the which-key popup to appear + (which-key-max-description-length 25) + (which-key-allow-imprecise-window-fit nil)) ;; Fixes which-key window slipping out in Emacs Daemon + +;; (use-package evil-multiedit +;; :config (evil-multiedit-default-keybinds)) + +(use-package evil-mc + ;; :hook (prog-mode . evil-mc-mode)) + :config (global-evil-mc-mode 1)) + +(use-package ace-window + :defer t) + +;; Make gc pauses faster by decreasing the threshold. +(setq gc-cons-threshold (* 2 1000 1000)) +;; Increase the amount of data which Emacs reads from the process +(setq read-process-output-max (* 1024 1024)) ;; 1mb diff --git a/src/home/gui/zoom.nix b/src/home/gui/zoom.nix index 76267ee..e218147 100644 --- a/src/home/gui/zoom.nix +++ b/src/home/gui/zoom.nix @@ -26,8 +26,8 @@ in home.directories = [ ".zoom" ]; - home.files = [ - ".config/zoomus.conf" - ]; + # home.files = [ + # ".config/zoomus.conf" + # ]; }; }