diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 712c684..0000000 --- a/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -custom.el -backups -eshell -elpaca - -eln-cache -elpa -org-roam.db -transient - -# projectile -projectile* - -# savehist file -history - -# recentf file -recentf - -session* - -# .org converted files -config*.el - -# Tramp connection file -tramp diff --git a/README.md b/README.md new file mode 100644 index 0000000..89897d5 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# emacs +My personal emacs configuration + +It is mostly based on tuhdo's emacs ide demo: https://github.com/tuhdo/emacs-c-ide-demo + +This configuration requires the installation of : + - the GNU global package (for gtags) + - clang (for ivory) + - cmake (for ivory) + - llvm-libs (for cmake, somehow not a dependency on Manjaro when installing cmake) + - Use python-pip to install jedi, flake8, importmagic and autopep8 (for elpy) + - ditaa (for ascii to image generation in org-mode) + +When first checking out this config, run irony-install-server to make and install the irony-server. diff --git a/README.org b/README.org deleted file mode 120000 index f13833e..0000000 --- a/README.org +++ /dev/null @@ -1 +0,0 @@ -config.org \ No newline at end of file diff --git a/cheat-sheet.txt b/cheat-sheet.txt new file mode 100644 index 0000000..ddd8cdd --- /dev/null +++ b/cheat-sheet.txt @@ -0,0 +1,8 @@ +C-M-Space : smartparens wrapping +C-c C-c : calculator (see init.el) +C-h k : lookup key sequence +C-x 0 : close current window +C-q : insert a +M-x (un)tabify : (replace) tabs +M-x describe-bindings : list of all mapped keys/commands +M-p : fill-paragraph, works for doxygen as well diff --git a/config.org b/config.org deleted file mode 100644 index fc60742..0000000 --- a/config.org +++ /dev/null @@ -1,1252 +0,0 @@ -#+STARTUP: overview -#+TITLE: My Emacs -#+CREATOR: Laurens Miers -#+LANGUAGE: en - -* General config - -#+BEGIN_SRC emacs-lisp - (use-package emacs - :ensure nil - :custom - (inhibit-startup-message t) - :init - (with-current-buffer (get-buffer-create "*scratch*") - (insert (format ";; - ;; ██╗ ██╗███████╗██╗ ██╗ ██████╗ - ;; ██║ ██║██╔════╝██║ ██║ ██╔═══██╗ - ;; ███████║█████╗ ██║ ██║ ██║ ██║ - ;; ██╔══██║██╔══╝ ██║ ██║ ██║ ██║ - ;; ██║ ██║███████╗███████╗███████╗╚██████╔╝ - ;; ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝ ╚═════╝ - ;; - ;; ███████╗███╗ ███╗ █████╗ ██████╗███████╗ - ;; ██╔════╝████╗ ████║██╔══██╗██╔════╝██╔════╝ - ;; █████╗ ██╔████╔██║███████║██║ ███████╗ - ;; ██╔══╝ ██║╚██╔╝██║██╔══██║██║ ╚════██║ - ;; ███████╗██║ ╚═╝ ██║██║ ██║╚██████╗███████║ - ;; ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚══════╝ - ;; - ;; Loading time : %s - ;; Packages : %s - ;; - " - (emacs-init-time) - (number-to-string (length package-activated-list))))) - - (message (emacs-init-time)) - ) -#+END_SRC - -** Package repos - -#+BEGIN_SRC emacs-lisp -(require 'package) -(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) -;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities` -;; and `package-pinned-packages`. Most users will not need or want to do this. -;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) -(package-initialize) -#+END_SRC - -** Use-package - -*** Always ensure - -#+BEGIN_SRC emacs-lisp -(require 'use-package-ensure) -(setq use-package-always-ensure t) -#+END_SRC - -** Bell - -The audible bell is annoying AF. - -#+BEGIN_SRC emacs-lisp -(setq visible-bell 1) -#+END_SRC - -** Enable column numbers - -#+BEGIN_SRC emacs-lisp -(setq column-number-mode 1) -#+END_SRC - -** Whitespace cleanup - -#+BEGIN_SRC emacs-lisp -(use-package whitespace - :ensure nil - :hook (before-save-hook . delete-trailing-whitespace) - ;; if we wanna remove this hook at any time, eval: - ;; (remove-hook 'before-save-hook #'whitespace-cleanup) - ) -#+END_SRC - -** Save history and recent files - -#+begin_src emacs-lisp -;; The built-in `savehist-mode' saves minibuffer histories. Vertico -;; can then use that information to put recently selected options at -;; the top. -;; -;; Further reading: https://protesilaos.com/emacs/dotemacs#h:25765797-27a5-431e-8aa4-cc890a6a913a -(savehist-mode 1) - -;; The built-in `recentf-mode' keeps track of recently visited files. -;; You can then access those through the `consult-buffer' interface or -;; with `recentf-open'/`recentf-open-files'. -;; -;; I do not use this facility, because the files I care about are -;; either in projects or are bookmarked. -(recentf-mode 1) -#+end_src - -** Backups - -#+BEGIN_SRC emacs-lisp -(defvar myrmi-backup-directory (concat user-emacs-directory "backups")) -(if (not (file-exists-p myrmi-backup-directory)) - (make-directory myrmi-backup-directory t) - ) -(setq backup-directory-alist `(("." . ,myrmi-backup-directory))) -(setq make-backup-files t - backup-by-copying t - version-control t - delete-old-versions t - delete-by-moving-to-trash t - kept-old-versions 6 - kept-new-versions 9 - auto-save-default t - auto-save-timeout 20 - auto-save-interval 200 - ) -#+END_SRC - -** Yes-or-no - -Because I'm lazy, important yes-or-no questions can be answered with y-or-n: -#+begin_src emacs-lisp -(defalias 'yes-or-no-p 'y-or-n-p) -#+end_src - -** Switch windows - -#+begin_src emacs-lisp -(global-set-key (kbd "M-o") 'other-window) -#+end_src - -** Maximize at startup - -More info : https://www.emacswiki.org/emacs/FullScreen - -#+begin_src emacs-lisp -(push '(fullscreen . maximized) default-frame-alist) -#+end_src - -** ibuffer - -Use list-buffers bigger brother. -#+begin_src emacs-lisp -(global-set-key [remap list-buffers] 'ibuffer) -#+end_src - -** Eldoc - -#+BEGIN_SRC emacs-lisp -(use-package eldoc - :ensure nil - :init - (global-eldoc-mode)) -#+END_SRC - -** Isearch - -Inspired by [[https://github.com/LionyxML/emacs-solo][emacs-solo]]: - -#+BEGIN_SRC emacs-lisp -(use-package isearch - :ensure nil - :config - (setq isearch-lazy-count t) ; Display number of matches - (setq lazy-count-prefix-format "(%s/%s) ") ; eye-candy to add braces - (defun isearch-copy-selected-word () - "Copy the current `isearch` selection to the kill ring." - (interactive) - (when isearch-other-end - (let ((selection (buffer-substring-no-properties isearch-other-end (point)))) - (kill-new selection) - (isearch-exit)))) - - ;; Bind `M-w` in isearch to copy the selected word, so M-s M-. M-w - ;; does a great job of 'copying the current word under cursor'. - (define-key isearch-mode-map (kbd "M-w") 'isearch-copy-selected-word)) -#+END_SRC - -Reference that might be interesting for later: -https://endlessparentheses.com/leave-the-cursor-at-start-of-match-after-isearch.html - -** Flymake - -#+BEGIN_SRC emacs-lisp -(use-package flymake - :ensure nil - :defer t - :hook - (prog-mode-hook . flymake-mode) - :custom - (flymake-show-diagnostics-at-end-of-line 'short) - (flymake-indicator-type 'margins) - (flymake-margin-indicators-string - `((error "!" compilation-error) - (warning "?" compilation-warning) - (note "i" compilation-info)) - ) - ) -#+END_SRC - -** Which-func - -Show function we are currently in in the mode-line. - -#+BEGIN_SRC emacs-lisp -(use-package which-func - :ensure nil - :defer t - :custom - (which-func-display 'mode-and-header) - :hook - (prog-mode-hook . which-function-mode) - ) -#+END_SRC - -** Line-numbers - -Show line numbers. -#+BEGIN_SRC emacs-lisp -(global-display-line-numbers-mode t) -#+END_SRC - -** Abbrev - -#+begin_src emacs-lisp -(global-set-key [remap dabbrev-expand] 'hippie-expand) -#+end_src - -** Zap - -#+begin_src emacs-lisp -(global-set-key (kbd "M-S-z") 'zap-up-to-char) -#+end_src - -** Spell checking - -Look into customizing the 'ispell' group. - -#+begin_src emacs-lisp -(add-hook 'prog-mode-hook 'flyspell-prog-mode) -#+end_src - -** Delete selection mode - -#+BEGIN_SRC emacs-lisp -(delete-selection-mode t) -#+END_SRC - -** Enable disabled commands - -Some commands are disabled to protect the user. -Narrow-region/page is a really handy feature, enable it: - -#+BEGIN_SRC emacs-lisp -(put 'narrow-to-page 'disabled nil) -(put 'narrow-to-region 'disabled nil) -#+END_SRC - -** Adaptive cursor width - -Make cursor the width of the character it is under f.e. full width of a tab. - -#+BEGIN_SRC emacs-lisp -(setq x-stretch-cursor t) -#+END_SRC - -** Enable auto-revert - -#+BEGIN_SRC emacs-lisp -(global-auto-revert-mode t) -#+END_SRC - -* Resize-mode - -Minor-mode to easily resize frames (works with EXWM (firefox, ...)). -Courtesy goes to kuanyui (https://gist.github.com/kuanyui/65a408d393871048771c): - -#+BEGIN_SRC emacs-lisp -;;; resize-frame.el --- A minor mode to resize frames easily. -*- lexical-binding: t; -*- - -;; Copyright (C) 2014 kuanyui - -;; Author: kuanyui -;; Keywords: frames, tools, convenience -;; License: WTFPL 1.0 - -;;; Commentary: - -;; Press "ESC `" and use arrow-keys or i/j/k/l to adjust frames. press any key to done. - -;;; Code: - -(defvar resize-frame-map - (let ((map (make-keymap))) - (define-key map (kbd "") 'enlarge-window) - (define-key map (kbd "") 'shrink-window) - (define-key map (kbd "") 'enlarge-window-horizontally) - (define-key map (kbd "") 'shrink-window-horizontally) - (set-char-table-range (nth 1 map) t 'resize-frame-done) - (define-key map (kbd "C-p") 'enlarge-window) - (define-key map (kbd "C-n") 'shrink-window) - (define-key map (kbd "C-f") 'enlarge-window-horizontally) - (define-key map (kbd "C-b") 'shrink-window-horizontally) - map)) - -(define-minor-mode resize-frame - "A simple minor mode to resize-frame. -C-c C-c to apply." - ;; The initial value. - :init-value nil - ;; The indicator for the mode line. - :lighter " ResizeFrame" - ;; The minor mode bindings. - :keymap resize-frame-map - :global t - (if (<= (length (window-list)) 1) - (progn (setq resize-frame nil) - (message "Only root frame exists, abort.")) - (message "Use arrow-keys or C-p/n/f/b to adjust frames."))) - -(defun resize-frame-done () - (interactive) - (setq resize-frame nil) - (message "Done.")) - -(global-set-key (kbd "C-x C-r") 'resize-frame) -#+END_SRC - -* Completion -** Minibuffer - -#+BEGIN_SRC emacs-lisp -(use-package vertico - :custom - ;; (vertico-scroll-margin 0) ;; Different scroll margin - ;; (vertico-count 20) ;; Show more candidates - ;; (vertico-resize t) ;; Grow and shrink the Vertico minibuffer - (vertico-cycle t) ;; Enable cycling for `vertico-next/previous' - :hook (after-init . vertico-mode) - ) -#+END_SRC - -** Consult - -#+BEGIN_SRC emacs-lisp -(use-package consult - ;; Replace bindings. Lazily loaded by `use-package'. - :bind (;; C-c bindings in `mode-specific-map' - ;; ("C-c M-x" . consult-mode-command) - ;; ("C-c h" . consult-history) - ;; ("C-c k" . consult-kmacro) - ;; ("C-c m" . consult-man) - ;; ("C-c i" . consult-info) - ([remap Info-search] . consult-info) - ;; C-x bindings in `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 - ("C-x t b" . consult-buffer-other-tab) ;; orig. switch-to-buffer-other-tab - ("C-x r b" . consult-bookmark) ;; orig. bookmark-jump - ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer - ;; 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 - ;; M-g bindings in `goto-map' - ("M-g e" . consult-compile-error) - ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck - ("M-g g" . consult-goto-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-i" . consult-imenu) - ("M-I" . consult-imenu-multi) - ;; M-s bindings in `search-map' - ("M-s d" . consult-find) ;; Alternative: consult-fd - ;; ("M-s c" . consult-locate) - ("M-s g" . consult-grep) - ;; ("M-s G" . consult-git-grep) - ;; ("M-s r" . consult-ripgrep) - ("M-s l" . consult-line) - ;; ("M-s L" . consult-line-multi) - ;; ("M-s k" . consult-keep-lines) - ;; ("M-s u" . consult-focus-lines) - ;; Isearch integration - ("M-s e" . consult-isearch-history) - :map isearch-mode-map - ("M-e" . consult-isearch-history) ;; orig. isearch-edit-string - ("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string - ("M-s l" . consult-line) ;; needed by consult-line to detect isearch - ("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch - ;; Minibuffer history - :map minibuffer-local-map - ("M-s" . consult-history) ;; orig. next-matching-history-element - ("M-r" . consult-history) ;; orig. previous-matching-history-element - ) - - ;; Enable automatic preview at point in the *Completions* buffer. This is - ;; relevant when you use the default completion UI. - :hook (completion-list-mode . consult-preview-at-point-mode) - - ;; The :init configuration is always executed (Not lazy) - :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.5 - ;; 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) - - ;; Configure other variables and modes in the :config section, - ;; after lazily loading the package. - ;; :config - - ;; Optionally configure preview. The default value - ;; is 'any, such that any key triggers the preview. - ;; (setq consult-preview-key 'any) - ;; (setq consult-preview-key "M-.") - ;; (setq consult-preview-key '("S-" "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)) - - ;; Optionally configure the narrowing key. - ;; Both < and C-+ work reasonably well. - ;; (setq consult-narrow-key "<") ;; "C-+" - - ;; Optionally make narrowing help available in the minibuffer. - ;; You may want to use `embark-prefix-help-command' or which-key instead. - ;; (keymap-set consult-narrow-map (concat consult-narrow-key " ?") #'consult-narrow-help) -) -#+END_SRC - -** In-buffer completion - -*** Consult - -#+BEGIN_SRC emacs-lisp -(setq completion-in-region-function - (lambda (&rest args) - (apply (if vertico-mode - #'consult-completion-in-region - #'completion--in-region) - args))) -#+END_SRC - -*** Corfu - -#+BEGIN_SRC emacs-lisp -(use-package corfu - ;; Optional customizations - :bind (:map corfu-map ("" . corfu-complete)) - :config - (setq tab-always-indent 'complete) - :custom - (corfu-cycle t) ;; Enable cycling for `corfu-next/previous' - (corfu-auto t) ;; Enable auto completion - ;; (corfu-separator ?\s) ;; Orderless field separator - ;; (corfu-quit-at-boundary nil) ;; Never quit at completion boundary - ;; (corfu-quit-no-match nil) ;; Never quit, even if there is no match - ;; (corfu-preview-current nil) ;; Disable current candidate preview - ;; (corfu-preselect 'prompt) ;; Preselect the prompt - ;; (corfu-on-exact-match nil) ;; Configure handling of exact matches - ;; (corfu-scroll-margin 5) ;; Use scroll margin - - ;; Enable Corfu only for certain modes. See also `global-corfu-modes'. - ;; :hook ((prog-mode . corfu-mode) - ;; (shell-mode . corfu-mode) - ;; (eshell-mode . corfu-mode)) - - ;; Recommended: Enable Corfu globally. This is recommended since Dabbrev can - ;; be used globally (M-/). See also the customization variable - ;; `global-corfu-modes' to exclude certain modes. - :init - (global-corfu-mode)) -#+end_src - -** Orderless - -#+BEGIN_SRC emacs-lisp -(use-package orderless - :demand t - :custom - (completion-styles '(orderless basic)) - ;; (gnus-completion-styles '(orderless substring basic)) - ;; (completion-category-overrides '((file (styles basic partial-completion)))) - -;; Below not necessary if using vertico -;; (completion-category-overrides '( -;; (command (styles orderless basic partial-completion)) -;; (file (styles orderless basic partial-completion)) -;;;; (buffer (styles orderless basic)) -;; (variable (styles orderless basic)) -;; (symbol (styles orderless basic)) -;; (consult-location (styles orderless)) -;; (consult-multi (styles orderless)) -;; ) -;; ) -) -#+END_SRC - -** Marginalia - -#+BEGIN_SRC emacs-lisp -;; Enable rich annotations using the Marginalia package -(use-package marginalia - ;; Bind `marginalia-cycle' locally in the minibuffer. To make the binding - ;; available in the *Completions* buffer, add it to the - ;; `completion-list-mode-map'. - :bind (:map minibuffer-local-map - ("M-A" . marginalia-cycle)) - - ;; The :init section is always executed. - :init - ;; Marginalia must be activated in the :init section of use-package such that - ;; the mode gets enabled right away. Note that this forces loading the - ;; package. - (marginalia-mode)) -#+END_SRC - -* Dired - -** Dired-x - -#+begin_src emacs-lisp -(with-eval-after-load 'dired - (require 'dired-x) - ;; Set dired-x global variables here. For example: - ;; (setq dired-x-hands-off-my-keys nil) - ) - -(add-hook 'dired-mode-hook - (lambda () - ;; Set dired-x buffer-local variables here. For example: - ;; (dired-omit-mode 1) - )) -#+end_src - -** Guess target directory - -I currently prefer to have two dired windows open in the same frame. -Instruct dired to 'Prefer next windows on the same frame' when renaming/copying files. - -#+BEGIN_SRC emacs-lisp -(setq dired-dwim-target 'dired-dwim-target-next) -#+END_SRC - -* Whole-line-or-region - -Source: -https://github.com/purcell/whole-line-or-region - -Operate on the current line if no region is active. - -#+begin_src emacs-lisp -(use-package whole-line-or-region - :config - (whole-line-or-region-global-mode 1) -) -#+end_src - -* Terminal -** Eshell -*** Smart mode - -Plan 9 smart terminal features, for more info: -https://www.masteringemacs.org/article/complete-guide-mastering-eshell - -#+BEGIN_SRC emacs-lisp -(require 'eshell) -(require 'em-smart) -(setq eshell-where-to-jump 'begin) -(setq eshell-review-quick-commands nil) -(setq eshell-smart-space-goes-to-end t) - -(add-hook 'eshell-mode-hook 'eshell-smart-initialize) -#+END_SRC - -** Toggle between char- and line-mode - -Courtesy goes to https://joelmccracken.github.io/entries/switching-between-term-mode-and-line-mode-in-emacs-term/ - -#+BEGIN_SRC emacs-lisp -(require 'term) - -(defun jnm/term-toggle-mode () - "Toggles term between line mode and char mode" - (interactive) - (if (term-in-line-mode) - (term-char-mode) - (term-line-mode))) - -(define-key term-mode-map (kbd "C-c C-j") 'jnm/term-toggle-mode) -(define-key term-mode-map (kbd "C-c C-k") 'jnm/term-toggle-mode) - -(define-key term-raw-map (kbd "C-c C-j") 'jnm/term-toggle-mode) -(define-key term-raw-map (kbd "C-c C-k") 'jnm/term-toggle-mode) -#+END_SRC - -For the keybindings, we have to defien them in both raw and line mode. From the help page of term mode: - If you define custom keybindings, make sure to assign them to the - correct keymap (or to both): use ‘term-raw-map’ in raw mode and - ‘term-mode-map’ in line mode. - -* Theme - -#+BEGIN_SRC emacs-lisp -(use-package monokai-theme - :config - (load-theme 'monokai t) -) -#+END_SRC - -* Dashboard - -#+begin_src emacs-lisp -(use-package dashboard - :custom - (dashboard-center-content t) ;; Center content - (dashboard-icon-type 'nerd-icons) ;; Nerd icons used - (dashboard-set-heading-icons t) ;; Heading icons enabled - (dashboard-set-file-icons t) ;; File icons enabled - (dashboard-startup-banner 'logo) ;; Use alternative logo - :config - (dashboard-setup-startup-hook)) -#+end_src - -* Hydra - -https://github.com/abo-abo/hydra - -#+BEGIN_SRC emacs-lisp -(use-package hydra - :config - ;; Zoom hydra - (defhydra hydra-zoom (global-map "") - "zoom" - ("g" text-scale-increase "in") - ("l" text-scale-decrease "out") - ) - - ) -#+END_SRC - -* Zygospore - -Revert =C-x 1= by pressing =C-x 1= again: -[[https://github.com/louiskottmann/zygospore.el]] - -FYI: At one point, used this together with sr-speedbar. They did not play well together... - -#+BEGIN_SRC emacs-lisp -(use-package zygospore - :config - (global-set-key (kbd "C-x 1") 'zygospore-toggle-delete-other-windows) -) -#+END_SRC - -* Iedit - -Highlight occurences of symbol and replace them simultanously. -Shortkey: =C-;= - -https://github.com/victorhge/iedit - -#+BEGIN_SRC emacs-lisp -(use-package iedit) -#+END_SRC - -* Programming - -** Angry faces - -#+BEGIN_SRC emacs-lisp -(defface highlight-angry-faces - '( - (default :background "Yellow" :foreground "Red") - ) - "Angry faces highlighting." - :group 'basic-faces -) - -(mapc (lambda (mode) - (font-lock-add-keywords - mode - '( - ("\\<\\(FIXME\\)" 1 'highlight-angry-faces t) - ("\\<\\(TODO\\)" 1 'highlight-angry-faces t) - ))) - '(text-mode emacs-lisp-mode rust-mode zig-mode c-ts-mode c-mode prog-mode) -) -#+END_SRC - -** Electric pair - -#+BEGIN_SRC emacs-lisp -(use-package elec-pair - :ensure nil - :defer t - :hook (prog-mode-hook . electric-pair-mode)) -#+END_SRC - -** Paren - -#+BEGIN_SRC emacs-lisp -(use-package paren - :ensure nil - :hook (after-init-hook . show-paren-mode) - :custom - (show-paren-delay 0) - (show-paren-style 'mixed) - (show-paren-context-when-offscreen t)) ;; show matches within window splits -#+END_SRC - -** Eglot - -#+BEGIN_SRC emacs-lisp -(use-package eglot - :ensure nil - :custom - (eglot-autoshutdown t) - :init - (setq eglot-stay-out-of '(xref)) - (add-hook 'prog-mode-hook 'eglot-ensure) - (add-hook 'eglot-managed-mode-hook (lambda () - (if (eglot-managed-p) - (add-hook 'xref-backend-functions 'eglot-xref-backend) - (remove-hook 'xref-backend-functions 'eglot-xref-backend) - ))) - - ) - -#+END_SRC - -** Markdown-mode - -#+BEGIN_SRC emacs-lisp -(use-package markdown-mode - :defer t -) - -#+END_SRC - -** Yasnippet - -#+BEGIN_SRC emacs-lisp -(use-package yasnippet - :hook - (prog-mode . yas-minor-mode) - (org-mode . yas-minor-mode) - (text-mode . yas-minor-mode) - :config - (yas-reload-all) -) -#+END_SRC - -** Magit - -*** Core - -#+BEGIN_SRC emacs-lisp -(use-package magit - :defer t - ) - -#+END_SRC - -** Dumb-jump - -#+BEGIN_SRC emacs-lisp -(use-package dumb-jump - :init - (add-hook 'xref-backend-functions #'dumb-jump-xref-activate) -) -#+END_SRC - -** C-programming - -*** Tree-sitter - -#+BEGIN_SRC emacs-lisp -(add-to-list 'major-mode-remap-alist '(c-mode . c-ts-mode)) -#+END_SRC - -** Compilation - -*** Goto end of buffer on completion - -Compilation output is almost always bigger than a normal buffer. -Move to the end if the compilation finishes. - -#+BEGIN_SRC emacs-lisp -(defun goto-end-compilation-buffer (comp-buffer msg) - (goto-char (point-max)) - ) - -(add-hook 'compilation-finish-functions #'goto-end-compilation-buffer) -#+END_SRC - -** Rust - -#+BEGIN_SRC emacs-lisp -(use-package rust-mode - :defer t - :init - (setq rust-mode-treesitter-derive t)) -#+END_SRC - -** Zig - -#+BEGIN_SRC emacs-lisp -(use-package zig-mode - :defer t - ) -#+END_SRC - -** Python - -#+BEGIN_SRC emacs-lisp -(use-package python-mode - :defer t - ) -#+END_SRC - -* Multiple cursors - -#+BEGIN_SRC emacs-lisp -(use-package multiple-cursors - :bind - ("C-x r a" . mc/edit-beginnings-of-lines) - ("C-x r e" . mc/edit-ends-of-lines) - ("C->" . mc/mark-next-like-this) - ("C-<" . mc/mark-previous-like-this) - ("C-c C->" . mc/mark-all-like-this) -) -#+END_SRC - -* Volatile highlights - -Show/highlight changes when doing undo/yanks/kills/... - -https://github.com/k-talo/volatile-highlights.el - -#+BEGIN_SRC emacs-lisp -(use-package volatile-highlights - :config - (volatile-highlights-mode t) -) -#+END_SRC - -* Comment-dwim-2 - -Replacement for built-in =comment-dwim=, more comment features. - -https://github.com/remyferre/comment-dwim-2 - -#+BEGIN_SRC emacs-lisp -(use-package comment-dwim-2 - :bind - ("M-;" . comment-dwim-2) -) -#+END_SRC - -* Projectile - -#+BEGIN_SRC emacs-lisp -(use-package projectile - :config - (setq projectile-enable-caching t) - (define-key projectile-mode-map (kbd "C-x p") 'projectile-command-map) - (projectile-mode +1) - (require 'project) - (add-hook 'project-find-functions #'project-projectile) -) -#+END_SRC -* Org - -** General config - -#+BEGIN_SRC emacs-lisp -(use-package org - :ensure nil - :defer t - :mode ("\\.org\\'" . org-mode) - :config - (setq - ;; Start collapsed for speed - org-startup-folded t - ;; Use ={}= for subscripting: https://orgmode.org/manual/Subscripts-and-superscripts.html - org-use-sub-superscripts '{} - ;; Preserve indentation in SRC blocks - org-src-preserve-indentation t - ) - ;; Ellipsis styling - (setq org-ellipsis " ▼ ") - (set-face-attribute 'org-ellipsis nil :inherit 'default :box nil)) -#+END_SRC - -** Org-todo - -*** Mark parent entry as DONE when children are DONE - -#+BEGIN_SRC emacs-lisp -(defun org-summary-todo (n-done n-not-done) - "Switch entry to DONE when all subentries are done, to TODO otherwise." - (let (org-log-done org-todo-log-states) ; turn off logging - (org-todo (if (= n-not-done 0) "DONE" "TODO")))) - -(add-hook 'org-after-todo-statistics-hook #'org-summary-todo) -#+END_SRC - -** Org bullets - -#+BEGIN_SRC emacs-lisp -(use-package org-bullets - :defer t - :after org - :config - (add-hook 'org-mode-hook (lambda () (org-bullets-mode)))) -#+END_SRC - -** Org Roam - -#+BEGIN_SRC emacs-lisp -(use-package org-roam - :demand - :custom - (org-roam-directory "~/projects/notes") - (org-roam-completion-everywhere t) - :config - (org-roam-setup) - (setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags}" 'face 'org-tag))) - (org-roam-db-autosync-mode) - ;; Add todo lists to org-agenda - (custom-set-variables '(org-agenda-files (directory-files-recursively org-roam-directory "todo\\.org$"))) - (load (expand-file-name "init.el" org-roam-directory) :no-error-if-file-is-missing) -) -#+END_SRC - -*** Consult - -#+BEGIN_SRC emacs-lisp -(use-package consult-org-roam - :ensure t - :after org-roam - :init - (require 'consult-org-roam) - ;; Activate the minor mode - (consult-org-roam-mode 1) - ;; :custom - ;; Use `ripgrep' for searching with `consult-org-roam-search' - ;; (consult-org-roam-grep-func #'consult-ripgrep) - - ;; Configure a custom narrow key for `consult-buffer', default is 'n', this sets it to 'r' - ;; (consult-org-roam-buffer-narrow-key ?r) - - ;; Display org-roam buffers right after non-org-roam buffers - ;; in consult-buffer (and not down at the bottom) - ;; (consult-org-roam-buffer-after-buffers t) - :config - ;; Eventually suppress previewing for certain functions - (consult-customize - consult-org-roam-forward-links - :preview-key "M-.") - :bind - ;; Define some convenient keybindings as an addition - ("C-c n f" . consult-org-roam-file-find) - ("C-c n b" . consult-org-roam-backlinks) - ("C-c n B" . consult-org-roam-backlinks-recursive) - ("C-c n l" . consult-org-roam-forward-links) - ("C-c n s" . consult-org-roam-search) - ("C-c n d" . org-roam-dailies-goto-today) - ) -#+END_SRC - -** Org Download - -#+BEGIN_SRC emacs-lisp -(use-package org-download - :defer t - :after org - :config - (add-hook 'dired-mode-hook 'org-download-enable) - ) -#+END_SRC - -* Elisp - -** Add demos to describe-function - -#+BEGIN_SRC emacs-lisp -(use-package elisp-demos - :config - (advice-add 'describe-function-1 :after #'elisp-demos-advice-describe-function-1) - ) -#+END_SRC - -* Custom - -** Modeline - -#+BEGIN_SRC emacs-lisp -(setq-default mode-line-format - '("%e" " " - ;; (:propertize " " display (raise +0.1)) ;; Top padding - ;; (:propertize " " display (raise -0.1)) ;; Bottom padding - (:propertize "𝝮 " face font-lock-keyword-face) - - (:propertize - ("" mode-line-mule-info mode-line-client mode-line-modified mode-line-remote mode-line-window-dedicated)) - - mode-line-frame-identification - mode-line-buffer-identification - " " - mode-line-position - mode-line-format-right-align - " " - (project-mode-line project-mode-line-format) - " " - (vc-mode vc-mode) - " " - mode-line-modes - mode-line-misc-info - mode-line-end-spaces) - project-mode-line t - mode-line-buffer-identification '(" %b") - mode-line-position-column-line-format '(" %l:%c")) -#+END_SRC - -** Org-roam - -Inspired by https://github.com/org-roam/org-roam/wiki/User-contributed-Tricks#filter-by-a-tag . - -#+BEGIN_SRC emacs-lisp -(defun myrmi/org-roam-node-find-tag-filter () - "Select a single tag from list and filter `org-roam-node' by it." - (interactive) - (let ((tag (car (completing-read-multiple "Tag: " - (org-roam-tag-completions))))) - (org-roam-node-find nil nil - (lambda (node) - (member tag - (org-roam-node-tags node)))))) -#+END_SRC - -** Font - -'Inspired' by https://protesilaos.com/codelog/2024-11-28-basic-emacs-configuration/#h:1e4fde73-a2a2-4dc5-82ad-02cf3884ece6 . -#+BEGIN_SRC emacs-lisp -(let ((mono-spaced-font "Monospace") - (proportionately-spaced-font "Sans")) - (set-face-attribute 'default nil :family mono-spaced-font :height 100) - (set-face-attribute 'fixed-pitch nil :family mono-spaced-font :height 1.0) - (set-face-attribute 'variable-pitch nil :family proportionately-spaced-font :height 1.0)) -#+END_SRC - -*** Icon fonts - -To make this setup work, the user must type M-x and then call the -command 'nerd-icons-install-fonts'. This will store the icon font files -in a local directory (on Linux this is ~/.local/share/fonts). - -#+BEGIN_SRC emacs-lisp -(use-package nerd-icons - :ensure t) - -(use-package nerd-icons-completion - :ensure t - :after marginalia - :config - (add-hook 'marginalia-mode-hook #'nerd-icons-completion-marginalia-setup)) - -(use-package nerd-icons-corfu - :ensure t - :after corfu - :config - (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter)) - -(use-package nerd-icons-dired - :ensure t - :hook - (dired-mode . nerd-icons-dired-mode)) -#+END_SRC - -** Sudo current buffer - -#+BEGIN_SRC emacs-lisp -(defun myrmi/sudo-current-buffer () - "Use TRAMP to `sudo' the current buffer." - (interactive) - (when buffer-file-name - (find-alternate-file - (concat "/sudo:root@localhost:" - buffer-file-name) - ) - ) -) -#+END_SRC - -** Save symbol at point - -#+BEGIN_SRC emacs-lisp -(defun myrmi/save-symbol-at-point () - "Make symbol at point the latest kill in the kill ring." - (interactive) - (let ((symbol (thing-at-point 'symbol))) - (when symbol (kill-new symbol)))) - -(global-set-key (kbd "C-M-w") 'myrmi/save-symbol-at-point) -#+END_SRC - -** Ceedling - -#+BEGIN_SRC emacs-lisp -(defvar ceedling-project-file-name "project.yml") -(defvar ceedling-cmd "ceedling") -(defvar ceedling-project-root ".") - -(defun myrmi/run-ceedling-tests (&optional file-name) - (interactive) - (let* ( - (file-path (or file-name buffer-file-name)) - (root-path (or (locate-dominating-file file-path ceedling-project-file-name) ceedling-project-root)) - ) - (compile - (concat "cd " root-path " && " ceedling-cmd) - ) - ) - ) -#+END_SRC - -** Set path to shell path - -#+BEGIN_SRC emacs-lisp -(defun set-exec-path-from-shell-PATH () - (let ((path-from-shell - (replace-regexp-in-string "[[:space:]\n]*$" "" - (shell-command-to-string "$SHELL -l -c 'echo $PATH'")))) - (setenv "PATH" path-from-shell) - (setq exec-path (split-string path-from-shell path-separator)))) - -(set-exec-path-from-shell-PATH) -#+END_SRC - -** Reload dir-locals.el - -#+BEGIN_SRC emacs-lisp -(defun myrmi/reload-dir-locals-for-current-buffer () - "Reload dir locals for the current buffer" - (interactive) - (let ((enable-local-variables :all)) - (hack-dir-local-variables-non-file-buffer))) - -(defun myrmi/reload-dir-locals-for-all-buffers-in-this-directory () - "For every buffer with the same `default-directory` as the - current buffer, reload dir-locals." - (interactive) - (let ((dir default-directory)) - (dolist (buffer (buffer-list)) - (with-current-buffer buffer - (when (equal default-directory dir) - (myrmi/reload-dir-locals-for-current-buffer)))))) -#+END_SRC - -** Visit/reload config - -These snippets assume my-config-file variable is set outside this configuration. -This should normally be done by the init.el to load this configuration. - -#+BEGIN_SRC emacs-lisp -(defun myrmi/visit-config () - "Visit emacs config" - (interactive) - (find-file my-config-file)) - -(defun myrmi/reload-config () - "Reload emacs config at runtime" - (interactive) - (org-babel-load-file my-config-file)) -#+END_SRC - -** Tips and Tricks - -*** Cheat-sheet - -| Key | Explanation | -|-----------------------+-----------------------------------------------------------| -| C-h k | Lookup key sequencesmartparens wrapping | -| C-q | Insert quoted/explicitly. F.e. to insert a tab, ... | -| M-x untabify/tabify | Convert to spaces/tabs | -| M-x describe-bindings | List all mapped keys/commands | -| M-q | Fill paragraph | - -** Minibuffer - -*** Close minibuffer when pressing C-g - -'Inspired' by https://protesilaos.com/codelog/2024-11-28-basic-emacs-configuration/#h:1e4fde73-a2a2-4dc5-82ad-02cf3884ece6 . -#+BEGIN_SRC emacs-lisp -(defun myrmi/keyboard-quit-dwim () - "Do-What-I-Mean behaviour for a general `keyboard-quit'. - -The generic `keyboard-quit' does not do the expected thing when -the minibuffer is open. Whereas we want it to close the -minibuffer, even without explicitly focusing it. - -The DWIM behaviour of this command is as follows: - -- When the region is active, disable it. -- When a minibuffer is open, but not focused, close the minibuffer. -- When the Completions buffer is selected, close it. -- In every other case use the regular `keyboard-quit'." - (interactive) - (cond - ((region-active-p) - (keyboard-quit)) - ((derived-mode-p 'completion-list-mode) - (delete-completion-window)) - ((> (minibuffer-depth) 0) - (abort-recursive-edit)) - (t - (keyboard-quit)))) - -(define-key global-map (kbd "C-g") #'myrmi/keyboard-quit-dwim) - -#+END_SRC diff --git a/config_old.org b/config_old.org deleted file mode 100644 index ff3b9cb..0000000 --- a/config_old.org +++ /dev/null @@ -1,1608 +0,0 @@ -#+STARTUP: overview -#+TITLE: My Emacs -#+CREATOR: Laurens Miers -#+LANGUAGE: en -[[./img/dash_logo.png]] - -* TABLE OF CONTENTS :toc: -- [[#installation][Installation]] - - [[#garbage-collection][Garbage collection]] -- [[#base-packages-to-install-first][Base packages to install first]] - - [[#elpaca][Elpaca]] - - [[#diminish][Diminish]] - - [[#hydra][Hydra]] -- [[#ivy][Ivy]] - - [[#flx][flx]] - - [[#ivy-1][Ivy]] -- [[#utils][Utils]] - - [[#custom-command-line-arguments][Custom command line arguments]] - - [[#kill-other-buffers][Kill other buffers]] - - [[#global-variables][Global variables]] - - [[#ripgrep][Ripgrep]] -- [[#term][Term]] - - [[#toggle-between-char--and-line-mode][Toggle between char- and line-mode]] - - [[#with-editor][With editor]] - - [[#eshell][Eshell]] -- [[#dired][Dired]] - - [[#single-buffer][Single-buffer]] - - [[#hideshow-dot-files][Hide/show dot-files]] -- [[#resize-frame][Resize frame]] -- [[#general-stuff][General stuff]] - - [[#unsorted][Unsorted]] - - [[#macros][Macro's]] - - [[#goto-line][Goto-line]] - - [[#rectangle][Rectangle]] - - [[#yes-or-no-questions][Yes-or-no questions]] - - [[#emacs-fullscreen-at-startup][Emacs fullscreen at startup]] - - [[#enable-disabled-commands][Enable disabled commands]] - - [[#buffers][Buffers]] - - [[#helping-vim-users][Helping vim-users]] - - [[#backup-files][Backup files]] - - [[#describe-key][Describe key]] - - [[#adaptive-cursor-width][Adaptive cursor width]] -- [[#which-key][Which-key]] -- [[#theme][Theme]] - - [[#highlight-line][Highlight line]] -- [[#dashboard][Dashboard]] -- [[#zygospore][Zygospore]] -- [[#mode-line][Mode-line]] - - [[#clock][Clock]] -- [[#editing-settings][Editing settings]] - - [[#kill-ring-customization][Kill-ring customization]] - - [[#newline-at-end-of-file][Newline at end-of-file]] - - [[#enable-column-numbers][Enable column numbers]] - - [[#look-and-feel-modifications][Look-and-feel modifications]] - - [[#automatic-indent][Automatic indent]] - - [[#delete-trailing-whitespace][Delete trailing whitespace]] - - [[#angry-faces][Angry faces]] - - [[#c-coding-settings][C Coding settings]] -- [[#undo-tree][Undo-tree]] -- [[#volatile-highlights][Volatile highlights]] -- [[#iedit][iedit]] -- [[#smartparens][Smartparens]] -- [[#comment-dwim-2][Comment-dwim-2]] -- [[#expand-region][Expand-region]] -- [[#windooze][Windooze]] -- [[#projectile][Projectile]] -- [[#mutliple-cursors][Mutliple cursors]] -- [[#gdb][GDB]] -- [[#magit][Magit]] -- [[#programming][Programming]] - - [[#yasnippet][Yasnippet]] - - [[#relative-line-numbers][(Relative) Line numbers]] - - [[#xref][xref]] - - [[#cc-mode][C/C++ mode]] - - [[#python-mode][Python mode]] - - [[#zig-mode][Zig mode]] - - [[#rust][Rust]] -- [[#windows][Windows]] - - [[#splitting][Splitting]] - - [[#switching][Switching]] - - [[#multi-frame-rebindings-obsolete-with-switch-window][Multi-frame rebindings (OBSOLETE with switch-window)]] -- [[#avy][Avy]] -- [[#convenience-stuff][Convenience stuff]] - - [[#visiting-the-configuration][Visiting the configuration]] - - [[#reload-the-configuration][Reload the configuration]] - - [[#subword][Subword]] - - [[#bell][Bell]] -- [[#server][Server]] -- [[#beacon][Beacon]] -- [[#org][Org]] - - [[#enabling-table-of-contents][Enabling table of contents]] - - [[#org-bullets][Org bullets]] - - [[#some-basic-config][Some basic config]] - - [[#note-config][Note config]] -- [[#shell-pop][Shell-pop]] -- [[#old-stuff-maybe-usefull-for-lookup-later][Old stuff, maybe usefull for lookup later]] - - [[#diff-mode-stuff][Diff mode stuff]] - - [[#speedbar][Speedbar]] -- [[#exwm][EXWM]] -- [[#transparency][Transparency]] -- [[#debugging][Debugging]] -- [[#todo][TODO]] - -* Installation - -My personal emacs configuration - -(Heavily) Inspired by the following configs: - - https://github.com/tuhdo/emacs-c-ide-demo - - https://github.com/daedreth/UncleDavesEmacs - -This configuration requires the installation of : - - - Use python-pip to install requirements for elpy: - =pip install jedi flake8 importmagic autopep8 yapf= - - =ditaa= (for ascii to image generation in org-mode) - -** Garbage collection - -Increase GC threshold to minimize time wasting on modern machines: -#+BEGIN_SRC emacs-lisp -(setq gc-cons-threshold 20000000) ;; 20 MB -#+END_SRC - -Recommendation stolen from https://github.com/lewang/flx?tab=readme-ov-file#gc-optimization . - -* Base packages to install first -** Elpaca - -Replacement for built-in package manager package.el : - -https://github.com/progfolio/elpaca - -#+BEGIN_SRC emacs-lisp - (defvar elpaca-installer-version 0.7) - (defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory)) - (defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory)) - (defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory)) - (defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git" - :ref nil :depth 1 - :files (:defaults "elpaca-test.el" (:exclude "extensions")) - :build (:not elpaca--activate-package))) - (let* ((repo (expand-file-name "elpaca/" elpaca-repos-directory)) - (build (expand-file-name "elpaca/" elpaca-builds-directory)) - (order (cdr elpaca-order)) - (default-directory repo)) - (add-to-list 'load-path (if (file-exists-p build) build repo)) - (unless (file-exists-p repo) - (make-directory repo t) - (when (< emacs-major-version 28) (require 'subr-x)) - (condition-case-unless-debug err - (if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*")) - ((zerop (apply #'call-process `("git" nil ,buffer t "clone" - ,@(when-let ((depth (plist-get order :depth))) - (list (format "--depth=%d" depth) "--no-single-branch")) - ,(plist-get order :repo) ,repo)))) - ((zerop (call-process "git" nil buffer t "checkout" - (or (plist-get order :ref) "--")))) - (emacs (concat invocation-directory invocation-name)) - ((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch" - "--eval" "(byte-recompile-directory \".\" 0 'force)"))) - ((require 'elpaca)) - ((elpaca-generate-autoloads "elpaca" repo))) - (progn (message "%s" (buffer-string)) (kill-buffer buffer)) - (error "%s" (with-current-buffer buffer (buffer-string)))) - ((error) (warn "%s" err) (delete-directory repo 'recursive)))) - (unless (require 'elpaca-autoloads nil t) - (require 'elpaca) - (elpaca-generate-autoloads "elpaca" repo) - (load "./elpaca-autoloads"))) - (add-hook 'after-init-hook #'elpaca-process-queues) - (elpaca `(,@elpaca-order)) -#+END_SRC - -*** Use-package support - -#+BEGIN_SRC emacs-lisp - ;; Install use-package support -(elpaca elpaca-use-package - ;; Enable :elpaca use-package keyword. - (elpaca-use-package-mode) - ;; Assume :elpaca t unless otherwise specified. - (setq elpaca-use-package-by-default t)) - -;; Always install when use-package is used -(eval-and-compile - (setq use-package-always-ensure t)) -#+END_SRC - -*** Wait till initialized - -#+BEGIN_SRC emacs-lisp -;;When installing a package which modifies a form used at the top-level -;;(e.g. a package which adds a use-package key word), -;;use `elpaca-wait' to block until that package has been installed/configured. -;;For example: -;;(use-package general :demand t) -;;(elpaca-wait) -(elpaca-wait) -#+END_SRC - -** Diminish - -https://github.com/emacsmirror/diminish - -#+begin_src emacs-lisp -(use-package diminish - :config - (diminish 'subword-mode) - (diminish 'auto-revert-mode) - ) -#+end_src - -** Hydra - -https://github.com/abo-abo/hydra - -#+begin_src emacs-lisp -(use-package hydra - :config - ;; Hydra zoom - (defhydra hydra-zoom (global-map "") - "zoom" - ("g" text-scale-increase "in") - ("l" text-scale-decrease "out") - ) -) -#+end_src - -* Ivy -** flx - -Fuzzy matching: -https://github.com/lewang/flx - -#+begin_src emacs-lisp -(use-package flx) -#+end_src - -** Ivy - -Generic completion frontend: -https://github.com/abo-abo/swiper - -#+begin_src emacs-lisp -(use-package ivy - :defer 0.1 ;; TODO: fixes ivy not loading at startup, not sure why - :diminish - :bind (("C-x B" . ivy-switch-buffer-other-window) - :map ivy-minibuffer-map - ("TAB" . ivy-alt-done) - :map ivy-switch-buffer-map - ("C-d" . ivy-switch-buffer-kill) - :map ivy-occur-grep-mode-map - ("C-x e" . ivy-wgrep-change-to-wgrep-mode) - ("C-x C-s" . wgrep-finish-edit) - ("C-q" . wgrep-abort-changes) - ) - :config - (setq ivy-re-builders-alist - '( - (swiper . ivy--regex-fuzzy) - (t . ivy--regex-ignore-order) - ) - ) - (setq ivy-use-virtual-buffers t) ;; Add recent files + bookmarks to ivy-switch-buffer - (setq ivy-count-format "(%d/%d) ") ;; Style to use for displaying current candidate count - (ivy-mode) -) - -(use-package counsel - :after ivy - :diminish - :bind ( - ("C-x f" . counsel-fzf) - ) - :config - (counsel-mode) -) - -(use-package swiper - :after ivy - :bind ( - ("C-s" . swiper-thing-at-point) - ) -) - -(use-package ivy-hydra - :after (ivy hydra) -) - -(use-package ivy-rich - :after ivy - :init - (ivy-rich-mode 1) -) -#+end_src - -* Utils - -** Custom command line arguments - -Return if a custom command line arguments was found. -If it was found, we delete it from the list of command line arguments. - -#+BEGIN_SRC emacs-lisp -(defun found-custom-arg (switch) - (let ((found-switch (member switch command-line-args))) - (setq command-line-args (delete switch command-line-args)) - found-switch)) -#+END_SRC - -** Kill other buffers - -Function to kill other buffers but the current open one (and some standard buffers which should be kept alive). -Stolen from https://www.emacswiki.org/emacs/KillingBuffers . - -#+BEGIN_SRC emacs-lisp - -(setq not-to-kill-buffer-list '("*scratch*" "*Messages*")) - -(defun kill-other-buffers () - "Kill all other buffers." - (interactive) - (if (member (buffer-name (current-buffer)) not-to-kill-buffer-list) - (bury-buffer) - (kill-buffer (current-buffer)))) -#+END_SRC - -** Global variables - -Some package behave strangely if we have custom command line parameters. -F.e. Dashboard assumes you are directly opening a file so it won't load the dashboard. - -So, we remove our custom variables from the command line arguments and set global 'flags'. -These flags will enable/disable parts of the config. - -#+BEGIN_SRC emacs-lisp -(setq EXWM_ENABLE nil) - -(if (found-custom-arg "-start_wm") - (setq EXWM_ENABLE t) -) - -#+END_SRC - -** Ripgrep - -#+BEGIN_SRC emacs-lisp -(use-package rg - :config - (rg-enable-menu) ;; Enable transient menu - ) -#+END_SRC - -* Term - -** Toggle between char- and line-mode - -Courtesy goes to https://joelmccracken.github.io/entries/switching-between-term-mode-and-line-mode-in-emacs-term/ - -#+BEGIN_SRC emacs-lisp -(require 'term) - -(defun jnm/term-toggle-mode () - "Toggles term between line mode and char mode" - (interactive) - (if (term-in-line-mode) - (term-char-mode) - (term-line-mode))) - -(define-key term-mode-map (kbd "C-c C-j") 'jnm/term-toggle-mode) -(define-key term-mode-map (kbd "C-c C-k") 'jnm/term-toggle-mode) - -(define-key term-raw-map (kbd "C-c C-j") 'jnm/term-toggle-mode) -(define-key term-raw-map (kbd "C-c C-k") 'jnm/term-toggle-mode) -#+END_SRC - -** With editor -This will ensure things/commands/... called in eshell/shell that use $EDITOR, will use the current Emacs. - -#+BEGIN_SRC emacs-lisp -(use-package with-editor - :commands with-editor-export-editor - :init - (progn - (add-hook 'shell-mode-hook 'with-editor-export-editor) - (add-hook 'eshell-mode-hook 'with-editor-export-editor))) -#+END_SRC - -** Eshell - -*** Smart mode - -Plan 9 smart terminal features, for more info: -https://www.masteringemacs.org/article/complete-guide-mastering-eshell - -#+BEGIN_SRC emacs-lisp -(require 'eshell) -(require 'em-smart) -(setq eshell-where-to-jump 'begin) -(setq eshell-review-quick-commands nil) -(setq eshell-smart-space-goes-to-end t) - -(add-hook 'eshell-mode-hook 'eshell-smart-initialize) -#+END_SRC - -*** Remember password - -In order to make eshell remember the password for X time after entering it, we have to do a few things. - -We first have to switch to eshell/sudo if we want to be independent of the underlying OS. -We could use an alias (alias sudo eshell/sudo $*), but to keep things inside this config file, switch to lisp functions before we set the password cache: - -#+BEGIN_SRC emacs-lisp -(require 'em-tramp) ; to load eshell’s sudo - -(setq eshell-prefer-lisp-functions t) -(setq eshell-prefer-lisp-variables t) - -(setq password-cache t) ; enable password caching -(setq password-cache-expiry 3600) ; for one hour (time in secs) -#+END_SRC - -** Vterm - -#+BEGIN_SRC emacs-lisp -(use-package vterm - :ensure t - ) -#+END_SRC - -* Dired - - -** Single-buffer - -#+begin_src emacs-lisp -(use-package dired-single - :bind ( - :map dired-mode-map - ([remap dired-find-file] . dired-single-buffer) - ([remap dired-mouse-find-file-other-window] . dired-single-buffer-mouse) - ([remap dired-up-directory] . dired-single-up-directory) - ("" . dired-single-up-directory) - ) - :custom - (dired-listing-switches "-agho --group-directories-first") - (dired-dwim-target t) ;; Make dired guess the target directory for copy/... operations -) -#+end_src - -** Hide/show dot-files - -#+begin_src emacs-lisp -(use-package dired-hide-dotfiles - :hook (dired-mode . dired-hide-dotfiles-mode) - :bind ( - :map dired-mode-map - ("H" . dired-hide-dotfiles-mode) - ) -) -#+end_src - -* Resize frame - -Minor-mode to easily resize frames (works with EXWM (firefox, ...)). -Courtesy goes to kuanyui (https://gist.github.com/kuanyui/65a408d393871048771c): - -#+BEGIN_SRC emacs-lisp -;;; resize-frame.el --- A minor mode to resize frames easily. -*- lexical-binding: t; -*- - -;; Copyright (C) 2014 kuanyui - -;; Author: kuanyui -;; Keywords: frames, tools, convenience -;; License: WTFPL 1.0 - -;;; Commentary: - -;; Press "ESC `" and use arrow-keys or i/j/k/l to adjust frames. press any key to done. - -;;; Code: - -(defvar resize-frame-map - (let ((map (make-keymap))) - (define-key map (kbd "") 'enlarge-window) - (define-key map (kbd "") 'shrink-window) - (define-key map (kbd "") 'enlarge-window-horizontally) - (define-key map (kbd "") 'shrink-window-horizontally) - (set-char-table-range (nth 1 map) t 'resize-frame-done) - (define-key map (kbd "C-p") 'enlarge-window) - (define-key map (kbd "C-n") 'shrink-window) - (define-key map (kbd "C-f") 'enlarge-window-horizontally) - (define-key map (kbd "C-b") 'shrink-window-horizontally) - map)) - -(define-minor-mode resize-frame - "A simple minor mode to resize-frame. -C-c C-c to apply." - ;; The initial value. - :init-value nil - ;; The indicator for the mode line. - :lighter " ResizeFrame" - ;; The minor mode bindings. - :keymap resize-frame-map - :global t - (if (<= (length (window-list)) 1) - (progn (setq resize-frame nil) - (message "Only root frame exists, abort.")) - (message "Use arrow-keys or i/j/k/l to adjust frames."))) - -(defun resize-frame-done () - (interactive) - (setq resize-frame nil) - (message "Done.")) - -(global-set-key (kbd "C-x C-r") 'resize-frame) -#+END_SRC - -* General stuff -** Unsorted - -Collection of stuff that needs to be sorted...someday....maybe... -#+BEGIN_SRC emacs-lisp -(global-set-key (kbd "M-p") 'fill-paragraph) -#+END_SRC -** Macro's - -Rebind the macro keys to Fx keys to give them a decent purpose. - -#+BEGIN_SRC emacs-lisp -(global-set-key [f9] 'start-kbd-macro) -(global-set-key [f10] 'end-kbd-macro) -(global-set-key [f11] 'call-last-kbd-macro) -#+END_SRC - -** Goto-line - -Starting with Emacs 23.2, =M-g g= is bound to goto-line. -However, I find this too long. So rebind it: - -#+BEGIN_SRC emacs-lisp -(global-set-key (kbd "M-g") 'goto-line) -#+END_SRC - -** Rectangle - -Most rectangle functions are by default mapped to something like =C-x r (other-char)=. -I use =string-insert-rectangle= and =query-replace-regexp= quite a lot, -so rebind it to something easy to remember. - -#+BEGIN_SRC emacs-lisp -(global-set-key (kbd "C-x r i") 'string-insert-rectangle) -(global-set-key (kbd "C-x r r") 'query-replace-regexp) -#+END_SRC - -** Yes-or-no questions - -Because I'm lazy, important yes-or-no questions can be answered with y-or-n: - -#+BEGIN_SRC emacs-lisp -(defalias 'yes-or-no-p 'y-or-n-p) -#+END_SRC - -** Emacs fullscreen at startup - -#+BEGIN_SRC emacs-lisp -(add-to-list 'default-frame-alist '(fullscreen . maximized)) -#+END_SRC - -** Enable disabled commands - -Some commands are disabled to protect the user. -Narrow-region/page is a really handy feature, enable it: - -#+BEGIN_SRC emacs-lisp -(put 'narrow-to-page 'disabled nil) -(put 'narrow-to-region 'disabled nil) -#+END_SRC - -** Buffers - -Why is this not built-in? - -#+BEGIN_SRC emacs-lisp -(defun kill-all-buffers () - "Kill all buffers without regard for their origin." - (interactive) - (mapc 'kill-buffer (buffer-list))) -#+END_SRC - -** Helping vim-users - -#+BEGIN_SRC emacs-lisp -(defconst wq "This is not vi! Use C-x C-c instead.") -(defconst w "This is not vi! Use C-x C-s instead.") -(defconst q! "This is EMACS not vi! Use C-x C-c instead.") -(defconst wq! "This is EMACS not vi! Use C-x C-c instead.") -#+END_SRC - -** Backup files - -Disable the generation of backup-files, I don't use them. - -#+BEGIN_SRC emacs-lisp -(setq make-backup-files nil) -#+END_SRC - -** Describe key - -Describe key will open a new buffer with the relevant information. -However, it stays in the current window and opens a new window with the help-info, forcing you to switch buffers to close the help window. -This small function just switches the focus to the newly opened window so we can close it more easily. - -#+BEGIN_SRC emacs-lisp -(defun move-to-help-window () - (switch-to-buffer-other-window "*Help*") -) -(add-hook 'help-mode-hook 'move-to-help-window) -#+END_SRC - -** Adaptive cursor width - -Make cursor the width of the character it is under f.e. full width of a tab. - -#+BEGIN_SRC emacs-lisp -(setq x-stretch-cursor t) -#+END_SRC - -* Which-key - -Display available keybindings in popup: -https://github.com/justbur/emacs-which-key - -#+BEGIN_SRC emacs-lisp -(use-package which-key - :diminish - :config - (which-key-setup-side-window-bottom) - (which-key-mode)) -#+END_SRC - -* Theme - -#+BEGIN_SRC emacs-lisp -(use-package monokai-theme - :init - (load-theme 'monokai t) -) -#+END_SRC - -** Highlight line - -Highlight line will highlight the current line we are on. -Enable highlight-line globally and replace its background colour. - -#+BEGIN_SRC emacs-lisp -(global-hl-line-mode 1) -(set-face-background hl-line-face "dark slate grey") -#+END_SRC - -* Dashboard - -I use the dashboard as start screen. -Since I like it to give me a list of recent files, we need to enable =recentf-mode=. - -#+BEGIN_SRC emacs-lisp -(use-package dashboard - :init - (recentf-mode 1) - :config - (dashboard-setup-startup-hook) - (setq dashboard-center-content t) - (setq dashboard-startup-banner "~/.emacs.d/img/dash_logo.png") - (setq dashboard-items '((recents . 10) - (bookmarks . 5) - (projects . 5) - )) - (setq dashboard-banner-logo-title "") - (setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*"))) -) -#+END_SRC - -Important to note, =dashboard-setup-startup-hook= will not display the dashboard when command-line arguments are provided. -It assumes the command line arguments are filenames and skips showing the dashboard. - -* Zygospore - -Revert =C-x 1= by pressing =C-x 1= again: -[[https://github.com/louiskottmann/zygospore.el]] - -FYI: At one point, used this together with sr-speedbar. They did not play well together... - -#+BEGIN_SRC emacs-lisp -(use-package zygospore - :config - (global-set-key (kbd "C-x 1") 'zygospore-toggle-delete-other-windows) -) -#+END_SRC - -* Mode-line - -[[https://github.com/Malabarba/smart-mode-line]] - -#+BEGIN_SRC emacs-lisp -(use-package smart-mode-line - :config - (setq sml/no-confirm-load-theme t) - (setq sml/theme 'respectful) - (sml/setup) -) -#+END_SRC - -** Clock - -#+BEGIN_SRC emacs-lisp - (setq display-time-24hr-format t) - (setq display-time-format "%H:%M - %d %b %Y") - (setq display-time-default-load-average nil) - - (display-time-mode 1) -#+END_SRC - -* Editing settings - -** Kill-ring customization - -Setting =kill-whole-line= to non-nil means when we execute =C-k= at the beginning of a line -will the entire line including the following newline will be deleted. - -#+BEGIN_SRC emacs-lisp -(setq kill-ring-max 5000) ; increase kill-ring capacity -;; (setq kill-whole-line t) -#+END_SRC - -** Newline at end-of-file - -#+BEGIN_SRC emacs-lisp -(setq mode-require-final-newline t) ; add a newline to end of file -#+END_SRC - -** Enable column numbers - -#+BEGIN_SRC emacs-lisp -(setq column-number-mode 1) -#+END_SRC - -** Look-and-feel modifications - -Remove scroll-, tool- and menu-bar. I don't use them so free some space. - -#+BEGIN_SRC emacs-lisp -(scroll-bar-mode -1) -(tool-bar-mode -1) -(menu-bar-mode -1) -#+END_SRC - -** Automatic indent - -Automatically indent when pressing =RET=. -#+BEGIN_SRC emacs-lisp -(global-set-key (kbd "RET") 'newline-and-indent) -#+END_SRC - -** Delete trailing whitespace - -Automatically delete trailing whitespace when saving a file. - -#+BEGIN_SRC emacs-lisp -(add-hook 'before-save-hook 'delete-trailing-whitespace) -#+END_SRC - -** Angry faces - -#+BEGIN_SRC emacs-lisp -;; make angry face to get my attention -(setq prog-modes '(c++-mode python-mode erlang-mode java-mode c-mode emacs-lisp-mode scheme-mode prog-mode)) -(make-face 'font-lock-angry-face) -(modify-face 'font-lock-angry-face "Red" "Yellow" nil t nil t nil nil) - -;; Add keywords to recognize to angry face -(mapc (lambda (mode) - (font-lock-add-keywords - mode - '(("\\<\\(FIXME\\)" 1 'font-lock-angry-face t))) - ) - prog-modes) -(mapc (lambda (mode) - (font-lock-add-keywords - mode - '(("\\<\\(TODO\\)" 1 'font-lock-angry-face t))) - ) - prog-modes) -#+END_SRC - -** C Coding settings - -Some basic C-coding settings (style, indentation offset, ...). - -#+BEGIN_SRC emacs-lisp -;; default coding style -(setq c-default-style "linux") -#+END_SRC - -* Undo-tree - -Undo with =C-/=. - -#+BEGIN_SRC emacs-lisp -(use-package undo-tree - :diminish - :config - (global-undo-tree-mode) - (setq undo-tree-auto-save-history t) ;; Enable auto-save of undo history - (setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo"))) ;; Move undo-files to separate dir to avoid corrupting project with undo-files -) -#+END_SRC - -Move the undo-files to a separate folder and also auto-save. -Define the same behaviour for tramp-files to not pollute the remove file system. -Stolen from: https://emacs.stackexchange.com/questions/33/put-all-backups-into-one-backup-folder . -Not using it now due to use of undo-tree but leaving it here as a reference - -#+BEGIN_SRC emacs-lisp -;; (let ((backup-dir "~/.emacs.d/backups") -;; (auto-saves-dir "~/.emacs.d/auto-saves/")) -;; (dolist (dir (list backup-dir auto-saves-dir)) -;; (when (not (file-directory-p dir)) -;; (make-directory dir t))) -;; (setq backup-directory-alist `(("." . ,backup-dir)) -;; undo-tree-history -;; auto-save-file-name-transforms `((".*" ,auto-saves-dir t)) -;; auto-save-list-file-prefix (concat auto-saves-dir ".saves-") -;; tramp-backup-directory-alist `((".*" . ,backup-dir)) -;; tramp-auto-save-directory auto-saves-dir)) - -;; (setq backup-by-copying t ; Don't delink hardlinks -;; delete-old-versions t ; Clean up the backups -;; version-control t ; Use version numbers on backups, -;; kept-new-versions 5 ; keep some new versions -;; kept-old-versions 2) ; and some old ones, too -#+END_SRC - -* Volatile highlights - -Show/highlight changes when doing undo/yanks/kills/... - -https://github.com/k-talo/volatile-highlights.el - -#+BEGIN_SRC emacs-lisp -(use-package volatile-highlights - :diminish - :config - (volatile-highlights-mode t) -) -#+END_SRC - -* iedit - -Highlight occurences of symbol and replace them simultanously. -Shortkey: =C-;= - -https://github.com/victorhge/iedit - -#+BEGIN_SRC emacs-lisp -(use-package iedit -) -#+END_SRC - -* Smartparens - -Smart minor-mode to deal with pairs. -Extra options: - - =show-smartparens-global-mode= : highlight corresponding bracket/pair/... - - =smartparens-global-mode= : enable smartparens - -https://github.com/Fuco1/smartparens - -#+BEGIN_SRC emacs-lisp -(use-package smartparens - :bind - ("C-M-k" . sp-kill-sexp) - ("C-M-w" . sp-copy-sexp) - :config - (require 'smartparens-config) - (show-smartparens-global-mode t) - (smartparens-global-mode t) -) - -;; old config stuff -;; (setq sp-base-key-bindings 'paredit) -;; (setq sp-autoskip-closing-pair 'always) -;; (setq sp-hybrid-kill-entire-symbol nil) -;; (sp-use-paredit-bindings) -;; -;; (show-smartparens-global-mode +1) -;; (smartparens-global-mode 1) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; keybinding management smartparens ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; cl-package contains the loop macro -;; (require 'cl) -;; -;; (defmacro def-pairs (pairs) -;; `(progn -;; ,@(loop for (key . val) in pairs -;; collect -;; `(defun ,(read (concat -;; "wrap-with-" -;; (prin1-to-string key) -;; "s")) -;; (&optional arg) -;; (interactive "p") -;; (sp-wrap-with-pair ,val))))) -;; -;; (def-pairs ((paren . "(") -;; (bracket . "[") -;; (brace . "{") -;; (single-quote . "'") -;; (double-quote . "\"") -;; (underscore . "_") -;; (back-quote . "`"))) -;; -;; (define-key smartparens-mode-map (kbd "C-c (") 'wrap-with-parens) -;; (define-key smartparens-mode-map (kbd "C-c [") 'wrap-with-brackets) -;; (define-key smartparens-mode-map (kbd "C-c {") 'wrap-with-braces) -;; (define-key smartparens-mode-map (kbd "C-c '") 'wrap-with-single-quotes) -;; (define-key smartparens-mode-map (kbd "C-c \"") 'wrap-with-double-quotes) -;; (define-key smartparens-mode-map (kbd "C-c _") 'wrap-with-underscores) -;; (define-key smartparens-mode-map (kbd "C-c `") 'wrap-with-back-quotes) -;; -;; (define-key smartparens-mode-map (kbd "C-c s r") 'sp-rewrap-sexp) -;; (define-key smartparens-mode-map (kbd "C-c s u") 'sp-unwrap-sexp) -;; -;; (define-key smartparens-mode-map (kbd "C-M-f") 'sp-forward-sexp) -;; (define-key smartparens-mode-map (kbd "C-M-b") 'sp-backward-sexp) -;; -;; ;; TODO: in manjaro this selects keyboard-layout or something -;; (define-key smartparens-mode-map (kbd "C-M-k") 'sp-kill-sexp) -;; (define-key smartparens-mode-map (kbd "C-M-w") 'sp-copy-sexp) -;; -;; (define-key smartparens-mode-map (kbd "C-M-n") 'sp-next-sexp) -;; (define-key smartparens-mode-map (kbd "C-M-p") 'sp-previous-sexp) -;; -;; ;; TODO: for some reason this does not work -;; (define-key smartparens-mode-map (kbd "C-M-a") 'sp-beginning-of-sexp) -;; (define-key smartparens-mode-map (kbd "C-M-e") 'sp-end-of-sexp) -;; -;; (define-key smartparens-mode-map (kbd "C-M-h") 'mark-defun) -;; -;; (smartparens-global-mode t) - -#+END_SRC - -* Comment-dwim-2 - -Replacement for built-in =comment-dwim=, more comment features. - -https://github.com/remyferre/comment-dwim-2 - -#+BEGIN_SRC emacs-lisp -(use-package comment-dwim-2 - :config - (global-set-key (kbd "M-;") 'comment-dwim-2) -) -#+END_SRC - -* Expand-region - -Expand region increases the selected region by semantic units. -I also enable =pending-delete-mode=, this means when we mark a region and start typing, -the text within the mark is deleted with the new typed text and the mark disappears. - -https://github.com/magnars/expand-region.el - -#+BEGIN_SRC emacs-lisp -(use-package expand-region - :init - (pending-delete-mode t) - :config - (global-set-key (kbd "C-=") 'er/expand-region) -) -#+END_SRC - -* Windooze - -When we use windows as our bootloader, we have to setup some things first: - -#+BEGIN_SRC emacs-lisp -;; Windows performance tweaks -;; -(when (boundp 'w32-pipe-read-delay) - (setq w32-pipe-read-delay 0)) -;; Set the buffer size to 64K on Windows (from the original 4K) -(when (boundp 'w32-pipe-buffer-size) - (setq irony-server-w32-pipe-buffer-size (* 64 1024))) - -;; Set pipe delay to 0 to reduce latency of irony -(setq w32-pipe-read-delay 0) - -;; From "setting up irony mode on Windows" : -;; Make sure the path to clang.dll is in emacs' exec_path and shell PATH. -(setenv "PATH" - (concat - "C:\\msys64\\usr\\bin" ";" - "C:\\msys64\\mingw64\\bin" ";" - (getenv "PATH") - ) -) -(setq exec-path (append '("c:/msys64/usr/bin" "c:/alt/msys64/mingw64/bin") - exec-path)) -#+END_SRC - -To be fair, I didn't test this in a while... - -* Projectile - -Projectile is a project management tool, full details on: -https://github.com/bbatsov/projectile - -#+BEGIN_SRC emacs-lisp -(use-package projectile - :diminish - :custom ((projectile-completion-system 'ivy)) - :bind-keymap - ("C-c p" . projectile-command-map) - :config - (setq projectile-globally-ignored-directories (cons ".ccls-cache" projectile-globally-ignored-directories)) - (setq projectile-indexing-method 'alien) - (setq projectile-enable-caching t) - (projectile-mode) -) -#+END_SRC - -* Mutliple cursors - -https://github.com/magnars/multiple-cursors.el - -#+BEGIN_SRC emacs-lisp -(use-package multiple-cursors - :bind - ("C-x r a" . mc/edit-lines) - ("C-x r e" . mc/edit-ends-of-lines) - ("C->" . mc/mark-next-like-this) - ("C-<" . mc/mark-previous-like-this) - ("C-c C->" . mc/mark-all-like-this) -) -#+END_SRC - -* GDB - -TODO: need to document this - -#+BEGIN_SRC emacs-lisp -(setq gdb-many-windows 1) - -;; Select a register number which is unlikely to get used elsewere -(defconst egdbe-windows-config-register 313465989 - "Internal used") - -(defvar egdbe-windows-config nil) - -(defun set-egdbe-windows-config () - (interactive) - (setq egdbe-windows-config (window-configuration-to-register egdbe-windows-config-register))) - -(defun egdbe-restore-windows-config () - (interactive) - (jump-to-register egdbe-windows-config-register)) - -(defun egdbe-start-gdb (&optional gdb-args) - "" - (interactive) - (set-egdbe-windows-config) - (call-interactively 'gdb)) - -(defun egdbe-quit () - "finish." - (interactive) - (gud-basic-call "quit") - (egdbe-restore-windows-config)) - -(defun egdbe-gud-mode-hook () - "" - (local-unset-key (kbd "q")) - (local-set-key (kbd "q") 'egdbe-quit)) - -(add-hook 'gud-mode-hook 'egdbe-gud-mode-hook) -#+END_SRC - -* Magit - - -#+BEGIN_SRC emacs-lisp -(use-package transient - :ensure t - ) -#+END_SRC - -#+BEGIN_SRC emacs-lisp -(use-package magit - :ensure t - :bind - ("C-c m" . magit-status) - :config - (transient-define-suffix magit-submodule-update-all () - "Update all submodules" - :description "Update All git submodule update --init --recursive" - (interactive) - (magit-with-toplevel - (magit-run-git-async "submodule" "update" "--force"))) - - (transient-append-suffix 'magit-submodule "f" - '("U" magit-submodule-update-all)) - -) -#+END_SRC - -* Programming - -** Yasnippet - -Template system for Emacs. - -https://github.com/joaotavora/yasnippet - -#+BEGIN_SRC emacs-lisp -(use-package yasnippet - :config - (yas-reload-all) - (add-hook 'prog-mode-hook 'yas-minor-mode) -) -#+END_SRC - -** (Relative) Line numbers - -#+BEGIN_SRC emacs-lisp -(use-package linum-relative - :config - (setq linum-relative-current-symbol "") - (add-hook 'prog-mode-hook 'linum-relative-mode)) -#+END_SRC - -** xref - -#+BEGIN_SRC emacs-lisp -(global-set-key (kbd "M-.") 'xref-find-definitions) -(global-set-key (kbd "C-M-.") 'xref-find-references) -(global-set-key (kbd "M-,") 'xref-pop-marker-stack) -#+END_SRC - -** C/C++ mode - -*** Eglot - -Eldoc complaints: - -#+BEGIN_SRC emacs-lisp -(use-package eldoc - :preface - (unload-feature 'eldoc t) - (setq custom-delayed-init-variables '()) - (defvar global-eldoc-mode nil) - :config - (global-eldoc-mode)) - - -(use-package jsonrpc - :preface - (unload-feature 'jsonrpc t) - ) - -#+END_SRC - - -#+BEGIN_SRC emacs-lisp -(use-package eglot - :hook (prog-mode . eglot-ensure) -) -#+END_SRC - -*** Company - -#+BEGIN_SRC emacs-lisp -(use-package company - :init (global-company-mode) - :bind ( - ("" . company-complete) - ) - :hook - ( - (c-mode c++-mode objc-mode) . company-mode - ) -) -#+END_SRC - -** Python mode - -Use =elpy=: -https://github.com/jorgenschaefer/elpy - -It is a full dev env and sometimes feels like a bit too much but overal good experience. - -#+BEGIN_SRC emacs-lisp -(use-package elpy - :init - (elpy-enable) -) -#+END_SRC - -** Zig mode - -#+BEGIN_SRC emacs-lisp -(use-package zig-mode -) -#+END_SRC - -** Rust - -#+BEGIN_SRC emacs-lisp -(use-package rust-mode -) -#+END_SRC - -* Windows - -** Splitting - -After you split a window, your focus remains in the previous one. -Credit goes to https://github.com/daedreth/UncleDavesEmacs - -#+BEGIN_SRC emacs-lisp -(defun split-and-follow-horizontally () - (interactive) - (split-window-below) - (balance-windows) - (other-window 1)) -(global-set-key (kbd "C-x 2") 'split-and-follow-horizontally) - -(defun split-and-follow-vertically () - (interactive) - (split-window-right) - (balance-windows) - (other-window 1)) -(global-set-key (kbd "C-x 3") 'split-and-follow-vertically) -#+END_SRC - -** Switching - -https://github.com/dimitri/switch-window - -Explanation for different config when EXWM is in the README on the github. - -#+BEGIN_SRC emacs-lisp -(use-package switch-window - :config - (setq switch-window-input-style 'minibuffer) - (setq switch-window-increase 6) - (setq switch-window-threshold 2) - (setq switch-window-shortcut-style 'qwerty) - (setq switch-window-qwerty-shortcuts - '("a" "s" "d" "f" "j" "k" "l" "i" "o")) - (setq switch-window-multiple-frames t) - - (if EXWM_ENABLE - (progn - (setq switch-window-input-style 'minibuffer) - ) - ) - - - - - :bind - ("C-x o" . switch-window)) -#+END_SRC - -When using exwm, have a look at this: https://github.com/dimitri/switch-window/pull/62 - -** Multi-frame rebindings (OBSOLETE with switch-window) - -Sometimes I have multiple emacs-frames open. -In the past, I preferred that the normal =C-x o= can deal with this but this is used by switch-window now. - -#+BEGIN_SRC emacs-lisp -;; ;; Use C-x o to switch to other frame when using multi-monitor -;; (global-set-key (kbd "C-x o") 'next-multiframe-window) -#+END_SRC - -Now that =next-multiframe-window= is bound to =C-x o=, -Bind =C-x p= to =previous-multiframe-window=. - -#+BEGIN_SRC emacs-lisp -;; (global-set-key (kbd "\C-x p") 'previous-multiframe-window) -#+END_SRC - -* Avy - -https://github.com/abo-abo/avy - -#+BEGIN_SRC emacs-lisp -(use-package avy - :bind - ("M-s" . avy-goto-char)) -#+END_SRC - -* Convenience stuff - -** Visiting the configuration - -#+BEGIN_SRC emacs-lisp -(defun config-visit () - (interactive) - (find-file "~/.emacs.d/config.org")) -(global-set-key (kbd "C-c E") 'config-visit) -#+END_SRC - -** Reload the configuration - -#+BEGIN_SRC emacs-lisp -(defun config-reload () - "Reloads ~/.emacs.d/config.org at runtime" - (interactive) - (org-babel-load-file (expand-file-name "~/.emacs.d/config.org"))) -(global-set-key (kbd "C-c R") 'config-reload) -#+END_SRC - -** Subword - -#+BEGIN_SRC emacs-lisp -(global-subword-mode 1) -#+END_SRC - -** Bell - -The audible bell is annoying AF. - -#+BEGIN_SRC emacs-lisp -(setq visible-bell 1) -#+END_SRC - -* Server - -Emacs as a server. -Emacsclient will then use this emacs as its server. - -Use server-running-p to test if it is already running. - -#+BEGIN_SRC emacs-lisp -(require 'server) -(unless (server-running-p) - (server-start)) -#+END_SRC - -* Beacon - -https://github.com/Malabarba/beacon - -#+BEGIN_SRC emacs-lisp -(use-package beacon - :diminish - :config - (beacon-mode 1) - (setq beacon-color "#FFFFCC") ;; yelowish -) -#+END_SRC - -* Org - -** Enabling table of contents - -Stolen from distrotube: -https://gitlab.com/dwt1/configuring-emacs/-/blob/main/01-elpaca-evil-general/config.org#enabling-table-of-contents - -#+BEGIN_SRC emacs-lisp -(use-package toc-org - :commands toc-org-enable - :init (add-hook 'org-mode-hook 'toc-org-enable)) -#+END_SRC - -** Org bullets - -https://github.com/sabof/org-bullets - -#+BEGIN_SRC emacs-lisp -(use-package org-bullets - :config - (add-hook 'org-mode-hook (lambda () (org-bullets-mode)))) -#+END_SRC - -** Some basic config - -*** Super/Sub-scripts - -Use ={}= for subscripting: - -https://orgmode.org/manual/Subscripts-and-superscripts.html - -#+BEGIN_SRC emacs-lisp -(setq org-use-sub-superscripts '{}) -#+END_SRC - -*** Indentation - -Preserve indentation in SRC blocks - -#+BEGIN_SRC emacs-lisp -(setq org-src-preserve-indentation t) -#+END_SRC - - -*** Runnable languages - -#+BEGIN_SRC emacs-lisp -(org-babel-do-load-languages - 'org-babel-load-languages '( - (ditaa . t)) - ) -#+END_SRC - -**** Dita - -Tell org where to look for ditaa - -#+BEGIN_SRC emacs-lisp -(setq org-ditaa-jar-path "/usr/share/java/ditaa/ditaa-0_10.jar") -#+END_SRC - -** Note config - -#+BEGIN_SRC emacs-lisp -;; when ending TODO (C-C C-t) end with a note + timestamp -(setq org-log-done 'note) -;; Add extra states for keywords -(setq org-todo-keywords - '((sequence "TODO" "IN-PROGRESS" "WAITING" "DONE"))) -#+END_SRC - -* Shell-pop - -https://github.com/kyagi/shell-pop-el - -#+BEGIN_SRC emacs-lisp -(use-package shell-pop - :bind (("C-c t" . shell-pop)) - :config - (setq shell-pop-shell-type (quote ("eshell" "*eshell*" (lambda nil (eshell shell-pop-term-shell))))) - (setq shell-pop-term-shell "/bin/zsh") - ;; need to do this manually or not picked up by `shell-pop' - (shell-pop--set-shell-type 'shell-pop-shell-type shell-pop-shell-type)) -#+END_SRC - -* Old stuff, maybe usefull for lookup later - -** Diff mode stuff - -#+BEGIN_SRC emacs-lisp -;; show whitespace in diff-mode -;; (add-hook 'diff-mode-hook (lambda () -;; (setq-local whitespace-style -;; '(face -;; tabs -;; tab-mark -;; spaces -;; space-mark -;; trailing -;; indentation::space -;; indentation::tab -;; newline -;; newline-mark)) -;; (whitespace-mode 1))) -#+END_SRC - -** Speedbar - -#+BEGIN_SRC emacs-lisp -;; Package: sr-speedbar -;;(require 'sr-speedbar) -;; (add-hook 'emacs-startup-hook (lambda () ; Open sr speedbar on startup -;; (sr-speedbar-open) -;; )) -;; (setq speedbar-show-unknown-files t) ; Enable speedbar to show all files -;; (setq speedbar-use-images nil) ; use text for buttons -;; (setq sr-speedbar-right-side nil) ; put on left side -;; (setq sr-speedbar-width 40) -;; -;; (provide 'setup-speedbar) -#+END_SRC - -* EXWM - -Arandr config is still too static, should find a way to simplify this. - -#+BEGIN_SRC emacs-lisp -(if EXWM_ENABLE - (progn - (message "Loading EXWM...") - (use-package exwm - :config - (require 'exwm-systemtray) - (exwm-systemtray-enable) - - (require 'exwm-randr) - (setq exwm-workspace-number 1) - - ;; (setq exwm-randr-workspace-output-plist - ;; '(0 "DP1" 1 "DP2")) - ;; (add-hook 'exwm-randr-screen-change-hook - ;; (lambda () - ;; (start-process-shell-command - ;; "xrandr" nil "xrandr --output DP2 --primary --mode 1920x1080 --pos 1920x0 --rotate left --output DP1 --mode 1920x1080 --pos 0x0 --rotate normal --auto"))) - ;; (exwm-randr-enable) - - (require 'exwm-config) - - ;; Make class name the buffer name - (add-hook 'exwm-update-class-hook - (lambda () - (exwm-workspace-rename-buffer exwm-class-name))) - ;; Global keybindings. - (setq exwm-input-global-keys - `( - ;; 's-r': Reset (to line-mode). - ([?\s-r] . exwm-reset) - ;; 's-w': Switch workspace. - ([?\s-w] . exwm-workspace-switch) - ;; 's-return': Launch application. - ([s-return] . (lambda (command) - (interactive (list (read-shell-command "$ "))) - (start-process-shell-command command nil command))) - ;; 's-N': Switch to certain workspace. - ,@(mapcar (lambda (i) - `(,(kbd (format "s-%d" i)) . - (lambda () - (interactive) - (exwm-workspace-switch-create ,i)))) - (number-sequence 0 9)))) - ;; Line-editing shortcuts - (setq exwm-input-simulation-keys - '(([?\C-b] . [left]) - ([?\C-f] . [right]) - ([?\C-p] . [up]) - ([?\C-n] . [down]) - ([?\C-a] . [home]) - ([?\C-e] . [end]) - ([?\M-v] . [prior]) - ([?\C-v] . [next]) - ([?\C-d] . [delete]) - ([?\C-s] . [C-f]) - ([?\C-k] . [S-end delete]))) - - (global-set-key (kbd "C-x C-b") 'exwm-workspace-switch-to-buffer) - - ;; Enable EXWM - (exwm-enable) - ) - ) -) -#+END_SRC - -* Transparency - -Taken from EmacsWiki: -https://www.emacswiki.org/emacs/TransparentEmacs - -#+BEGIN_SRC emacs-lisp - (defun toggle-transparency () - (interactive) - (let ((alpha (frame-parameter nil 'alpha))) - (set-frame-parameter - nil 'alpha - (if (eql (cond ((numberp alpha) alpha) - ((numberp (cdr alpha)) (cdr alpha)) - ;; Also handle undocumented ( ) form. - ((numberp (cadr alpha)) (cadr alpha))) - 100) - '(85 . 50) '(100 . 100))))) - (global-set-key (kbd "C-x t") 'toggle-transparency) -#+END_SRC - -* Debugging - -Just some ways to debug lags, etc. - -#+BEGIN_SRC -M-x profiler-start - -...do stuff... - -M-x profiler-report -#+END_SRC - -Some usefull links: -- https://emacs.stackexchange.com/questions/5359/how-can-i-troubleshoot-a-very-slow-emacs - -* TODO - -stuff i need to look into: -- ibuffer -- fix dired-mode (f.e. new-buffer for every folder, ...) -- helm-exwm -- symon -- spaceline -- async -- helm-hide-minibuffer -- doxymacs diff --git a/custom/setup-autocompletion.el b/custom/setup-autocompletion.el new file mode 100644 index 0000000..e784b93 --- /dev/null +++ b/custom/setup-autocompletion.el @@ -0,0 +1,22 @@ +(add-hook 'after-init-hook 'global-company-mode) + +;; Add irony as company-backend +(eval-after-load 'company + '(add-to-list 'company-backends 'company-irony)) + +;; Add irony as flycheck hook +(eval-after-load 'flycheck + '(add-hook 'flycheck-mode-hook 'flycheck-irony-setup)) + +(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options) +(add-hook 'irony-mode-hook 'irony-eldoc) + +;; Add irony-, flycheck-, company-mode to c-mode +(add-hook 'c-mode-hook 'irony-mode) +(add-hook 'c-mode-hook 'flycheck-mode) +(add-hook 'c-mode-hook 'company-mode) + +;; Set tab to autocomplete or indent depending on context +(global-set-key (kbd "") 'company-indent-or-complete-common) + +(provide 'setup-autocompletion) diff --git a/custom/setup-coding.el b/custom/setup-coding.el new file mode 100644 index 0000000..def1407 --- /dev/null +++ b/custom/setup-coding.el @@ -0,0 +1,48 @@ +;; make angry face to get my attention +(setq prog-modes '(c++-mode python-mode erlang-mode java-mode c-mode emacs-lisp-mode scheme-mode prog-mode)) +(make-face 'font-lock-angry-face) +(modify-face 'font-lock-angry-face "Red" "Yellow" nil t nil t nil nil) + +;; Add keywords to recognize to angry face +(mapc (lambda (mode) + (font-lock-add-keywords + mode + '(("\\<\\(FIXME\\)" 1 'font-lock-angry-face t))) + ) + prog-modes) +(mapc (lambda (mode) + (font-lock-add-keywords + mode + '(("\\<\\(TODO\\)" 1 'font-lock-angry-face t))) + ) + prog-modes) + +;; default coding style +(setq c-default-style "linux") + +;; sane indentation offset +(setq c-basic-offset 4) + +;; Tab-space strategy +;; we use spaces, deal with it +(setq-default indent-tabs-mode nil) + +;; Enable subword mode for handling CamelCase format +(global-subword-mode t) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Python ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(require 'py-autopep8) +(elpy-enable) + +(setq elpy-modules (delq 'elpy-module-flycheck elpy-modules)) +(add-hook 'elpy-mode-hook 'flycheck-mode) +(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Magit (git) ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(global-set-key (kbd "C-c m") 'magit-status) + +(provide 'setup-coding) diff --git a/custom/setup-cursors.el b/custom/setup-cursors.el new file mode 100644 index 0000000..d5a1aca --- /dev/null +++ b/custom/setup-cursors.el @@ -0,0 +1,10 @@ +(require 'multiple-cursors) + +(global-set-key (kbd "C-x r a") 'mc/edit-lines) +(global-set-key (kbd "C-x r e") 'mc/edit-ends-of-lines) + +(global-set-key (kbd "C->") 'mc/mark-next-like-this) +(global-set-key (kbd "C-<") 'mc/mark-previous-like-this) +(global-set-key (kbd "C-c C->") 'mc/mark-all-like-this) + +(provide 'setup-cursors) diff --git a/custom/setup-dashboard.el b/custom/setup-dashboard.el new file mode 100644 index 0000000..6d1490a --- /dev/null +++ b/custom/setup-dashboard.el @@ -0,0 +1,17 @@ +(require 'dashboard) + +(dashboard-setup-startup-hook) + +;; Set the startup message +(setq dashboard-banner-logo-title "") + +;; Set the banner +(setq dashboard-startup-banner 'logo) +(setq dashboard-items '((recents . 10) + (bookmarks . 5) + )) + +;; Enable recent files +(recentf-mode 1) + +(provide 'setup-dashboard) diff --git a/custom/setup-editing.el b/custom/setup-editing.el new file mode 100644 index 0000000..fbddaab --- /dev/null +++ b/custom/setup-editing.el @@ -0,0 +1,134 @@ +(setq global-mark-ring-max 5000 ; increase mark ring to contains 5000 entries + mark-ring-max 5000 ; increase kill ring to contains 5000 entries + mode-require-final-newline t ; add a newline to end of file + ) + +(setq kill-ring-max 5000 ; increase kill-ring capacity + kill-whole-line t ; if NIL, kill whole line and move the next line up + ) + +;; show column numbers +(setq column-number-mode 1) + +;; Remove scroll-bar, tool-bar and menu-bar +(scroll-bar-mode -1) +(tool-bar-mode -1) +(menu-bar-mode -1) + +;; set appearance of a tab that is represented by 4 spaces +(setq-default tab-width 4) + +;; automatically indent when press RET +(global-set-key (kbd "RET") 'newline-and-indent) + +;; Map query-replace-regexp to an easier key +(global-set-key (kbd "C-x r r") 'query-replace-regexp) + +;; Map query-replace-regexp to an easier key +(global-set-key (kbd "M-p") 'fill-paragraph) + +;; Delete trailing whitespace when saving file +(add-hook 'before-save-hook 'delete-trailing-whitespace) + +;; show whitespace in diff-mode +(add-hook 'diff-mode-hook (lambda () + (setq-local whitespace-style + '(face + tabs + tab-mark + spaces + space-mark + trailing + indentation::space + indentation::tab + newline + newline-mark)) + (whitespace-mode 1))) + +;; Package: undo-tree -- saner, imo, undo with C-/ +(require 'undo-tree) +(global-undo-tree-mode) + +;; Package: volatile-highlights --- show changes by "undo/yanks/..." +(require 'volatile-highlights) +(volatile-highlights-mode t) + +;;; Package: iedit --- Replace occurences of symbol and highlight them +(require 'iedit) + +;; Package: smartparens --- smart way to handle (), {}, ... +(require 'smartparens-config) +(setq sp-base-key-bindings 'paredit) +(setq sp-autoskip-closing-pair 'always) +(setq sp-hybrid-kill-entire-symbol nil) +(sp-use-paredit-bindings) + +(show-smartparens-global-mode +1) +(smartparens-global-mode 1) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; keybinding management smartparens ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; cl-package contains the loop macro +(require 'cl) + +(defmacro def-pairs (pairs) + `(progn + ,@(loop for (key . val) in pairs + collect + `(defun ,(read (concat + "wrap-with-" + (prin1-to-string key) + "s")) + (&optional arg) + (interactive "p") + (sp-wrap-with-pair ,val))))) + +(def-pairs ((paren . "(") + (bracket . "[") + (brace . "{") + (single-quote . "'") + (double-quote . "\"") + (underscore . "_") + (back-quote . "`"))) + +(define-key smartparens-mode-map (kbd "C-c (") 'wrap-with-parens) +(define-key smartparens-mode-map (kbd "C-c [") 'wrap-with-brackets) +(define-key smartparens-mode-map (kbd "C-c {") 'wrap-with-braces) +(define-key smartparens-mode-map (kbd "C-c '") 'wrap-with-single-quotes) +(define-key smartparens-mode-map (kbd "C-c \"") 'wrap-with-double-quotes) +(define-key smartparens-mode-map (kbd "C-c _") 'wrap-with-underscores) +(define-key smartparens-mode-map (kbd "C-c `") 'wrap-with-back-quotes) + +(define-key smartparens-mode-map (kbd "C-c s r") 'sp-rewrap-sexp) +(define-key smartparens-mode-map (kbd "C-c s u") 'sp-unwrap-sexp) + +(define-key smartparens-mode-map (kbd "C-M-f") 'sp-forward-sexp) +(define-key smartparens-mode-map (kbd "C-M-b") 'sp-backward-sexp) + +;; TODO: in manjaro this selects keyboard-layout or something +;;(define-key smartparens-mode-map (kbd "C-M-k") 'sp-kill-sexp) +(define-key smartparens-mode-map (kbd "C-M-w") 'sp-copy-sexp) + +(define-key smartparens-mode-map (kbd "C-M-n") 'sp-next-sexp) +(define-key smartparens-mode-map (kbd "C-M-p") 'sp-previous-sexp) + +;; TODO: for some reason this does not work +(define-key smartparens-mode-map (kbd "C-M-a") 'sp-beginning-of-sexp) +(define-key smartparens-mode-map (kbd "C-M-e") 'sp-end-of-sexp) + +(define-key smartparens-mode-map (kbd "C-M-h") 'mark-defun) + +(smartparens-global-mode t) + + +;; Package: comment-dwim-2 --- replacement for built-in comment-dwim, more comment features +(require 'comment-dwim-2) +(global-set-key (kbd "M-;") 'comment-dwim-2) + + +;; Package: yasnippet --- code template system +(require 'yasnippet) +(yas-global-mode 1) + +(provide 'setup-editing) diff --git a/custom/setup-expand-region.el b/custom/setup-expand-region.el new file mode 100644 index 0000000..1734ac0 --- /dev/null +++ b/custom/setup-expand-region.el @@ -0,0 +1,7 @@ +(require 'expand-region) + +(pending-delete-mode t) + +(global-set-key (kbd "C-=") 'er/expand-region) + +(provide 'setup-expand-region) diff --git a/custom/setup-gdb.el b/custom/setup-gdb.el new file mode 100644 index 0000000..4d40663 --- /dev/null +++ b/custom/setup-gdb.el @@ -0,0 +1,36 @@ +(setq gdb-many-windows 1) + +;; Select a register number which is unlikely to get used elsewere +(defconst egdbe-windows-config-register 313465989 + "Internal used") + +(defvar egdbe-windows-config nil) + +(defun set-egdbe-windows-config () + (interactive) + (setq egdbe-windows-config (window-configuration-to-register egdbe-windows-config-register))) + +(defun egdbe-restore-windows-config () + (interactive) + (jump-to-register egdbe-windows-config-register)) + +(defun egdbe-start-gdb (&optional gdb-args) + "" + (interactive) + (set-egdbe-windows-config) + (call-interactively 'gdb)) + +(defun egdbe-quit () + "finish." + (interactive) + (gud-basic-call "quit") + (egdbe-restore-windows-config)) + +(defun egdbe-gud-mode-hook () + "" + (local-unset-key (kbd "q")) + (local-set-key (kbd "q") 'egdbe-quit)) + +(add-hook 'gud-mode-hook 'egdbe-gud-mode-hook) + +(provide 'setup-gdb) diff --git a/custom/setup-general.el b/custom/setup-general.el new file mode 100644 index 0000000..221252c --- /dev/null +++ b/custom/setup-general.el @@ -0,0 +1,62 @@ +(global-set-key [f9] 'start-kbd-macro) +(global-set-key [f10] 'end-kbd-macro) +(global-set-key [f11] 'call-last-kbd-macro) + +;; Package zygospore --- revert C-x 1 by pressing C-x 1 again +;; TODO: Doesn't work with sr-speedbar +(global-set-key (kbd "C-x 1") 'zygospore-toggle-delete-other-windows) + +;; Set 'M-g' to 'goto-line', it's faster and what we usually want +(global-set-key (kbd "M-g") 'goto-line) + +;; Set 'C-x r i' to 'string-insert-rectangle' +;; Easier than using 'M-x' and searching for it. +(global-set-key (kbd "C-x r i") 'string-insert-rectangle) + +;; set garbage collection to higher value +;; see http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/ +(setq gc-cons-threshold 100000000) + +;; important yes-or-no questions can be answered with y-or-n +(defalias 'yes-or-no-p 'y-or-n-p) + +;; maximize Emacs at startup +(add-to-list 'default-frame-alist '(fullscreen . maximized)) + +;; Move one window back command +(global-set-key (kbd "\C-x p") 'previous-multiframe-window) + +;; Use C-x o to switch to other frame when using multi-monitor +(global-set-key (kbd "C-x o") 'next-multiframe-window) + +;; set my theme +(load-theme 'wombat) + +;; highlight line (hl-line) +(global-hl-line-mode 1) +(set-face-background hl-line-face "dark slate grey") + +;; smart mode line +(setq sml/no-confirm-load-theme t) +(setq sml/theme 'powerline) +(sml/setup) + +;; enable disabled commands +(put 'narrow-to-page 'disabled nil) +(put 'narrow-to-region 'disabled nil) + +;; quick function to kill all other buffers +(defun kill-other-buffers () + "Kill all other buffers." + (interactive) + (mapc 'kill-buffer + (delq (current-buffer) + (remove-if-not 'buffer-file-name (buffer-list))))) + +;; screw with vi(m)-users +(defconst wq "This is not vi! Use C-x C-c instead.") +(defconst w "This is not vi! Use C-x C-s instead.") +(defconst q! "This is EMACS not vi! Use C-x C-c instead.") +(defconst wq! "This is EMACS not vi! Use C-x C-c instead.") + +(provide 'setup-general) diff --git a/custom/setup-helm-gtags.el b/custom/setup-helm-gtags.el new file mode 100644 index 0000000..09b7e09 --- /dev/null +++ b/custom/setup-helm-gtags.el @@ -0,0 +1,19 @@ +(require 'helm-gtags) + +;; Enable helm-gtags-mode in languages that GNU Global supports +(add-hook 'c-mode-hook 'helm-gtags-mode) +(add-hook 'c++-mode-hook 'helm-gtags-mode) +(add-hook 'python-mode-hook 'helm-gtags-mode) +(add-hook 'java-mode-hook 'helm-gtags-mode) +(add-hook 'asm-mode-hook 'helm-gtags-mode) + +;; customize behaviour +(custom-set-variables + '(helm-gtags-auto-update t)) + +(global-set-key (kbd "M-.") 'helm-gtags-find-tag-from-here) +(global-set-key (kbd "M-,") 'helm-gtags-pop-stack) +(global-set-key (kbd "C-c C-f") 'helm-gtags-find-files) +(global-set-key (kbd "C-c g f") 'helm-gtags-parse-file) + +(provide 'setup-helm-gtags) diff --git a/custom/setup-helm.el b/custom/setup-helm.el new file mode 100644 index 0000000..1ed7612 --- /dev/null +++ b/custom/setup-helm.el @@ -0,0 +1,50 @@ +(require 'helm) +(require 'helm-config) + +;; replace vanilla commands with helm commands +(global-set-key (kbd "M-x") 'helm-M-x) +(global-set-key (kbd "M-y") 'helm-show-kill-ring) +(global-set-key (kbd "C-x b") 'helm-mini) +;; In vanilla, this is mapped to show-buffers, but I don't use that so map it to helm-mini as well +(global-set-key (kbd "C-x C-b") 'helm-mini) +(global-set-key (kbd "C-x C-f") 'helm-find-files) + +;; rebind tab to do persistent action +;; we use helm-execute-persistent-action more than helm-select-action (default for ) +(define-key helm-map (kbd "") 'helm-execute-persistent-action) +;; make TAB work in terminal +(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action) +;; remap helm-select-action: lists actions +(define-key helm-map (kbd "C-z") 'helm-select-action) + +;; remap calculator +(global-set-key (kbd "C-c C-c") 'helm-calcul-expression) + +;; TODO: experiment with mark ring (breadcrumbs something?) +;; TODO: experiment with helm-regexp (build and test regexes) +;; TODO: remember helm-top (helm interface for top program) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; PACKAGE: helm-swoop ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Locate the helm-swoop folder to your path +(require 'helm-swoop) + +;; replace vanilla I-search with helm-swoop +(global-set-key (kbd "C-s") 'helm-swoop) + +;; From helm-swoop to helm-multi-swoop-all +;;(define-key helm-swoop-map (kbd "M-s") 'helm-multi-swoop-all-from-helm-swoop) +(define-key helm-swoop-map (kbd "C-s") 'helm-multi-swoop-all-from-helm-swoop) +;; TODO: find out how to switch from multi-swoop to swoop back again + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Next 2 lines make sure when using helm-swoop only the current window/buffer is affected ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; If this value is t, split window inside the current window +(setq helm-swoop-split-with-multiple-windows t) + +;; Split direcion. 'split-window-vertically or 'split-window-horizontally +(setq helm-swoop-split-direction 'split-window-vertically) + +(provide 'setup-helm) diff --git a/custom/setup-org.el b/custom/setup-org.el new file mode 100644 index 0000000..1a448e6 --- /dev/null +++ b/custom/setup-org.el @@ -0,0 +1,28 @@ +(require 'org) + +(define-key global-map "\C-cl" 'org-store-link) +(define-key global-map "\C-ca" 'org-agenda) + +;; when ending TODO (C-C C-t) end with a note + timestamp +(setq org-log-done 'note) +;; Specify root dir to search for agenda files, TODOs, ... +(setq org-agenda-files '("~/org")) +;; Add extra states for keywords +(setq org-todo-keywords + '((sequence "TODO" "IN-PROGRESS" "WAITING" "DONE"))) + +(setq org-export-with-sub-superscripts nil) + +;; Preserve indentation in SRC blocks +(setq org-src-preserve-indentation t) + +;; Specify which languages are allowed to run inside org-mode +(org-babel-do-load-languages + 'org-babel-load-languages '( + (ditaa . t)) + ) + +;; Tell org where to look for ditaa +(setq org-ditaa-jar-path "/usr/share/java/ditaa/ditaa-0_10.jar") + +(provide 'setup-org) diff --git a/custom/setup-speedbar.el b/custom/setup-speedbar.el new file mode 100644 index 0000000..e38ac8d --- /dev/null +++ b/custom/setup-speedbar.el @@ -0,0 +1,11 @@ +;; Package: sr-speedbar +(require 'sr-speedbar) +;; (add-hook 'emacs-startup-hook (lambda () ; Open sr speedbar on startup +;; (sr-speedbar-open) +;; )) +(setq speedbar-show-unknown-files t) ; Enable speedbar to show all files +(setq speedbar-use-images nil) ; use text for buttons +(setq sr-speedbar-right-side nil) ; put on left side +(setq sr-speedbar-width 40) + +(provide 'setup-speedbar) diff --git a/custom/setup-windows.el b/custom/setup-windows.el new file mode 100644 index 0000000..695b1de --- /dev/null +++ b/custom/setup-windows.el @@ -0,0 +1,25 @@ +;; Windows performance tweaks +;; +(when (boundp 'w32-pipe-read-delay) + (setq w32-pipe-read-delay 0)) +;; Set the buffer size to 64K on Windows (from the original 4K) +(when (boundp 'w32-pipe-buffer-size) + (setq irony-server-w32-pipe-buffer-size (* 64 1024))) + +;; Set pipe delay to 0 to reduce latency of irony +(setq w32-pipe-read-delay 0) + +;; From "setting up irony mode on Windows" : +;; Make sure the path to clang.dll is in emacs' exec_path and shell PATH. +(setenv "PATH" + (concat + "C:\\msys64\\usr\\bin" ";" + "C:\\msys64\\mingw64\\bin" ";" + (getenv "PATH") + ) +) +(setq exec-path (append '("c:/msys64/usr/bin" "c:/alt/msys64/mingw64/bin") + exec-path)) + + +(provide 'setup-windows) diff --git a/early-init.el b/early-init.el deleted file mode 100644 index 5d83494..0000000 --- a/early-init.el +++ /dev/null @@ -1,18 +0,0 @@ -;;; early-init.el --- Early Init -*- lexical-binding: t; -*- - -;;; Commentary: -;; Early init configuration for Emacs Solo -;; - -;;; Code: - - -;; Only care about errors in *Messages* buffer -(setq warning-minimum-level :error) - -;; We control when packages are enabled -(setq package-enable-at-startup nil) - -(provide 'early-init) - -;;; early-init.el ends here diff --git a/init.el b/init.el index 3f13d33..876843e 100644 --- a/init.el +++ b/init.el @@ -1,28 +1,152 @@ -;;; init.el --- Init -*- lexical-binding: t; -*- +;; add the custom dir to our load path +(add-to-list 'load-path "~/.emacs.d/custom") -;;; Commentary: -;;; Load init files +;; add melpa-stable to package-archives +;; IMPORTANT: add (require 'package), else package-archives is not declared (void-variable) +(require 'package) +(add-to-list 'package-archives + '("melpa-stable" . "https://stable.melpa.org/packages/") t) +(add-to-list 'package-archives + '("melpa" . "http://melpa.milkbox.net/packages/") t) -;;; Code: +;; MUST be called after package-archives is updated +;; Else the automated installation logic is not able to install missing packages +(package-initialize) -;;; Increase garbage collection threshold during init but leave it to the default value after -;;; There are a LOT of articles/sites/... discussing this: -;;; https://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/ -;;; https://jonnay.github.io/emagicians-starter-kit/Emagician-Base.html -;;; ... -(let ((gc-cons-threshold most-positive-fixnum)) - (setq custom-file (expand-file-name "custom.el" user-emacs-directory)) - ;; This is the actual config file. It is omitted if it doesn't exist so emacs won't refuse to launch. - (defvar my-config-file (expand-file-name "config.org" user-emacs-directory)) +;; my required packages +(defconst my-packages + '( + undo-tree + volatile-highlights + smartparens + iedit + zygospore + comment-dwim-2 + yasnippet + yasnippet-snippets + sr-speedbar + company + irony + irony-eldoc + company-irony + flycheck-irony + elpy + py-autopep8 + magit + org + smart-mode-line + smart-mode-line-powerline-theme + helm + helm-gtags + helm-swoop + helm-company + dashboard + multiple-cursors + expand-region + )) - (when (file-readable-p my-config-file) - (org-babel-load-file (expand-file-name my-config-file))) +;; function to install new packages +(defun install-packages () + "Install all required packages." + (interactive) + (unless package-archive-contents + (package-refresh-contents)) + (dolist (package my-packages) + (unless (package-installed-p package) + (package-install package)))) - (load custom-file :no-error-if-file-is-missing) +;; install packages if not yet installed +(install-packages) + +;; setup general +(require 'setup-general) + +;; setup general editing settings +(require 'setup-editing) + +;; setup org +(require 'setup-org) + +;; setup coding +(require 'setup-coding) + +;; setup helm +(require 'setup-helm) +(require 'setup-helm-gtags) + +;; setup speedbar +(require 'setup-speedbar) + +;; setup autocompletion +(require 'setup-autocompletion) + +;; setup Windows if our bootloader is Windows +(if (eq system-type 'windows-nt) + (require 'setup-windows) ) -(provide 'init) +;; setup dashboard +(require 'setup-dashboard) +;; setup gdb +(require 'setup-gdb) + +;; setup multiple cursors +(require 'setup-cursors) + +;; setup expand-region +(require 'setup-expand-region) + +;; start emacs server +(server-start) + +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(ansi-color-faces-vector + [default default default italic underline success warning error]) + '(ansi-color-names-vector + ["#757575" "#CD5542" "#4A8F30" "#7D7C21" "#4170B3" "#9B55C3" "#68A5E9" "gray43"]) + '(custom-safe-themes + (quote + ("84d2f9eeb3f82d619ca4bfffe5f157282f4779732f48a5ac1484d94d5ff5b279" "c74e83f8aa4c78a121b52146eadb792c9facc5b1f02c917e3dbb454fca931223" "3c83b3676d796422704082049fc38b6966bcad960f896669dfc21a7a37a748fa" "938d8c186c4cb9ec4a8d8bc159285e0d0f07bad46edf20aa469a89d0d2a586ea" "6de7c03d614033c0403657409313d5f01202361e35490a3404e33e46663c2596" "ed317c0a3387be628a48c4bbdb316b4fa645a414838149069210b66dd521733f" "1db337246ebc9c083be0d728f8d20913a0f46edc0a00277746ba411c149d7fe5" default))) + '(fci-rule-color "#2e2e2e") + '(global-company-mode t) + '(package-selected-packages + (quote + (ample-zen-theme ample-theme magit irony-eldoc elpy irony helm-swoop helm))) + '(vc-annotate-background "#3b3b3b") + '(vc-annotate-color-map + (quote + ((20 . "#dd5542") + (40 . "#CC5542") + (60 . "#fb8512") + (80 . "#baba36") + (100 . "#bdbc61") + (120 . "#7d7c61") + (140 . "#6abd50") + (160 . "#6aaf50") + (180 . "#6aa350") + (200 . "#6a9550") + (220 . "#6a8550") + (240 . "#6a7550") + (260 . "#9b55c3") + (280 . "#6CA0A3") + (300 . "#528fd1") + (320 . "#5180b3") + (340 . "#6380b3") + (360 . "#DC8CC3")))) + '(vc-annotate-very-old-color "#DC8CC3")) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) + +(provide 'init) ;;; init.el ends here diff --git a/snippets/c-mode/define b/snippets/c-mode/define deleted file mode 100644 index eb89c4a..0000000 --- a/snippets/c-mode/define +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: Make a define -# key: def -# -- - -#define ${1:mydefine$(upcase yas-text)} $2 diff --git a/snippets/c-mode/fori b/snippets/c-mode/fori index e2e0ac6..acb5879 100644 --- a/snippets/c-mode/fori +++ b/snippets/c-mode/fori @@ -2,7 +2,8 @@ # name: for with loop variable # key: fori # -- +int i = 0; -for (${1:size_t i = 0}; ${2:i < N}; ${3:++i}) { +for (${1:i = 0}; ${2:i < N}; ${3:++i}) { $0 -} \ No newline at end of file +} diff --git a/snippets/c-mode/header b/snippets/c-mode/header deleted file mode 100644 index a7b5339..0000000 --- a/snippets/c-mode/header +++ /dev/null @@ -1,10 +0,0 @@ -#name : #ifndef XXX; #define XXX; #endif -# key: header -# -- - -#ifndef ${1:_`(upcase (file-name-nondirectory (file-name-sans-extension (or (buffer-file-name) ""))))`_H_} -#define $1 - -$0 - -#endif /* $1 */ \ No newline at end of file diff --git a/snippets/c-mode/kaboom b/snippets/c-mode/kaboom deleted file mode 100644 index d4220a2..0000000 --- a/snippets/c-mode/kaboom +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: kaboom -# key: kb -# -- - -char (*__kaboom)[sizeof($1)] = 1; diff --git a/snippets/c-mode/oncekl b/snippets/c-mode/oncekl new file mode 100644 index 0000000..d0f8afc --- /dev/null +++ b/snippets/c-mode/oncekl @@ -0,0 +1,9 @@ +#name : #ifndef XXX; #define XXX; #endif +# key: oncekl +# -- +#ifndef ${1:`(upcase (file-name-nondirectory (file-name-sans-extension (or (buffer-file-name) ""))))`_H_} +#define $1 + +$0 + +#endif /* $1 */ \ No newline at end of file diff --git a/snippets/org-mode/emacs-lisp-source-block b/snippets/org-mode/emacs-lisp-source-block deleted file mode 100644 index 25f00aa..0000000 --- a/snippets/org-mode/emacs-lisp-source-block +++ /dev/null @@ -1,8 +0,0 @@ -# -*- mode: snippet -*- -# name: Start emacs source block -# key: se -# -- - -#+BEGIN_SRC emacs-lisp -${1} -#+END_SRC diff --git a/snippets/org-mode/filetags b/snippets/org-mode/filetags deleted file mode 100644 index b3f283d..0000000 --- a/snippets/org-mode/filetags +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: Filetags -# key: ft -# -- - -#+FILETAGS: :$1: diff --git a/snippets/org-mode/source_block_emacs b/snippets/org-mode/source_block_emacs deleted file mode 100644 index 215d78e..0000000 --- a/snippets/org-mode/source_block_emacs +++ /dev/null @@ -1,8 +0,0 @@ -# -*- mode: snippet -*- -# name: Org source code block -# key: s -# -- - -#+BEGIN_SRC -${1} -#+END_SRC diff --git a/snippets/text-mode/git-commit-message-before-after b/snippets/text-mode/git-commit-message-before-after deleted file mode 100644 index 983e180..0000000 --- a/snippets/text-mode/git-commit-message-before-after +++ /dev/null @@ -1,10 +0,0 @@ -# -*- mode: snippet -*- -# name: Git commit message template -# key: bac -# -- - -Before this commit, -${1} - -After this commit, -${2}