;; Time-stamp: <2024-01-07 15h17 CET (anker)> ;; ----------------------------------------------------------------------------- ;; General setup ;; Always split horizontally when compiling ;; (defadvice compile (around split-horizontally activate) ;; (let ((split-width-threshold 0) ;; (split-height-threshold nil)) ;; ad-do-it)) ;; Resize to fill column (and a little bit) ;; (defadvice compile (after resize-window-properly activate) ;; (let ((ww (window-width))) ;; (when (< ww (+ 5 fill-column)) ;; (enlarge-window-horizontally (- (+ 5 fill-column) ww))))) (defun align-to-equals (begin end) "Align region to equal signs" (interactive "r") (align-regexp begin end "\\(\\s-*\\)=" 1 1 )) (use-package centered-window :ensure t) (use-package hideshow :bind (("C-c C-f C-f" . hs-toggle-hiding))) (use-package dtrt-indent :ensure t :config (dtrt-indent-global-mode t)) (defun programming-setup () (subword-mode 1) (electric-pair-local-mode) (set-fill-column 80) (hs-minor-mode) (display-line-numbers-mode 1) (setq auto-hscroll-mode t) (yas-minor-mode-on)) (add-hook 'prog-mode-hook #'programming-setup) ;; ----------------------------------------------------------------------------- ;; Specific packages (use-package shift-number :ensure t :bind (("C-c s p" . shift-number-up) ("C-c s n" . shift-number-down))) (use-package comment-dwim-2 :ensure t :bind (("M-;" . comment-dwim-2)) :config (setq comment-multi-line t comment-style 'extra-line)) (use-package aggressive-indent :ensure t :defer t :config (setq aggressive-indent-sit-for-time 1)) (use-package yasnippet :ensure t :defer t :commands yas-minor-mode-on) (use-package elec-pair :defer t :config (setq electric-pair-delete-adjacent-pairs t electric-pair-skip-self 'electric-pair-default-skip-self electric-pair-preserve-balance t electric-pair-skip-whitespace t electric-pair-inhibit-predicate 'electric-pair-default-inhibit)) (use-package lsp-mode :ensure t :defer t :init (setq lsp-keymap-prefix "M-l" lsp-warn-no-matched-clients nil)) ;; ----------------------------------------------------------------------------- ;; C (use-package clang-format :ensure t :defer :config (setq clang-format-style "file")) (use-package cc-mode :defer t :bind (:map c-mode-map ("M-/" . lh-matching-delim)) :hook ((c-mode c++-mode) . (lambda () (when (string-match-p (regexp-quote "rdx-code") (buffer-file-name)) (c-set-style "radix")) (auto-fill-mode) ;; (aggressive-indent-mode) (set-fill-column 80) (abbrev-mode 0) (lsp) ;; clangd seems pretty good! (c-toggle-hungry-state 1) (c-toggle-electric-state 1) (c-toggle-syntactic-indentation 1))) :config (c-add-style "gnu-mod" '("gnu" (c-basic-offset . 2) ; Guessed value (c-offsets-alist (block-close . 0) ; Guessed value (case-label . +) ; Guessed value (defun-block-intro . +) ; Guessed value (defun-close . 0) ; Guessed value (statement . 0) ; Guessed value (statement-block-intro . +) ; Guessed value (statement-case-intro . 0) ; Guessed value (substatement . +) ; Guessed value (topmost-intro . 0) ; Guessed value (access-label . -) (annotation-top-cont . 0) (annotation-var-cont . +) (arglist-close . c-lineup-close-paren) (arglist-cont c-lineup-gcc-asm-reg 0) (arglist-cont-nonempty . c-lineup-arglist) (arglist-intro . +) (block-open . 0) (brace-entry-open . 0) (brace-list-close . 0) (brace-list-entry . 0) (brace-list-intro . +) (brace-list-open . 0) (c . c-lineup-C-comments) (catch-clause . 0) (class-close . 0) (class-open . 0) (comment-intro . c-lineup-comment) (composition-close . 0) (composition-open . 0) (cpp-define-intro c-lineup-cpp-define +) (cpp-macro . -1000) (cpp-macro-cont . +) (defun-open . 0) (do-while-closure . 0) (else-clause . 0) (extern-lang-close . 0) (extern-lang-open . 0) (friend . 0) (func-decl-cont . +) (inclass . +) (incomposition . +) (inexpr-class . +) (inexpr-statement . +) (inextern-lang . +) (inher-cont . c-lineup-multi-inher) (inher-intro . +) (inlambda . 0) (inline-close . 0) (inline-open . +) (inmodule . +) (innamespace . +) (knr-argdecl . 0) (knr-argdecl-intro . +) (label . 2) (lambda-intro-cont . +) (member-init-cont . c-lineup-multi-inher) (member-init-intro . +) (module-close . 0) (module-open . 0) (namespace-close . 0) (namespace-open . 0) (objc-method-args-cont . c-lineup-ObjC-method-args) (objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call +) (objc-method-intro . [0]) (statement-case-open . 0) (statement-cont . +) (stream-op . c-lineup-streamop) (string . -1000) (substatement-label . 2) (substatement-open . +) (template-args-cont c-lineup-template-args +) (topmost-intro-cont . c-lineup-topmost-intro-cont)))) (c-add-style "radix" '("gnu-mod" (c-basic-offset . 4))) (setq c-default-style '((java-mode . "java") (awk-mode . "awk") (other . "gnu-mod")))) ;; ----------------------------------------------------------------------------- ;; Python (use-package python-black :ensure t :after python :config (setq python-black-extra-args '("-l120")) ;; :hook (python-mode . python-black-on-save-mode-enable-dwim) ) (use-package highlight-indent-guides :ensure t :defer t :config (setq highlight-indent-guides-auto-odd-face-perc 10 highlight-indent-guides-auto-even-face-perc 15)) (use-package python :hook (python-mode . (lambda () (highlight-indent-guides-mode t) (visual-line-mode))) :bind (:map python-mode-map ("C-c C-f" . nil))) ;; ----------------------------------------------------------------------------- ;; Rust (use-package cargo :ensure t :defer t) (use-package flycheck-rust :ensure t :defer t) (use-package rust-mode :ensure t :defer t :bind (:map rust-mode-map ("M-," . lh-backward-delim) ("M-." . lh-forward-delim) ("M-/" . lh-matching-delim) ("M-p" . beginning-of-defun) ("M-n" . end-of-defun) ("C-c r c" . rust-compile) ("C-c r r" . rust-run)) :hook (rust-mode . (lambda () (require 'rust-mode) (cargo-minor-mode) ;; Pair {} in rust format strings ... ? (setq-local electric-pair-text-pairs (cons '(?{ . ?}) electric-pair-pairs)) (flycheck-rust-setup) (lsp))) :config (setq rust-indent-offset 4 rust-indent-method-chain t rust-indent-where-clause t rust-format-on-save t) (setq lsp-rust-server 'rust-analyzer lsp-rust-analyzer-call-info-full nil)) ;; ------------------------------------------------------------------- ;; Misc languages (use-package json-mode :ensure t :defer t :mode (("\\.json\\.jinja\\'" . json-mode) ("\\.jinja" . json-mode)) :hook (json-mode . (lambda () (programming-setup) (setq standard-indent 2) (setq js-indent-level 2) (setq tab-width 2 indent-tabs-mode nil))) :bind (:map json-mode-map ("C-c C-f" . nil))) (use-package zig-mode :ensure t :defer t :hook (zig-mode . (lambda () (lsp))) :init (defun my-zig-run () (interactive) (zig--run-cmd "build run")) :bind (:map zig-mode-map ("M-," . lh-backward-delim) ("M-." . lh-forward-delim) ("M-/" . lh-matching-delim) ("M-p" . beginning-of-defun) ("M-n" . end-of-defun) ("C-c C-c" . zig-compile) ("C-c r" . zig-run) ("C-c C-r" . my-zig-run)) :config (require 'lsp) (setq zig-format-on-save nil lsp-zig-zls-executable "/usr/bin/zls")) ;; (use-package js-comint ;; :ensure t ;; :defer t ;; :config ;; (setq js-comint-program-command "node" ;; js-comint-program-arguments nil)) ;; (use-package js2-mode ;; :ensure t ;; :defer t ;; :after js-comint ;; :mode "\\.js$" ;; :bind (:map js2-mode-map ;; ("TAB" . js2-indent-line) ;; ("C-x C-e" . js-send-last-sexp) ;; ("C-c C-b" . js-send-buffer) ;; ("C-c C-l" . js-load-file)) ;; :hook (js2-mode . (lambda () ;; (auto-revert-mode -1) ;; (yas-minor-mode-on)))) ;; (use-package lua-mode ;; :after nodemcu-mode ;; :ensure t ;; :defer t ;; :bind (:map lua-mode-map ;; ("C-x C-e" . lua-send-current-line) ;; ("C-c C-d" . lua-send-defun) ;; ("C-c C-e" . lua-send-region) ;; ("C-c C-u" . nodemcu-better-upload-current-file) ;; ("C-c C-t" . nodemcu-terminal) ;; ("M-n" . lua-forward-sexp) ;; ("M-p" . lua-backwards-to-block-begin-or-end)) ;; :hook (lua-mode . (lambda () ;; (require 'nodemcu-mode) ;; (nodemcu-mode 1)))) ;; (use-package gforth ;; :commands forth-mode ;; :mode (("\\.fs$" . forth-mode) ;; ("\\.fb$" . forth-block-mode) ;; ("\\.4th$" . forth-mode))) (use-package uxntal-mode :ensure t :defer t :config (setq uxntal-mode-strict-comments t)) ;; ------------------------------------------------------------------- ;; This goes last so that we can recover major mode hooks correctly (use-package treesit-auto :ensure t :config (global-treesit-auto-mode) (setq treesit-auto-install t) (setq rust-ts-mode-hook rust-mode-hook rust-ts-mode-map (make-composed-keymap rust-ts-mode-map rust-mode-map)))