diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..712c684 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +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/.gitmodules b/.gitmodules deleted file mode 100644 index f8db735..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "extra/sunrise-commander"] - path = extra/sunrise-commander - url = https://github.com/escherdragon/sunrise-commander diff --git a/cheat-sheet.txt b/cheat-sheet.txt deleted file mode 100644 index ddd8cdd..0000000 --- a/cheat-sheet.txt +++ /dev/null @@ -1,8 +0,0 @@ -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 index fb7ef3d..fc60742 100644 --- a/config.org +++ b/config.org @@ -2,80 +2,282 @@ #+TITLE: My Emacs #+CREATOR: Laurens Miers #+LANGUAGE: en -[[./img/dash_logo.png]] -* 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 : - - - the GNU =global= package (for gtags) - - ccls language server (for LSP functionality) - - =llvm-libs= (for cmake, somehow not a dependency on Manjaro when installing cmake) - - Use python-pip to install requirements for elpy: - =pip install jedi flake8 importmagic autopep8 yapf= - - =ditaa= (for ascii to image generation in org-mode) - -* 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. +* General config #+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)) + (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 -** 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. +** Package repos #+BEGIN_SRC emacs-lisp -(setq EXWM_ENABLE nil) - -(if (found-custom-arg "-start_wm") - (setq EXWM_ENABLE t) -) - +(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 -* Term +** Use-package -** Toggle between char- and line-mode - -Courtesy goes to https://joelmccracken.github.io/entries/switching-between-term-mode-and-line-mode-in-emacs-term/ +*** Always ensure #+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) +(require 'use-package-ensure) +(setq use-package-always-ensure t) #+END_SRC -* Resize frame +** 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): @@ -120,8 +322,8 @@ C-c C-c to apply." :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."))) + (message "Only root frame exists, abort.")) + (message "Use arrow-keys or C-p/n/f/b to adjust frames."))) (defun resize-frame-done () (interactive) @@ -131,153 +333,323 @@ C-c C-c to apply." (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. +* Completion +** Minibuffer #+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) +(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 -** Goto-line - -Starting with Emacs 23.2, =M-g g= is bound to goto-line. -However, I find this too long. So rebind it: +** Consult #+BEGIN_SRC emacs-lisp -(global-set-key (kbd "M-g") 'goto-line) -#+END_SRC +(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 + ) -** Rectangle + ;; 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) -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. + ;; The :init configuration is always executed (Not lazy) + :init -#+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 + ;; 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) -** Garbage collection (gc) + ;; 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) -I used to have the following enabled in my init to increase the gc threshold to speed-up emacs startup: -(stolen from [[http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/]]) + ;; Use Consult to select xref locations with preview + (setq xref-show-xrefs-function #'consult-xref + xref-show-definitions-function #'consult-xref) -#+BEGIN_SRC emacs-lisp -(setq gc-cons-threshold 100000000) -#+END_SRC + ;; Configure other variables and modes in the :config section, + ;; after lazily loading the package. + ;; :config -But according to this: [[https://lists.gnu.org/archive/html/help-gnu-emacs/2007-06/msg00243.html ]], -it is no longer necessary. But I found that I still have to do this to speed up emacs. + ;; 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)) -** Yes-or-no questions + ;; Optionally configure the narrowing key. + ;; Both < and C-+ work reasonably well. + ;; (setq consult-narrow-key "<") ;; "C-+" -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*") + ;; 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) ) -(add-hook 'help-mode-hook 'move-to-help-window) #+END_SRC -* Which-key +** In-buffer completion -Display available keybindings in popup: -https://github.com/justbur/emacs-which-key +*** Consult #+BEGIN_SRC emacs-lisp -(use-package which-key - :ensure t - :config - (which-key-setup-side-window-bottom) - (which-key-mode)) +(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 - :ensure t - :init + :config (load-theme 'monokai t) - ) #+END_SRC -** Highlight line +* Dashboard -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 +#+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 @@ -285,41 +657,16 @@ https://github.com/abo-abo/hydra #+BEGIN_SRC emacs-lisp (use-package hydra - :ensure t -) -#+END_SRC - -** Hydra Zoom - -#+BEGIN_SRC emacs-lisp -(defhydra hydra-zoom (global-map "") - "zoom" - ("g" text-scale-increase "in") - ("l" text-scale-decrease "out")) -#+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 - :ensure t - :init - (recentf-mode 1) :config - (dashboard-setup-startup-hook) - (setq dashboard-startup-banner "~/.emacs.d/img/dash_logo.png") - (setq dashboard-items '((recents . 10) - (bookmarks . 5) - )) - (setq dashboard-banner-logo-title "") -) -#+END_SRC + ;; Zoom hydra + (defhydra hydra-zoom (global-map "") + "zoom" + ("g" text-scale-increase "in") + ("l" text-scale-decrease "out") + ) -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. + ) +#+END_SRC * Zygospore @@ -330,143 +677,187 @@ FYI: At one point, used this together with sr-speedbar. They did not play well t #+BEGIN_SRC emacs-lisp (use-package zygospore - :ensure t :config (global-set-key (kbd "C-x 1") 'zygospore-toggle-delete-other-windows) ) #+END_SRC -* Mode-line +* Iedit -[[https://github.com/Malabarba/smart-mode-line]] +Highlight occurences of symbol and replace them simultanously. +Shortkey: =C-;= + +https://github.com/victorhge/iedit #+BEGIN_SRC emacs-lisp -(use-package smart-mode-line - :ensure t - :config - (setq sml/no-confirm-load-theme t) - (setq sml/theme 'respectful) - (sml/setup) -) +(use-package iedit) #+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 - -** Tab-width - -Set the default tab width. -#+BEGIN_SRC emacs-lisp -(setq-default tab-width 4) -#+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 +* Programming ** 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) +(defface highlight-angry-faces + '( + (default :background "Yellow" :foreground "Red") + ) + "Angry faces highlighting." + :group 'basic-faces +) -;; 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) + (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 -** C Coding settings - -Some basic C-coding settings (style, indentation offset, ...). +** Electric pair #+BEGIN_SRC emacs-lisp -;; default coding style -(setq c-default-style "linux") - -;; sane indentation offset -(setq c-basic-offset 4) +(use-package elec-pair + :ensure nil + :defer t + :hook (prog-mode-hook . electric-pair-mode)) #+END_SRC -** Tabs vs spaces - -Tabs are evil. +** Paren #+BEGIN_SRC emacs-lisp -(setq-default indent-tabs-mode nil) +(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 -* Undo-tree +** Eglot -Undo with =C-/=. #+BEGIN_SRC emacs-lisp -(use-package undo-tree - :ensure t +(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 - (global-undo-tree-mode) + (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 @@ -478,109 +869,11 @@ https://github.com/k-talo/volatile-highlights.el #+BEGIN_SRC emacs-lisp (use-package volatile-highlights - :ensure t :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 - :ensure t -) -#+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 - :ensure t - :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. @@ -589,789 +882,371 @@ https://github.com/remyferre/comment-dwim-2 #+BEGIN_SRC emacs-lisp (use-package comment-dwim-2 - :ensure t - :config - (global-set-key (kbd "M-;") 'comment-dwim-2) + :bind + ("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 - :ensure t - :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 - :ensure t :config - (setq projectile-indexing-method 'alien) - (projectile-global-mode) - (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map) + (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 - -* Helm +* Org ** General config #+BEGIN_SRC emacs-lisp -(use-package helm - :ensure t - :bind - ("M-x" . helm-M-x) - ("M-y" . helm-show-kill-ring) - ("C-x b" . helm-mini) - ("C-x C-b" . helm-mini) - ("C-x C-f" . helm-find-files) - :init - (helm-mode 1) +(use-package org + :ensure nil + :defer t + :mode ("\\.org\\'" . org-mode) :config - (setq helm-M-x-fuzzy-match t - helm-buffers-fuzzy-matching t - helm-recentf-fuzzy-match t - helm-semantic-fuzzy-match t - helm-imenu-fuzzy-match t - helm-split-window-inside-p t ;; open helm buffer inside current window - helm-scroll-amount 8 ;; scroll 8 lines other window using M-/M- -;; helm-move-to-line-cycle-in-source nil ;; move to end or beginning of source when reaching to por bottom of source -;; helm-ff-search-library-in-sexp t ;; search for library in 'require' and 'declare-function' sexp -;; helm-echo-input-in-header-line t - ) - ;; 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) - (helm-autoresize-mode 1) ;; Awesome feature together with helm-split-window-inside-p != nil -) - -(use-package helm-swoop - :ensure t - :bind - ("C-s" . helm-swoop) - :config - ;; "C-s" + "C-s" results in mult-swoop - (define-key helm-swoop-map (kbd "C-s") 'helm-multi-swoop-all-from-helm-swoop) - ;; split window inside the current window when multiple windows open - (setq helm-swoop-split-with-multiple-windows t) -) - -;; (require 'helm-config) -;; ;; (define-key helm-find-files-map (kbd "C-b") 'helm-find-files-up-one-level) -;; ;; (define-key helm-find-files-map (kbd "C-f") 'helm-execute-persistent-action) -;; -;; make TAB work in terminal/minibuffer -(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) - + (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 -** Helm-gtags +** Org-todo + +*** Mark parent entry as DONE when children are DONE #+BEGIN_SRC emacs-lisp -(use-package helm-gtags - :ensure t - :bind - ( "M-." . helm-gtags-find-tag-from-here) - ( "M-," . helm-gtags-pop-stack) - :config - (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) +(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")))) - (custom-set-variables '(helm-gtags-auto-update t)) -) +(add-hook 'org-after-todo-statistics-hook #'org-summary-todo) #+END_SRC -** Helm-projectile - -Helm interface to projectile: -https://github.com/bbatsov/helm-projectile - -#+BEGIN_SRC emacs-lisp -(use-package helm-projectile - :ensure t - :init - (setq helm-projectile-fuzzy-match t) - (setq projectile-completion-system 'helm) - (setq projectile-switch-project-action 'helm-projectile) - :config - (helm-projectile-on) -) -#+END_SRC - -** Helm-mt - -Helm frontend for [[Multi-term]] -https://github.com/dfdeshom/helm-mt - -#+BEGIN_SRC emacs-lisp -(use-package helm-mt - :ensure t - :bind ("C-x t" . helm-mt) - :config - (helm-mt/reroute-terminal-functions t) -) -#+END_SRC - -* Mutliple cursors - -https://github.com/magnars/multiple-cursors.el - -#+BEGIN_SRC emacs-lisp -(use-package multiple-cursors - :ensure t - :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 magit - :ensure t - :bind - ("C-c m" . magit-status) -) -#+END_SRC - -* Programming - -** Yasnippet - -Template system for Emacs. - -https://github.com/joaotavora/yasnippet - -#+BEGIN_SRC emacs-lisp -(use-package yasnippet - :ensure t - :init - (add-to-list 'load-path - "~/.emacs.d/plugins/yasnippet") - :config - (add-hook 'prog-mode-hook 'yas-minor-mode) -) -#+END_SRC - -** Flycheck - -On-the-fly syntax checking. - -#+BEGIN_SRC emacs-lisp -(use-package flycheck - :ensure t - :config - (add-hook 'prog-mode-hook 'flycheck-mode) -) -#+END_SRC - -** Company mode - -#+BEGIN_SRC emacs-lisp -(use-package company - :ensure t - :config - (setq company-idle-delay 0) - (setq company-minimum-prefix-length 2)) - (add-hook 'prog-mode-hook 'company-mode) -#+END_SRC - -** LSP - -Just awesome IDE features: -https://github.com/MaskRay/ccls -https://github.com/MaskRay/emacs-ccls -https://github.com/emacs-lsp/lsp-mode -https://github.com/emacs-lsp/lsp-ui -https://github.com/tigersoldier/company-lsp -https://github.com/joaotavora/eglot - -#+BEGIN_SRC emacs-lisp -(defun +ccls/enable () - (condition-case nil - (lsp-ccls-enable) - (user-error nil))) - -(use-package ccls - :ensure t - :commands lsp-ccls-enable - :init - (add-hook 'c-mode-hook #'+ccls/enable) -) - -(use-package lsp-ui - :ensure t - :init (add-hook 'lsp-after-open-hook #'lsp-ui-mode) - :config - (setq lsp-ui-doc-enable t - lsp-ui-doc-header t - lsp-ui-doc-include-signature t - ;; lsp-ui-doc-position 'at-point - ) - ) - -(use-package company-lsp - :ensure t - :config - (push 'company-lsp company-backends) - (setq company-lsp-enable-recompletion t - company-lsp-enable-snippet t - company-lsp-cache-candidates t - company-lsp-async t) -) - -(use-package eglot - :ensure t - :init - (add-hook 'prog-mode-hook 'eglot-ensure) -) -#+END_SRC - -** (Relative) Line numbers - -#+BEGIN_SRC emacs-lisp -(use-package linum-relative - :ensure t - :config - (setq linum-relative-current-symbol "") - (add-hook 'prog-mode-hook 'linum-relative-mode)) -#+END_SRC - -** C/C++ mode - -*** Flycheck - -Functionality provided by LSP and flycheck combination. - -*** Company - -#+BEGIN_SRC emacs-lisp -(use-package company-c-headers - :ensure t) -#+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 - :ensure t - :config - (elpy-enable) -) -#+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 - :ensure t - :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 - :ensure t - :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. - -#+BEGIN_SRC emacs-lisp -(server-start) -#+END_SRC - -* Beacon - -https://github.com/Malabarba/beacon - -#+BEGIN_SRC emacs-lisp -(use-package beacon - :ensure t - :config - (beacon-mode 1) - (setq beacon-color "#FFFFCC") ;; yelowish -) -#+END_SRC - -* Sunrise commander - -https://github.com/escherdragon/sunrise-commander - -** Install - -#+BEGIN_SRC emacs-lisp -(add-to-list 'load-path "~/.emacs.d/extra/sunrise-commander") - -(require 'sunrise-commander) -(require 'sunrise-x-buttons) -(require 'sunrise-x-modeline) - -(global-set-key (kbd "C-c s") 'sunrise) -(global-set-key (kbd "C-c c") 'sunrise-cd) - -(add-to-list 'auto-mode-alist '("\\.srvm\\'" . sr-virtual-mode)) -#+END_SRC - -* Org - ** Org bullets -https://github.com/sabof/org-bullets - #+BEGIN_SRC emacs-lisp (use-package org-bullets - :ensure t + :defer t + :after org :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 +** Org Roam #+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 - -* Diminish - -https://github.com/myrjola/diminish.el - -#+BEGIN_SRC emacs-lisp -(use-package diminish - :ensure t +(use-package org-roam + :demand + :custom + (org-roam-directory "~/projects/notes") + (org-roam-completion-everywhere t) :config - (diminish 'volatile-highlights-mode) - (diminish 'smartparens-mode) - (diminish 'beacon-mode) - (diminish 'subword-mode) - (diminish 'auto-revert-mode) - (diminish 'helm-mode) - (diminish 'undo-tree-mode) - (diminish 'page-break-lines-mode) + (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 -* Shell -** Multi-term -<> - -Manage multiple terminals. - -https://www.emacswiki.org/emacs/MultiTerm +*** Consult #+BEGIN_SRC emacs-lisp -(use-package multi-term - :ensure t -) +(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 -* Shell-pop - -https://github.com/kyagi/shell-pop-el +** Org Download #+BEGIN_SRC emacs-lisp -(use-package shell-pop - :ensure t - :bind (("C-c t" . shell-pop)) +(use-package org-download + :defer t + :after org :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)) + (add-hook 'dired-mode-hook 'org-download-enable) + ) #+END_SRC -* Old stuff, maybe usefull for lookup later +* Elisp -** Diff mode stuff +** Add demos to describe-function #+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 - -* Paradox - -Paradox is a more modern package menu. -It can update packages async, ... - -https://github.com/Malabarba/paradox - -#+BEGIN_SRC emacs-lisp -(use-package paradox - :ensure t - :init - (setq paradox-execute-asynchronously t) +(use-package elisp-demos :config - (paradox-enable) -) - + (advice-add 'describe-function-1 :after #'elisp-demos-advice-describe-function-1) + ) #+END_SRC -* EXWM +* Custom -Arandr config is still too static, should find a way to simplify this. +** Modeline #+BEGIN_SRC emacs-lisp -(if EXWM_ENABLE - (progn - (message "Loading EXWM...") - (use-package exwm - :ensure t - :config - (require 'exwm-systemtray) - (exwm-systemtray-enable) +(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) - (require 'exwm-randr) - (setq exwm-workspace-number 1) + (:propertize + ("" mode-line-mule-info mode-line-client mode-line-modified mode-line-remote mode-line-window-dedicated)) - ;; (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) + 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 - (require 'exwm-config) +** Org-roam - ;; 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]))) +Inspired by https://github.com/org-roam/org-roam/wiki/User-contributed-Tricks#filter-by-a-tag . - (global-set-key (kbd "C-x C-b") 'exwm-workspace-switch-to-buffer) +#+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 - ;; Enable EXWM - (exwm-enable) +** 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 -* TODO +** Save symbol at point -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 +#+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 new file mode 100644 index 0000000..ff3b9cb --- /dev/null +++ b/config_old.org @@ -0,0 +1,1608 @@ +#+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 deleted file mode 100644 index fbfbaca..0000000 --- a/custom/setup-autocompletion.el +++ /dev/null @@ -1,8 +0,0 @@ -;; Add irony as flycheck hook -(eval-after-load 'flycheck - '(add-hook 'flycheck-mode-hook 'flycheck-irony-setup)) - -;; 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 deleted file mode 100644 index d915503..0000000 --- a/custom/setup-coding.el +++ /dev/null @@ -1,11 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; 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) - -(provide 'setup-coding) diff --git a/custom/setup-org.el b/custom/setup-org.el deleted file mode 100644 index 1a448e6..0000000 --- a/custom/setup-org.el +++ /dev/null @@ -1,28 +0,0 @@ -(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/early-init.el b/early-init.el new file mode 100644 index 0000000..5d83494 --- /dev/null +++ b/early-init.el @@ -0,0 +1,18 @@ +;;; 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/extra/sunrise-commander b/extra/sunrise-commander deleted file mode 160000 index cf8305a..0000000 --- a/extra/sunrise-commander +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cf8305a149a321d028858057e7a7c92f0038a06a diff --git a/img/dash_logo.png b/img/dash_logo.png deleted file mode 100644 index bd8c88b..0000000 Binary files a/img/dash_logo.png and /dev/null differ diff --git a/init.el b/init.el index dbbf211..3f13d33 100644 --- a/init.el +++ b/init.el @@ -1,39 +1,28 @@ -;; IMPORTANT: add (require 'package), else package-archives is not declared (void-variable) -(require 'package) +;;; init.el --- Init -*- lexical-binding: t; -*- -(setq package-enable-at-startup nil) -;; add melpa-stable to package-archives -(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) +;;; Commentary: +;;; Load init files -;; MUST be called after package-archives is updated -(package-initialize) -;;; Bootstrapping use-package -(unless (package-installed-p 'use-package) - (package-refresh-contents) - (package-install 'use-package)) +;;; Code: -;;; This is the actual config file. It is omitted if it doesn't exist so emacs won't refuse to launch. -(when (file-readable-p "~/.emacs.d/config.org") -(org-babel-load-file (expand-file-name "~/.emacs.d/config.org"))) +;;; 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)) + + (when (file-readable-p my-config-file) + (org-babel-load-file (expand-file-name my-config-file))) + + (load custom-file :no-error-if-file-is-missing) +) (provide 'init) -(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. - '(helm-gtags-auto-update t) - '(package-selected-packages - (quote - (elpy linum-relative avy flycheck-irony irony-eldoc company-irony company-c-headers flycheck magit py-autopep8 multiple-cursors helm-gtags helm-swoop zygospore yasnippet volatile-highlights use-package undo-tree smartparens smart-mode-line monokai-theme iedit helm expand-region dashboard comment-dwim-2)))) -(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. - ) + +;;; init.el ends here diff --git a/plugins/yasnippet/c-mode/oncekl b/plugins/yasnippet/c-mode/oncekl deleted file mode 100644 index d0f8afc..0000000 --- a/plugins/yasnippet/c-mode/oncekl +++ /dev/null @@ -1,9 +0,0 @@ -#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/c-mode/define b/snippets/c-mode/define new file mode 100644 index 0000000..eb89c4a --- /dev/null +++ b/snippets/c-mode/define @@ -0,0 +1,6 @@ +# -*- mode: snippet -*- +# name: Make a define +# key: def +# -- + +#define ${1:mydefine$(upcase yas-text)} $2 diff --git a/plugins/yasnippet/c-mode/fori b/snippets/c-mode/fori similarity index 62% rename from plugins/yasnippet/c-mode/fori rename to snippets/c-mode/fori index 63e65b0..e2e0ac6 100644 --- a/plugins/yasnippet/c-mode/fori +++ b/snippets/c-mode/fori @@ -3,6 +3,6 @@ # key: fori # -- -for (${1:int i = 0}; ${2:i < N}; ${3:++i}) { +for (${1:size_t 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 new file mode 100644 index 0000000..a7b5339 --- /dev/null +++ b/snippets/c-mode/header @@ -0,0 +1,10 @@ +#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 new file mode 100644 index 0000000..d4220a2 --- /dev/null +++ b/snippets/c-mode/kaboom @@ -0,0 +1,6 @@ +# -*- mode: snippet -*- +# name: kaboom +# key: kb +# -- + +char (*__kaboom)[sizeof($1)] = 1; diff --git a/snippets/org-mode/emacs-lisp-source-block b/snippets/org-mode/emacs-lisp-source-block new file mode 100644 index 0000000..25f00aa --- /dev/null +++ b/snippets/org-mode/emacs-lisp-source-block @@ -0,0 +1,8 @@ +# -*- 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 new file mode 100644 index 0000000..b3f283d --- /dev/null +++ b/snippets/org-mode/filetags @@ -0,0 +1,6 @@ +# -*- mode: snippet -*- +# name: Filetags +# key: ft +# -- + +#+FILETAGS: :$1: diff --git a/snippets/org-mode/source_block_emacs b/snippets/org-mode/source_block_emacs new file mode 100644 index 0000000..215d78e --- /dev/null +++ b/snippets/org-mode/source_block_emacs @@ -0,0 +1,8 @@ +# -*- 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 new file mode 100644 index 0000000..983e180 --- /dev/null +++ b/snippets/text-mode/git-commit-message-before-after @@ -0,0 +1,10 @@ +# -*- mode: snippet -*- +# name: Git commit message template +# key: bac +# -- + +Before this commit, +${1} + +After this commit, +${2}