init.el (14797B)
1 (setq custom-file (concat user-emacs-directory "custom.el")) 2 (add-to-list 'load-path "~/.config/emacs/local") 3 (add-to-list 'custom-theme-load-path "~/.config/emacs/local") 4 (when (file-exists-p custom-file) 5 (load custom-file)) 6 7 (load "odin-mode.el") 8 9 ;;; Appearance and basic functionality 10 (menu-bar-mode -1) 11 (tool-bar-mode -1) 12 (scroll-bar-mode -1) 13 14 (defun my/disable-scroll-bars (frame) 15 (modify-frame-parameters frame 16 '((vertical-scroll-bars . nil) 17 (horizontal-scroll-bars . nil)))) 18 19 (add-hook 'after-make-frame-functions 'my/disable-scroll-bars) 20 21 ;; (setq-default indent-tabs-mode nil) 22 (setq-default tab-width 4) 23 (setq inhibit-splash-screen t 24 inhibit-startup-message t 25 scroll-step 3 26 auto-save-default nil 27 make-backup-files nil 28 blink-cursor-mode nil 29 ring-bell-function 'ignore 30 display-line-numbers-type 'relative 31 dired-listing-switches "-alh --group-directories-first" 32 compilation-scroll-output t 33 gc-cons-threshold 100000000 34 compilation-ask-about-save nil 35 frame-resize-pixelwise t 36 mouse-drag-mode-line-buffer 1 37 display-time-24hr-format t 38 ) 39 40 ;; (global-hl-line-mode 1) 41 (global-display-line-numbers-mode) 42 43 ;; pascal compilation errors 44 (require 'compile) 45 (add-to-list 'compilation-error-regexp-alist 46 '("^\\(.*\\)(\\([0-9]+\\)+\\,\\([0-9]+\\)).*" 1 2 3)) 47 48 ;;; Package installs and configuration 49 (require 'package) 50 (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) 51 (package-initialize) 52 53 (eval-when-compile 54 (require 'use-package)) 55 56 (use-package gruber-darker-theme 57 :ensure) 58 59 (use-package minions 60 :ensure t 61 62 :custom 63 (minions-mode-line-delimiters (cons "" "")) 64 65 :config 66 (defun +set-minions-mode-line-lighter () 67 (setq minions-mode-line-lighter 68 (if (display-graphic-p) "⚙" "#"))) 69 70 (add-hook 'server-after-make-frame-hook #'+set-minions-mode-line-lighter) 71 (display-time-mode 1) 72 (display-battery-mode 1) 73 (minions-mode 1)) 74 75 (use-package naysayer-theme 76 :ensure) 77 78 (use-package zenburn-theme 79 :ensure) 80 81 (use-package savehist 82 :init 83 (savehist-mode)) 84 85 (use-package eat 86 :ensure) 87 ;; (add-hook 'eshell-first-time-mode-hook #'eat-eshell-mode)) 88 89 (use-package eshell 90 :ensure 91 :hook (eshell-mode . (lambda () 92 (display-line-numbers-mode -1)))) 93 94 (use-package vertico 95 :ensure 96 :init 97 (vertico-mode 1) 98 (setq vertico-cycle t) 99 :config 100 (setq vertico-multiform-categories 101 '((consult-grep 102 buffer 103 (vertico-buffer-display-action . (display-buffer-same-window)))))) 104 105 (use-package orderless 106 :ensure 107 :init 108 ;; Configure a custom style dispatcher (see the Consult wiki) 109 ;; (setq orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch) 110 ;; orderless-component-separator #'orderless-escapable-split-on-space) 111 (setq completion-styles '(orderless basic) 112 completion-category-defaults nil 113 completion-category-overrides '((file (styles partial-completion)))) 114 :config 115 (vertico-multiform-mode) 116 (setq vertico-multiform-categories 117 '((consult-grep buffer)))) 118 119 (use-package dired 120 :config 121 (setq dired-clean-up-buffers-too t 122 dired-dwim-target t 123 dired-recursive-copies 'always 124 dired-recursive-deletes 'top 125 global-auto-revert-non-file-buffers t 126 auto-revert-verbose nil)) 127 128 (use-package marginalia 129 :ensure 130 :init 131 (marginalia-mode)) 132 133 (use-package smex 134 :ensure 135 :config 136 ;; (smex-initialize) 137 :bind 138 ;; ("M-x" . smex) 139 ;; ("M-X" . smex-major-mode-commands) 140 ) 141 142 (use-package company 143 :ensure 144 :config 145 (setq company-idle-delay nil) 146 (global-company-mode) 147 :bind 148 ("C-<return>" . company-complete) 149 ("C-<tab>" . dabbrev-expand)) 150 151 (use-package yasnippet 152 :ensure 153 :config 154 (require 'company) 155 ;; Add yasnippet support for all company backends 156 ;; https://github.com/syl20bnr/spacemacs/pull/179 157 (defvar company-mode/enable-yas t 158 "Enable yasnippet for all backends.") 159 160 (defun company-mode/backend-with-yas (backend) 161 (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend))) 162 backend 163 (append (if (consp backend) backend (list backend)) 164 '(:with company-yasnippet)))) 165 (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends)) 166 (yas-global-mode 1)) 167 168 (use-package hl-todo 169 :ensure 170 :config 171 (setq hl-todo-keyword-faces 172 '(("TODO" . "#f43841") 173 ("NOTE" . "#73c936") 174 ("IMPORTANT" . "#2ea3f2"))) 175 :init 176 (global-hl-todo-mode)) 177 178 (use-package dumb-jump 179 :ensure 180 :config 181 (setq xref-show-definitions-function #'xref-show-definitions-completing-read) 182 (add-hook 'xref-backend-functions #'dumb-jump-xref-activate)) 183 184 (use-package magit 185 :ensure) 186 187 (use-package go-mode 188 :ensure) 189 190 (use-package lua-mode 191 :ensure) 192 193 (use-package rust-mode 194 :ensure) 195 196 (use-package zig-mode 197 :ensure 198 :config 199 (setq zig-format-on-save nil)) 200 201 (use-package glsl-mode 202 :ensure) 203 204 (use-package org 205 :defer t 206 :hook (org-mode . (lambda () 207 (display-line-numbers-mode -1)))) 208 209 (use-package org-download 210 :ensure 211 :after (org) 212 :init 213 ;; remove the stupid #+DOWNLOADED annotation 214 (defun dummy-org-download-annotate-function (link) 215 "") 216 (setq org-download-annotate-function #'dummy-org-download-annotate-function) 217 218 (setq org-download-method 'directory) 219 (setq org-download-image-dir (concat (file-name-sans-extension (buffer-file-name)) "-images")) 220 (setq org-download-image-org-width 600) 221 (setq org-download-link-format "[[file:%s]]\n") 222 (setq org-download-abbreviate-filename-function #'file-relative-name) 223 (setq org-download-link-format-function #'org-download-link-format-function-default)) 224 225 (use-package org-tempo 226 :after (org) 227 :config 228 (add-to-list 'org-structure-template-alist 229 '("el" . "src emacs-lisp"))) 230 231 (use-package evil-org 232 :ensure t 233 :after org 234 :hook (org-mode . (lambda () evil-org-mode)) 235 :config 236 (require 'evil-org-agenda) 237 (evil-org-agenda-set-keys)) 238 239 (use-package org-bullets 240 :disabled 241 :ensure 242 :config 243 (add-hook 'org-mode-hook #'(lambda () (org-bullets-mode 1)))) 244 245 (use-package ido 246 :config 247 (setq ido-enable-flex-matching t 248 ido-everywhere t 249 ido-show-dot-for-dired t 250 ido-auto-merge-work-directories-length -1) 251 (ido-mode 0)) 252 253 (defun ido-goto-symbol (&optional symbol-list) 254 "Refresh imenu and jump to a place in the buffer using Ido." 255 (interactive) 256 (unless (featurep 'imenu) 257 (require 'imenu nil t)) 258 (cond 259 ((not symbol-list) 260 (let ((ido-mode ido-mode) 261 (ido-enable-flex-matching 262 (if (boundp 'ido-enable-flex-matching) 263 ido-enable-flex-matching t)) 264 name-and-pos symbol-names position) 265 (unless ido-mode 266 (ido-mode 1) 267 (setq ido-enable-flex-matching t)) 268 (while (progn 269 (imenu--cleanup) 270 (setq imenu--index-alist nil) 271 (ido-goto-symbol (imenu--make-index-alist)) 272 (setq selected-symbol 273 (ido-completing-read "Goto: " symbol-names)) 274 (string= (car imenu--rescan-item) selected-symbol))) 275 (unless (and (boundp 'mark-active) mark-active) 276 (push-mark nil t nil)) 277 (setq position (cdr (assoc selected-symbol name-and-pos))) 278 (cond 279 ((overlayp position) 280 (goto-char (overlay-start position))) 281 (t 282 (goto-char position))))) 283 ((listp symbol-list) 284 (dolist (symbol symbol-list) 285 (let (name position) 286 (cond 287 ((and (listp symbol) (imenu--subalist-p symbol)) 288 (ido-goto-symbol symbol)) 289 ((listp symbol) 290 (setq name (car symbol)) 291 (setq position (cdr symbol))) 292 ((stringp symbol) 293 (setq name symbol) 294 (setq position 295 (get-text-property 1 'org-imenu-marker symbol)))) 296 (unless (or (null position) (null name) 297 (string= (car imenu--rescan-item) name)) 298 (add-to-list 'symbol-names name) 299 (add-to-list 'name-and-pos (cons name position)))))))) 300 301 ;;; C-mode 302 (setq-default c-basic-offset 4 303 c-default-style '((java-mode . "java") 304 (awk-mode . "awk") 305 (other . "bsd"))) 306 ;; (c-set-offset 'case-label '+) 307 308 (font-lock-add-keywords 'c-mode 309 '(("internal" . font-lock-keyword-face) 310 ("global" . 'font-lock-keyword-face))) 311 312 ;;; Keybinds 313 (defun my/eshell () 314 "Open eshell in other window" 315 (interactive) 316 (split-window-sensibly) 317 (other-window 1) 318 (eshell)) 319 320 (defun indent-buffer () 321 "Run indent-region on entire buffer" 322 (interactive) 323 (indent-region (point-min) (point-max) nil)) 324 ;; (add-hook 'before-save-hook 'indent-buffer) 325 326 (defun find-corresponding-file () 327 "Find the file that corresponds to this one." 328 (interactive) 329 (setq CorrespondingFileName nil) 330 (setq BaseFileName (file-name-sans-extension buffer-file-name)) 331 (if (string-match "\\.c" buffer-file-name) 332 (setq CorrespondingFileName (concat BaseFileName ".h"))) 333 (if (string-match "\\.h" buffer-file-name) 334 (if (file-exists-p (concat BaseFileName ".c")) (setq CorrespondingFileName (concat BaseFileName ".c")) 335 (setq CorrespondingFileName (concat BaseFileName ".cpp")))) 336 (if (string-match "\\.hin" buffer-file-name) 337 (setq CorrespondingFileName (concat BaseFileName ".cin"))) 338 (if (string-match "\\.cin" buffer-file-name) 339 (setq CorrespondingFileName (concat BaseFileName ".hin"))) 340 (if (string-match "\\.cpp" buffer-file-name) 341 (setq CorrespondingFileName (concat BaseFileName ".h"))) 342 (if CorrespondingFileName (find-file CorrespondingFileName) 343 (error "Unable to find a corresponding file"))) 344 345 (defun find-corresponding-file-other-window () 346 "Finds the file that corresponds to this and opens it in the other window." 347 (interactive) 348 (find-file-other-window buffer-file-name) 349 (find-corresponding-file)) 350 351 ;;; Launch gud-gdb in a new window 352 (defun my/gud () 353 "Run gud-gdb in other window" 354 (interactive) 355 (setq files (directory-files (file-name-directory buffer-file-name))) 356 (setq input (completing-read "executable: " files)) 357 (split-window-sensibly) 358 (other-window 1) 359 (gud-gdb (concat "gdb --fullname " input))) 360 361 ;; Sets the default compile command based on OS 362 (if (string= system-type "windows-nt") 363 (setq compile-command "build.bat") 364 (setq compile-command "./build.sh")) 365 366 (defun disable-all-themes () 367 "Disables all active themes." 368 (interactive) 369 (dolist (i custom-enabled-themes) 370 (disable-theme i))) 371 372 (defun update-theme () 373 "Set theme based on time of day" 374 (interactive) 375 (let ((hour (nth 2 (parse-time-string (current-time-string))))) 376 (disable-all-themes) 377 (if (and (> hour 9) 378 (< hour 18)) 379 (load-theme 'zenburn t) 380 (load-theme 'gruber-darker t)))) 381 382 (defun swap-theme () 383 "Swaps theme to either zenburn or gruber-darker" 384 (interactive) 385 (let ((theme (nth 0 custom-enabled-themes))) 386 (disable-all-themes) 387 (if (string= theme "gruber-darker") 388 (load-theme 'zenburn t) 389 (load-theme 'gruber-darker t)))) 390 391 (defun transparency (value) 392 "Sets the transparency of the frame window. 0=transparent/100=opaque" 393 (interactive "nTransparency Value 0 - 100 opaque: ") 394 (set-frame-parameter (selected-frame) 'alpha-background value)) 395 396 (load "device.el") 397 398 (setq default-frame-alist `((font . ,my-font))) 399 400 (defun toggle-big-font () 401 "Toggles on/off a bigger font for hidpi or presentations" 402 (interactive) 403 (if (eq (aref (font-info (face-attribute 'default :font)) 2) my-font-size) 404 (set-frame-font (concat "Iosevka Nerd Font:pixelsize=" (number-to-string my-font-big-size)) nil t) 405 (set-frame-font (concat my-font-name (number-to-string my-font-size)) nil t))) 406 407 (defun meow-setup () 408 (setq meow-cheatsheet-layout meow-cheatsheet-layout-colemak-dh) 409 (meow-motion-overwrite-define-key 410 ;; Use e to move up, n to move down. 411 ;; Since special modes usually use n to move down, we only overwrite e here. 412 '("e" . meow-prev) 413 '("<escape>" . ignore)) 414 (meow-motion-overwrite-define-key 415 '("i" . meow-prev) 416 '("e" . meow-next)) 417 (meow-leader-define-key 418 '("?" . meow-cheatsheet) 419 '("." . find-file) 420 '("," . switch-to-buffer) 421 '(">" . find-file-other-window) 422 '("<" . switch-to-buffer-other-window) 423 ;; To execute the originally e in MOTION state, use SPC e. 424 '("1" . meow-digit-argument) 425 '("2" . meow-digit-argument) 426 '("3" . meow-digit-argument) 427 '("4" . meow-digit-argument) 428 '("5" . meow-digit-argument) 429 '("6" . meow-digit-argument) 430 '("7" . meow-digit-argument) 431 '("8" . meow-digit-argument) 432 '("9" . meow-digit-argument) 433 '("0" . meow-digit-argument)) 434 (meow-normal-define-key 435 '("0" . meow-expand-0) 436 '("1" . meow-expand-1) 437 '("2" . meow-expand-2) 438 '("3" . meow-expand-3) 439 '("4" . meow-expand-4) 440 '("5" . meow-expand-5) 441 '("6" . meow-expand-6) 442 '("7" . meow-expand-7) 443 '("8" . meow-expand-8) 444 '("9" . meow-expand-9) 445 '("-" . negative-argument) 446 '(";" . meow-reverse) 447 '("," . meow-inner-of-thing) 448 '("." . meow-bounds-of-thing) 449 '("[" . meow-beginning-of-thing) 450 '("]" . meow-end-of-thing) 451 '("/" . meow-visit) 452 '("a" . meow-append) 453 '("A" . meow-open-below) 454 '("b" . meow-back-word) 455 '("B" . meow-back-symbol) 456 '("c" . meow-change) 457 '("i" . meow-prev) 458 '("I" . meow-prev-expand) 459 '("f" . meow-find) 460 '("g" . meow-cancel-selection) 461 '("G" . meow-grab) 462 '("n" . meow-left) 463 '("N" . meow-left-expand) 464 '("o" . meow-right) 465 '("O" . meow-right-expand) 466 '("j" . meow-join) 467 '("k" . meow-kill) 468 '("l" . meow-line) 469 '("L" . meow-goto-line) 470 '("h" . meow-mark-word) 471 '("H" . meow-mark-symbol) 472 '("e" . meow-next) 473 '("E" . meow-next-expand) 474 '("m" . meow-block) 475 '("M" . meow-to-block) 476 '("p" . meow-yank) 477 '("q" . meow-quit) 478 '("r" . meow-replace) 479 '("s" . meow-insert) 480 '("S" . meow-open-above) 481 '("t" . meow-till) 482 '("u" . meow-undo) 483 '("U" . meow-undo-in-selection) 484 '("v" . meow-search) 485 '("w" . meow-next-word) 486 '("W" . meow-next-symbol) 487 '("x" . meow-delete) 488 '("X" . meow-backward-delete) 489 '("y" . meow-save) 490 '("z" . meow-pop-selection) 491 '("'" . repeat) 492 '("<escape>" . ignore))) 493 494 (use-package meow 495 :ensure 496 :config 497 (meow-setup) 498 (meow-global-mode 1)) 499 500 (define-key dired-mode-map "o" 'dired-find-file) 501 (define-key dired-mode-map "n" 'dired-up-directory) 502 503 ;; ;; Startup time 504 ;; (defun efs/display-startup-time () 505 ;; (message 506 ;; "Emacs loaded in %s with %d garbage collections." 507 ;; (format 508 ;; "%.2f seconds" 509 ;; (float-time 510 ;; (time-subtract after-init-time before-init-time))) 511 ;; gcs-done)) 512 ;; (add-hook 'emacs-startup-hook #'efs/display-startup-time)