Skip to content
Open

emacs #1537

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions users/profiles/emacs/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
(setopt initial-major-mode 'fundamental-mode) ; default mode for the *scratch* buffer
(setopt display-time-default-load-average nil) ; this information is useless for most

;; Allows us to call git commit / jj commit / split etc from a vterm inside emacs
(setq server-window 'switch-to-buffer)

;; Automatically reread from disk if the underlying file changes
(setopt auto-revert-avoid-polling t)
;; Some systems don't do file notifications well; see
Expand Down Expand Up @@ -64,6 +67,10 @@
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file t t)

(setq find-program "@find-program@")
(setq shell-file-name "@shell-file-name@")
(setq explicit-shell-file-name shell-file-name)

;; Enable winner mode after init
(add-hook 'after-init-hook #'winner-mode)

Expand Down Expand Up @@ -123,6 +130,17 @@
(setq display-line-numbers-type 'relative)
(global-display-line-numbers-mode)

;; Disable them in certain major modes
(dolist (mode '(org-mode
eshell-mode
term-mode
shell-mode
vterm-mode
help-mode
compilation-mode))
(add-hook (intern (concat (symbol-name mode) "-hook"))
(lambda () (display-line-numbers-mode 0))))

;; We won't set these, but they're good to know about
;;
;; (setopt indent-tabs-mode nil)
Expand Down Expand Up @@ -162,9 +180,10 @@
(setopt display-time-interval 1)
(display-time-mode)

(use-package emacs
:config
(load-theme 'modus-vivendi)) ; for light theme, use modus-operandi
;; Theme loading is handled by extras/catppuccin.el
;; (use-package emacs
;; :config
;; (load-theme 'modus-vivendi)) ; for light theme, use modus-operandi

@extras@

Expand Down
19 changes: 10 additions & 9 deletions users/profiles/emacs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
...
}: let
emacsInit = pkgs.replaceVars ./config.el {
find-program = "${pkgs.findutils}/bin/find";
shell-file-name = "${pkgs.bashInteractive}/bin/bash";
extras = lib.concatStringsSep "\n" (map (n: builtins.readFile ./extras/${n}) (
lib.mapAttrsToList (name: _: name) (lib.filterAttrs (_: type: type == "regular") (builtins.readDir ./extras))
));
Expand All @@ -19,37 +21,36 @@ in {
;; MASSIVE startup optimizations
(setq gc-cons-threshold most-positive-fixnum
gc-cons-percentage 0.6)

;; Prevent package.el loading packages prior to init.el
(setq package-enable-at-startup nil)

;; Inhibit resizing frame
(setq frame-inhibit-implied-resize t)

;; Disable file handler checking during startup
(defvar default-file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)

;; Prevent unwanted runtime compilation for native-comp
(setq native-comp-deferred-compilation nil
native-comp-async-report-warnings-errors 'silent)

;; Silence warnings
(setq byte-compile-warnings '(not obsolete))
(setq warning-suppress-log-types '((comp) (bytecomp)))

;; UI optimizations
(push '(menu-bar-lines . 0) default-frame-alist)
(push '(tool-bar-lines . 0) default-frame-alist)
(push '(vertical-scroll-bars) default-frame-alist)
(setq frame-resize-pixelwise t)

;; Silence startup message
(setq inhibit-startup-echo-area-message (user-login-name))

;; Default frame configuration
(setq default-frame-alist '((fullscreen . maximized)
(background-color . "#000000")
(ns-appearance . dark)
(ns-transparent-titlebar . t)))

Expand Down
47 changes: 45 additions & 2 deletions users/profiles/emacs/extras/base.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
(use-package embark
:ensure t
:defer t ; Load on first use
:bind (("C-c a" . embark-act)) ; bind this to an easy key to hit
:bind (("C-c a" . embark-act) ; bind this to an easy key to hit
("C-c e" . embark-export))
:config
;; Add the option to run embark when using avy
(defun bedrock/avy-action-embark (pt)
Expand Down Expand Up @@ -180,11 +181,53 @@

;; Modify search results en masse
(use-package wgrep
:ensure t
:commands (wgrep-setup wgrep-change-to-wgrep-mode)
:init
;; Set the key before wgrep loads
(setq wgrep-enable-key "C-c C-p")
(with-eval-after-load 'grep
(define-key grep-mode-map (kbd "C-c C-p") 'wgrep-change-to-wgrep-mode))
:config
(setq wgrep-auto-save-buffer t)
(setq wgrep-change-readonly-file nil)

;; Helix-style keybindings in wgrep mode
(define-key wgrep-mode-map (kbd "C-c C-c") 'wgrep-finish-edit)
(define-key wgrep-mode-map (kbd "C-c C-k") 'wgrep-abort-changes)
(define-key wgrep-mode-map (kbd "C-x C-s") 'wgrep-finish-edit))

;; Setup wgrep for consult-grep/ripgrep results
(use-package grep
:ensure nil ; built-in
:config
(require 'wgrep nil t)
:hook ((grep-mode . wgrep-setup)
(ripgrep-search-mode . wgrep-setup)))

;; Make consult-ripgrep results editable via embark and wgrep

;; Deadgrep - better project search interface
(use-package deadgrep
:ensure t
:defer t
:commands (deadgrep)
:config
;; Use project root by default
(setq deadgrep-project-root-function
(lambda () (project-root (project-current)))))

;; wgrep support for deadgrep buffers (faster than deadgrep-edit-mode)
(use-package wgrep-deadgrep
:ensure t
:after wgrep
:config
(setq wgrep-auto-save-buffer t))
;; Setup wgrep for deadgrep buffers
(add-hook 'deadgrep-finished-hook 'wgrep-deadgrep-setup))

;; Add keybinding for entering wgrep mode in deadgrep buffers
(with-eval-after-load 'deadgrep
(define-key deadgrep-mode-map (kbd "C-c C-p") 'wgrep-change-to-wgrep-mode))

(use-package websocket
:ensure t
Expand Down
4 changes: 2 additions & 2 deletions users/profiles/emacs/extras/catpuccin.el
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use-package catppuccin-theme
:ensure t
:demand t ; Load immediately, not deferred
:init
(setq catppuccin-flavor 'frappe)
:config
(load-theme 'catppuccin :no-confirm)
)
(load-theme 'catppuccin :no-confirm))
57 changes: 53 additions & 4 deletions users/profiles/emacs/extras/meow.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@
(forward-char 1)
(delete-region (region-beginning) (region-end)))))

(defun meow-helix-toggle-comment ()
"Toggle comment on current line or region, like Helix's C-c."
(interactive)
(if (region-active-p)
;; Comment/uncomment region
(comment-or-uncomment-region (region-beginning) (region-end))
;; Comment/uncomment current line
(save-excursion
(beginning-of-line)
(set-mark (point))
(end-of-line)
(comment-or-uncomment-region (region-beginning) (region-end)))))

(defvar meow-helix-ex-commands
'(("w" . save-buffer)
("write" . save-buffer)
Expand Down Expand Up @@ -405,17 +418,17 @@
(define-key map "B" 'ibuffer)
(define-key map "s" 'save-buffer)
(define-key map "S" 'save-some-buffers)
(define-key map "c" 'meow-helix-toggle-comment) ;; Comment toggle
(define-key map "q" 'save-buffers-kill-emacs)
(define-key map "Q" 'kill-emacs)
(define-key map "w" 'meow-helix-window-mode) ;; Changed to enter window mode
(define-key map "W" 'delete-other-windows)
(define-key map "v" 'split-window-right)
(define-key map "h" 'split-window-below)
(define-key map "o" 'other-window)
(define-key map "/" 'meow-helix-project-search) ;; Project-wide search
(define-key map "k" 'kill-current-buffer)
(define-key map "K" 'kill-buffer)
(define-key map "r" 'query-replace)
(define-key map "R" 'query-replace-regexp)
(define-key map "g" 'magit-status)
(define-key map "p" 'project-switch-project)
(define-key map "e" 'eval-expression)
Expand All @@ -430,6 +443,41 @@
(interactive)
(set-transient-map meow-helix-space-mode-map))

;; Project-wide search and replace functions
(defun meow-helix-project-search ()
"Search across the project using deadgrep.
Press C-c C-p to enter edit mode, C-c C-c to save changes."
(interactive)
(if (fboundp 'deadgrep)
(call-interactively 'deadgrep)
;; Fallback to consult-ripgrep if available
(if (fboundp 'consult-ripgrep)
(progn
(consult-ripgrep)
(message "Press C-c e to export, then C-c C-p to edit"))
(call-interactively 'project-find-regexp))))


(defun meow-helix-search-word-at-point ()
"Search for the word at point across the project."
(interactive)
(let ((word (thing-at-point 'symbol t)))
(if word
(if (fboundp 'deadgrep)
(deadgrep word)
(if (fboundp 'consult-ripgrep)
(consult-ripgrep nil word)
(project-find-regexp word)))
(message "No word at point"))))

(defun meow-helix-search-symbol-at-point ()
"Search for symbol at point in current buffer.
With prefix arg, search across the project."
(interactive)
(if current-prefix-arg
(meow-helix-search-word-at-point)
(isearch-forward-symbol-at-point)))

(defvar meow-helix-window-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "w" 'other-window)
Expand Down Expand Up @@ -1163,7 +1211,7 @@ Returns (START-OPEN . END-CLOSE) positions or nil."
'("?" . isearch-backward)
'("n" . meow-helix-search-next)
'("N" . meow-helix-search-prev)
'("*" . isearch-forward-symbol-at-point)
'("*" . meow-helix-search-symbol-at-point)

'("m" . meow-helix-match-mode)
'("%" . meow-helix-select-whole-file) ; Select whole file like Helix
Expand All @@ -1173,6 +1221,7 @@ Returns (START-OPEN . END-CLOSE) positions or nil."

'("c" . meow-change)
;; '("C" . meow-helix-duplicate) ; Replaced with cursor-below
'("M-c" . meow-helix-toggle-comment) ; Comment toggle (Alt-c, since C-c conflicts)
'("d" . meow-helix-delete) ; Simple delete without extending selection
'("D" . meow-kill-whole-line)

Expand Down Expand Up @@ -1229,7 +1278,7 @@ Returns (START-OPEN . END-CLOSE) positions or nil."
'("C-a" . meow-helix-select-all)
'("C-b" . meow-helix-page-up)
'("C-f" . meow-helix-page-down)
'("C-u" . meow-helix-half-page-up)
;; '("C-u" . meow-helix-half-page-up) ; Commented out to restore C-u as universal argument
'("C-d" . meow-helix-half-page-down)
'("C-w" . meow-helix-window-mode)

Expand Down
Loading