From af3881fdfd45caea6da478ef56082d0c107f4a85 Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Tue, 9 Aug 2022 08:16:16 +0200 Subject: work inits --- emacs/work_inits/01-basic.el | 145 +++++++++++++++++++ emacs/work_inits/11-completion.el | 159 +++++++++++++++++++++ emacs/work_inits/13-ibuffer.el | 56 ++++++++ emacs/work_inits/15-project-mgmt.el | 30 ++++ emacs/work_inits/20-programming.el | 277 ++++++++++++++++++++++++++++++++++++ 5 files changed, 667 insertions(+) create mode 100644 emacs/work_inits/01-basic.el create mode 100644 emacs/work_inits/11-completion.el create mode 100644 emacs/work_inits/13-ibuffer.el create mode 100644 emacs/work_inits/15-project-mgmt.el create mode 100644 emacs/work_inits/20-programming.el (limited to 'emacs') diff --git a/emacs/work_inits/01-basic.el b/emacs/work_inits/01-basic.el new file mode 100644 index 0000000..ecfe165 --- /dev/null +++ b/emacs/work_inits/01-basic.el @@ -0,0 +1,145 @@ +;; Time-stamp: <2022-07-27 11h57 CEST (radix)> + +;; ----------------------------------------------------------------------------- +;; Interface + +(tool-bar-mode -1) +(menu-bar-mode -1) +(scroll-bar-mode -1) +(fset 'yes-or-no-p 'y-or-n-p) + +(setq select-enable-clipboard t + select-enable-primary t + save-interprogram-paste-before-kill t + require-final-newline t + visible-bell nil) + +(setq echo-keystrokes 0.1 + confirm-kill-emacs 'y-or-n-p + disabled-command-function nil + ring-bell-function 'ignore) + +(size-indication-mode t) + +(defun enlarge-to-fill () + "Stretch the buffer to accomodate `fill-column` many columns." + (interactive) + (let ((ww (window-width))) + (when (< ww (+ 1 fill-column)) + (enlarge-window-horizontally (- (+ 1 fill-column) ww))))) + +(global-set-key (kbd "C-c 3") (lambda () + (interactive) + (split-window-horizontally) + (enlarge-to-fill))) + +(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/") + +(when (eq 'x (window-system)) + ;;; Time-based theming + ;; (if (<= 20 (nth 2 (decode-time))) + ;; (load-theme 'nord t) + ;; (load-theme 'solo-jazz t)) + ;; (load-theme 'solo-jazz t) + (load-theme 'acme t) + (set-face-attribute 'font-lock-comment-face nil :slant 'italic) + ;; (set-face-attribute 'region nil :background "orange") + (set-face-attribute 'default nil :font "Iosevka Slab-10") + (set-face-attribute 'variable-pitch nil :font "Frank Ruehl CLM-18")) + + +(setq-default line-spacing nil) + +(blink-cursor-mode 0) +(setq cursor-type 'box) +;; (set-cursor-color "orange") + +(set-fringe-style 0) +;; (set-fringe-mode 128) + +;; ----------------------------------------------------------------------------- +;; Backups + +(setq backup-by-copying t + backup-directory-alist '(("." . "/home/user/store/backups/")) + delete-old-versions t + kept-new-versions 6 + kept-old-versions 2 + version-control t) + +(setq create-lockfiles nil) + +;; ----------------------------------------------------------------------------- +;; Defaults + +(setq fill-column 80) + +(setq standard-indent 4) +(setq-default tab-width 4 + indent-tabs-mode nil) +(add-hook 'before-save-hook #'whitespace-cleanup) + +(show-paren-mode t) + +(setq-default truncate-lines t + truncate-partial-width-windows nil) +(setq scroll-step 1 + scroll-margin 5) + +(setq next-line-add-newlines nil) + +(setq enable-dir-local-variables nil) + +(setq shell-file-name "bash") + +;; ----------------------------------------------------------------------------- +;; Basic packages + +(use-package recentf + :demand t + :config + (setq recentf-max-saved-items 42) + (recentf-mode)) + +(use-package uniquify + :config + (setq uniquify-buffer-name-style 'forward)) + +(use-package tramp + :config + (setq tramp-use-ssh-controlmaster-options nil)) + +(require 'saveplace) +(save-place-mode) + +;; (use-package undo-tree +;; :ensure t +;; :config (setq undo-tree-visualizer-timestamps t) +;; (global-undo-tree-mode 1)) + +;; (use-package keyfreq +;; :ensure t +;; :config +;; (setq keyfreq-file "~/.emacs.d/keyfreq" +;; keyfreq-file-lock "~/.emacs.d/keyfreq.lock") +;; (keyfreq-mode 1) +;; (keyfreq-autosave-mode 1)) + +;; ----------------------------------------------------------------------------- +;; Scratch buffer + +(defun immortal-scratch () + (if (eq (current-buffer) (get-buffer "*scratch*")) + (progn (bury-buffer) nil) t)) + +(add-hook 'kill-buffer-query-functions 'immortal-scratch) + +;; I couldn't understand the config options, so this is the next best thing +(defun display-startup-echo-area-message () nil) + +(setq initial-scratch-message nil + initial-buffer-choice t) + +(add-hook 'after-init-hook + (lambda () + (setq default-directory "~/"))) diff --git a/emacs/work_inits/11-completion.el b/emacs/work_inits/11-completion.el new file mode 100644 index 0000000..17b85d3 --- /dev/null +++ b/emacs/work_inits/11-completion.el @@ -0,0 +1,159 @@ +;; Time-stamp: <2022-07-28 14h06 CEST (radix)> + +;; ----------------------------------------------------------------------------- +;; Vertico + +(use-package vertico + :ensure t + :bind (:map vertico-map ("" . vertico-insert)) + :init + (vertico-mode) + (setq vertico-cycle t) + (setq completion-styles '(substring))) + +(use-package orderless + :ensure t + :config + (setq orderless-component-separator 'orderless-escapable-split-on-space + completion-styles '(orderless basic) + completion-category-overrides '((file (styles basic partial-completion))))) + +(use-package savehist + :ensure t + :init (savehist-mode)) + +(use-package emacs + :init + ;; Add prompt indicator to `completing-read-multiple'. + (defun crm-indicator (args) + (cons (concat "[CRM] " (car args)) (cdr args))) + (advice-add #'completing-read-multiple :filter-args #'crm-indicator) + + ;; Grow and shrink minibuffer + ;;(setq resize-mini-windows t) + + ;; Do not allow the cursor in the minibuffer prompt + (setq minibuffer-prompt-properties + '(read-only t cursor-intangible t face minibuffer-prompt)) + (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode) + + ;; Enable recursive minibuffers + (setq enable-recursive-minibuffers t)) + +;; ----------------------------------------------------------------------------- +;; Consult + +(use-package consult + :ensure t + :bind (;; C-c bindings (mode-specific-map) + ("C-c h" . consult-history) + ("C-c m" . consult-mode-command) + ("C-c b" . consult-bookmark) + ("C-c k" . consult-kmacro) + ;; C-x bindings (ctl-x-map) + ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command + ("C-x b" . consult-buffer) ;; orig. switch-to-buffer + ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window + ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame + ;; Custom M-# bindings for fast register access + ("M-#" . consult-register-load) + ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated) + ("C-M-#" . consult-register) + ;; Other custom bindings + ("M-y" . consult-yank-pop) ;; orig. yank-pop + (" a" . consult-apropos) ;; orig. apropos-command + ;; M-g bindings (goto-map) + ("M-g e" . consult-compile-error) + ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck + ;; ("C-s" . consult-line) ;; orig. goto-line + ("M-g M-g" . consult-goto-line) ;; orig. goto-line + ("M-g o" . consult-outline) ;; Alternative: consult-org-heading + ("M-g m" . consult-mark) + ("M-g k" . consult-global-mark) + ("M-g i" . consult-imenu) + ("M-g I" . consult-project-imenu) + ;; M-s bindings (search-map) + ("M-s f" . consult-find) + ("M-s L" . consult-locate) + ("C-c g" . consult-ripgrep) + ("C-c G" . consult-git-grep) + ("M-s l" . consult-line) + ("M-s m" . consult-multi-occur) + ("M-s k" . consult-keep-lines) + ("M-s u" . consult-focus-lines) + ;; Isearch integration + ;; ("M-s e" . consult-isearch) + :map isearch-mode-map + ;; ("M-e" . consult-isearch) ;; orig. isearch-edit-string + ;; ("M-s e" . consult-isearch) ;; orig. isearch-edit-string + ("M-s l" . consult-line)) ;; needed by consult-line to detect isearch + + :init + ;; Optionally configure the register formatting. This improves the register + ;; preview for `consult-register', `consult-register-load', + ;; `consult-register-store' and the Emacs built-ins. + (setq register-preview-delay 0 + register-preview-function #'consult-register-format) + + ;; Optionally tweak the register preview window. + ;; This adds thin lines, sorting and hides the mode line of the window. + (advice-add #'register-preview :override #'consult-register-window) + + ;; Use Consult to select xref locations with preview + (setq xref-show-xrefs-function #'consult-xref + xref-show-definitions-function #'consult-xref) + + :config + (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-buffer consult--source-project-buffer consult--source-bookmark + :preview-key (kbd "M-.")) + + (defun previous-history-or-next () + (interactive) + (if (string= "" (minibuffer-contents-no-properties)) + (progn + (previous-history-element 1) + (end-of-line)) + (vertico-next))) + + (defvar my-consult-line-map + (let ((map (make-sparse-keymap))) + (define-key map "\C-s" #'previous-history-or-next) + map)) + + (consult-customize consult-line :keymap my-consult-line-map) + + ;; Optionally configure the narrowing key. + ;; Both < and C-+ work reasonably well. + (setq consult-narrow-key "<") ;; (kbd "C-+") + + ;; Optionally make narrowing help available in the minibuffer. + ;; You may want to use `embark-prefix-help-command' or which-key instead. + ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help) + + ;; Projectile integration + (autoload 'projectile-project-root "projectile") + (setq consult-project-function #'projectile-project-root) + + ;; Ues consult for capfs + (setq completion-in-region-function #'consult-completion-in-region)) + +;; ----------------------------------------------------------------------------- +;; Marginalia + +(use-package marginalia + :ensure t + :bind (:map minibuffer-local-map ("M-A" . marginalia-cycle)) + :init (marginalia-mode)) + + +;; CTRLF +(use-package ctrlf + :ensure t + :config + (ctrlf-mode)) diff --git a/emacs/work_inits/13-ibuffer.el b/emacs/work_inits/13-ibuffer.el new file mode 100644 index 0000000..1562f29 --- /dev/null +++ b/emacs/work_inits/13-ibuffer.el @@ -0,0 +1,56 @@ +;; Time-stamp: <2022-06-13 10h46 CDT (radix)> + +(use-package ibuffer + :bind (("C-x C-b" . ibuffer)) + :hook (ibuffer-mode . (lambda () + (ibuffer-switch-to-saved-filter-groups "default"))) + :config + (setq ibuffer-display-summary nil + ibuffer-saved-filter-groups + '(("default" + ("c{,++}" (or (mode . c-mode) + (mode . c++-mode) + (mode . makefile-gmake-mode))) + ("dired" (mode . dired-mode)) + ("elisp" (or (mode . emacs-lisp-mode) + (name . "^\\*Backtrace\\*"))) + ("emacs" (or (name . "^\\*scratch\\*$") + (name . "^\\*Messages\\*$") + (name . "^\\*init log\\*$") + (name . "^\\*Compile-Log\\*$") + (mode . helpful-mode) + (name . "^\\*Help\\*$"))) + ("magit" (name . "^magit[:-]")) + ("python" (mode . python-mode)) + ("REPL" (name . "^\\*.*REPL.*\\*$"))))) + + (defadvice ibuffer-update-title-and-summary (after remove-column-titles) + (with-current-buffer "*Ibuffer*" + (read-only-mode -1) + (goto-char 1) + (search-forward "-\n" nil t) + (delete-region 1 (point)) + (let ((window-min-height 1)) + ;; save a little screen estate + (shrink-window-if-larger-than-buffer)) + (read-only-mode 1))) + + (ad-activate 'ibuffer-update-title-and-summary) + + (define-ibuffer-column size-h + (:name "Size" :inline t) + (cond + ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0))) + ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0))) + ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0))) + (t (format "%8d" (buffer-size))))) + + (setq ibuffer-formats + '((mark modified read-only locked " " + (name 18 18 :left :elide) + " " + (size-h 9 -1 :right) + " " + (mode 16 16 :left :elide) + " " + filename-and-process)))) diff --git a/emacs/work_inits/15-project-mgmt.el b/emacs/work_inits/15-project-mgmt.el new file mode 100644 index 0000000..a9e5336 --- /dev/null +++ b/emacs/work_inits/15-project-mgmt.el @@ -0,0 +1,30 @@ +;; Time-stamp: <2022-05-10 20h39 CDT (radix)> + +(use-package projectile + :ensure t + :bind (("C-c p" . projectile-switch-project) + ("C-c f" . projectile-find-file-dwim)) + :config + (projectile-mode 1) + + ;; (defadvice projectile-project-root (around ignore-remote first activate) + ;; (unless (file-remote-p default-directory) ad-do-it)) + + (setq projectile-indexing-method 'alien + projectile-sort-order 'recently-active + projectile-enable-caching t + projectile-require-root t + projectile-completion-system 'default + projectile-mode-line-prefix "" + projectile-mode-line-function '(lambda () + (format " ¶[%s]" (projectile-project-name))) + ;; projectile-mode-line-function '(lambda () " ¶") + )) + +(use-package magit + :ensure t + :bind (("C-x g" . magit-status)) + :config + (setq magit-process-find-password-functions '(magit-process-password-auth-source))) + +(setenv "SSH_AUTH_SOCK" "/home/user/.SSH_AGENT_vault-keys") diff --git a/emacs/work_inits/20-programming.el b/emacs/work_inits/20-programming.el new file mode 100644 index 0000000..90ab2d8 --- /dev/null +++ b/emacs/work_inits/20-programming.el @@ -0,0 +1,277 @@ +;; Time-stamp: <2022-07-21 10h34 CEST (radix)> + +;; ----------------------------------------------------------------------------- +;; 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))))) + +;; (use-package smart-tabs-mode +;; :ensure t +;; :config +;; (smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'ruby 'nxml) +;; (setq whitespace-style '(face trailing tabs spaces lines +;; newline empty space-before-tab space-mark tab-mark +;; newline-mark))) + +(defun align-to-equals (begin end) + "Align region to equal signs" + (interactive "r") + (align-regexp begin end "\\(\\s-*\\)=" 1 1 )) + +;; (use-package flycheck +;; :defer t +;; :ensure t) + +;; (use-package origami +;; :ensure t +;; :bind (("C-c C-f C-f" . origami-recursively-toggle-node) +;; ("C-c C-f C-o" . origami-show-only-node) +;; ("C-c C-f C-u" . origami-undo) +;; ("C-c C-f C-r" . origami-redo)) +;; :config +;; (global-origami-mode -1)) + +(use-package hideshow + :bind (("C-c C-f C-f" . hs-toggle-hiding))) + +(defun programming-setup () + (subword-mode 1) + (electric-pair-local-mode) + (set-fill-column 80) + (hs-minor-mode) + ;; Emacs25 compat + (if (fboundp 'display-line-numbers-mode) + (display-line-numbers-mode) + (linum-mode)) + (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) + +(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")) + +;; ----------------------------------------------------------------------------- +;; C + +;; What are these? +;; (setq gdb-show-threads-by-default nil +;; gdb-many-windows nil +;; gdb-show-main nil) + +(use-package cc-mode + :defer t + :bind (:map c-mode-map + ("M-/" . lh-matching-delim)) + :hook ((c-mode c++-mode) . (lambda () + (auto-fill-mode) + (set-fill-column 80) + (abbrev-mode 0) + ;; (flycheck-mode 1) + ;; (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 . 4) ; 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)))) + + (setq c-default-style '((java-mode . "java") + (awk-mode . "awk") + (other . "gnu-mod")))) + +;; ----------------------------------------------------------------------------- +;; Python + +;; (use-package yapfify +;; :ensure t +;; :defer t +;; :config +;; (setq yapfify-executable "yapf3")) + +(use-package highlight-indent-guides + :ensure t + :defer t + :config + (setq highlight-indent-guides-auto-odd-face-perc 1.5 + highlight-indent-guides-auto-even-face-perc 3)) + +(use-package python + :hook (python-mode . (lambda () + (highlight-indent-guides-mode) + ;; (yapf-mode) + )) + ;; :config + ;; (setq python-shell-interpreter "python3") + ) + +;; ------------------------------------------------------------------- +;; Misc languages + +(use-package json-mode + :ensure t + :defer t + :bind (:map json-mode-map + ("C-c C-f" . nil))) + +;; (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))) -- cgit v1.2.3