(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) ;; Enable vertico (use-package vertico :ensure t :init (vertico-mode) ;; Different scroll margin ;; (setq vertico-scroll-margin 0) ;; Show more candidates ;; (setq vertico-count 20) ;; Grow and shrink the Vertico minibuffer ;; (setq vertico-resize t) ;; Optionally enable cycling for `vertico-next' and `vertico-previous'. ;; (setq vertico-cycle t) ) ;; Persist history over Emacs restarts. Vertico sorts by history position. (use-package savehist :ensure t :init (savehist-mode)) ;; A few more useful configurations... (use-package emacs :init ;; Add prompt indicator to `completing-read-multiple'. ;; We display [CRM], e.g., [CRM,] if the separator is a comma. (defun crm-indicator (args) (cons (format "[CRM%s] %s" (replace-regexp-in-string "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" "" crm-separator) (car args)) (cdr args))) (advice-add #'completing-read-multiple :filter-args #'crm-indicator) ;; Do not allow the cursor in the minibuffer prompt (setq minibuffer-prompt-properties '(read-only t cursor-intangible t face minibuffer-prompt)) (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode) ;; Support opening new minibuffers from inside existing minibuffers. (setq enable-recursive-minibuffers t) ;; Emacs 28 and newer: Hide commands in M-x which do not work in the current ;; mode. Vertico commands are hidden in normal buffers. This setting is ;; useful beyond Vertico. (setq read-extended-command-predicate #'command-completion-default-include-p) ;; Settings the smooth croll (setq scroll-margin 5 scroll-step 1 scroll-conservatively 10000 scroll-preserve-screen-position 1) ;; Set backup behiviour (setq backup-by-copying t ; don't clobber symlinks backup-directory-alist '(("." . "~/.saves/")) ; don't litter my fs tree delete-old-versions t kept-new-versions 6 kept-old-versions 2 version-control t) ; use versioned backups ;; Settings keymap :bind (("C-x t " . tab-bar-switch-to-next-tab) ("C-x t " . tab-bar-switch-to-prev-tab) ("C-x C-g" . recentf-open-files) ("C-q" . mark-word) ("C-x w" . downcase-word) ("C-," . shrink-window-horizontally) ("C-." . enlarge-window-horizontally))) ;; example configuration for Consult (use-package consult :ensure t ;; Replace bindings. Lazily loaded due 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-g i" . consult-imenu) ("M-g I" . consult-imenu-multi) ;; M-s bindings in `search-map' ("M-s d" . consult-find) ;; Alternative: consult-fd ("M-s c" . consult-locate) ("M-s g" . consult-grep) ("M-s G" . consult-git-grep) ("M-s r" . consult-ripgrep) ("M-s l" . consult-line) ("M-s L" . consult-line-multi) ("M-s k" . consult-keep-lines) ("M-s u" . consult-focus-lines) ;; Isearch integration ("M-s e" . consult-isearch-history) :map isearch-mode-map ("M-e" . consult-isearch-history) ;; orig. isearch-edit-string ("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string ("M-s l" . consult-line) ;; needed by consult-line to detect isearch ("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch ;; Minibuffer history :map minibuffer-local-map ("M-s" . consult-history) ;; orig. next-matching-history-element ("M-r" . consult-history)) ;; orig. previous-matching-history-element ;; Enable automatic preview at point in the *Completions* buffer. This is ;; relevant when you use the default completion UI. :hook (completion-list-mode . consult-preview-at-point-mode) ;; The :init configuration is always executed (Not lazy) :init ;; Optionally configure the register formatting. This improves the register ;; preview for `consult-register', `consult-register-load', ;; `consult-register-store' and the Emacs built-ins. (setq register-preview-delay 0.5 register-preview-function #'consult-register-format) ;; Optionally tweak the register preview window. ;; This adds thin lines, sorting and hides the mode line of the window. (advice-add #'register-preview :override #'consult-register-window) ;; Use Consult to select xref locations with preview (setq xref-show-xrefs-function #'consult-xref xref-show-definitions-function #'consult-xref) ;; Configure other variables and modes in the :config section, ;; after lazily loading the package. :config ;; Optionally configure preview. The default value ;; is 'any, such that any key triggers the preview. ;; (setq consult-preview-key 'any) ;; (setq consult-preview-key "M-.") ;; (setq consult-preview-key '("S-" "S-")) ;; For some commands and buffer sources it is useful to configure the ;; :preview-key on a per-command basis using the `consult-customize' macro. (consult-customize consult-theme :preview-key '(:debounce 0.2 any) consult-ripgrep consult-git-grep consult-grep consult-bookmark consult-recent-file consult-xref consult--source-bookmark consult--source-file-register consult--source-recent-file consult--source-project-recent-file ;; :preview-key "M-." :preview-key '(:debounce 0.4 any)) ;; Optionally configure the narrowing key. ;; Both < and C-+ work reasonably well. (setq consult-narrow-key "<") ;; "C-+" ;; Optionally make narrowing help available in the minibuffer. ;; You may want to use `embark-prefix-help-command' or which-key instead. ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help) ;; By default `consult-project-function' uses `project-root' from project.el. ;; Optionally configure a different project root function. ;;;; 1. project.el (the default) ;; (setq consult-project-function #'consult--default-project--function) ;;;; 2. vc.el (vc-root-dir) ;; (setq consult-project-function (lambda (_) (vc-root-dir))) ;;;; 3. locate-dominating-file ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git"))) ;;;; 4. projectile.el (projectile-project-root) ;; (autoload 'projectile-project-root "projectile") ;; (setq consult-project-function (lambda (_) (projectile-project-root))) ;;;; 5. No project support ;; (setq consult-project-function nil) ) (use-package orderless :ensure t :demand t :config (defun +orderless--consult-suffix () "Regexp which matches the end of string with Consult tofu support." (if (and (boundp 'consult--tofu-char) (boundp 'consult--tofu-range)) (format "[%c-%c]*$" consult--tofu-char (+ consult--tofu-char consult--tofu-range -1)) "$")) ;; Recognizes the following patterns: ;; * .ext (file extension) ;; * regexp$ (regexp matching at end) (defun +orderless-consult-dispatch (word _index _total) (cond ;; Ensure that $ works with Consult commands, which add disambiguation suffixes ((string-suffix-p "$" word) `(orderless-regexp . ,(concat (substring word 0 -1) (+orderless--consult-suffix)))) ;; File extensions ((and (or minibuffer-completing-file-name (derived-mode-p 'eshell-mode)) (string-match-p "\\`\\.." word)) `(orderless-regexp . ,(concat "\\." (substring word 1) (+orderless--consult-suffix)))))) ;; Define orderless style with initialism by default (orderless-define-completion-style +orderless-with-initialism (orderless-matching-styles '(orderless-initialism orderless-literal orderless-regexp))) ;; You may want to combine the `orderless` style with `substring` and/or `basic`. ;; There are many details to consider, but the following configurations all work well. ;; Personally I (@minad) use option 3 currently. Also note that you may want to configure ;; special styles for special completion categories, e.g., partial-completion for files. ;; ;; 1. (setq completion-styles '(orderless)) ;; This configuration results in a very coherent completion experience, ;; since orderless is used always and exclusively. But it may not work ;; in all scenarios. Prefix expansion with TAB is not possible. ;; ;; 2. (setq completion-styles '(substring orderless)) ;; By trying substring before orderless, TAB expansion is possible. ;; The downside is that you can observe the switch from substring to orderless ;; during completion, less coherent. ;; ;; 3. (setq completion-styles '(orderless basic)) ;; Certain dynamic completion tables (completion-table-dynamic) ;; do not work properly with orderless. One can add basic as a fallback. ;; Basic will only be used when orderless fails, which happens only for ;; these special tables. ;; ;; 4. (setq completion-styles '(substring orderless basic)) ;; Combine substring, orderless and basic. ;; (setq completion-styles '(orderless basic) completion-category-defaults nil ;;; Enable partial-completion for files. ;;; Either give orderless precedence or partial-completion. ;;; Note that completion-category-overrides is not really an override, ;;; but rather prepended to the default completion-styles. ;; completion-category-overrides '((file (styles orderless partial-completion))) ;; orderless is tried first completion-category-overrides '((file (styles partial-completion)) ;; partial-completion is tried first ;; enable initialism by default for symbols (command (styles +orderless-with-initialism)) (variable (styles +orderless-with-initialism)) (symbol (styles +orderless-with-initialism))) orderless-component-separator #'orderless-escapable-split-on-space ;; allow escaping space with backslash! orderless-style-dispatchers (list #'+orderless-consult-dispatch #'orderless-affix-dispatch))) (use-package company :ensure t :init (global-company-mode) :hook (c-mode . company-mode) :custom (company-idle-delay 0.01)) (use-package flycheck :ensure t :init (global-flycheck-mode)) ;; (use-package flycheck-eglot ;; :ensure t ;; :after (flycheck eglot)) ;;(use-package tree-sitter ;; :ensure t ;; :init (global-tree-sitter-mode)) ;; ;;(use-package tree-sitter-langs ;; :ensure t ;; :after tree-sitter ;; :hook ((c-mode d-mode) . tree-sitter-hl-mode)) (use-package markdown-mode :ensure t :commands (markdown-mode gfm-mode) :mode (("README\\.md\\'" . gfm-mode) ("\\.md\\'" . markdown-mode) ("\\.markdown\\'" . markdown-mode)) :init (setq markdown-command "pandoc")) (use-package multiple-cursors :ensure t :init :bind(("C-S-c C-S-c" . mc/edit-lines) ("C->" . mc/mark-next-like-this) ("C-<" . mc/mark-previous-like-this) ("C-S-c C-<" . mc/mark-previous-like-this-word))) (use-package json-mode :custom (js-indent-line 4)) (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. '(custom-enabled-themes '(gruvbox-dark-medium)) '(custom-safe-themes '("046a2b81d13afddae309930ef85d458c4f5d278a69448e5a5261a5c78598e012" "d445c7b530713eac282ecdeea07a8fa59692c83045bf84dd112dd738c7bcad1d" "ba323a013c25b355eb9a0550541573d535831c557674c8d59b9ac6aa720c21d3" "871b064b53235facde040f6bdfa28d03d9f4b966d8ce28fb1725313731a2bcc8" "7b8f5bbdc7c316ee62f271acf6bcd0e0b8a272fdffe908f8c920b0ba34871d98" default)) '(display-line-numbers t) '(flycheck-c/c++-gcc-executable "x86_64-w64-mingw32-gcc-14") '(flycheck-gcc-args '("-Wall" "-mwindows" "-municode")) '(indent-tabs-mode nil) '(inhibit-startup-screen t) '(menu-bar-mode nil) '(package-selected-packages '(multiple-cursors markdown-mode d-mode flycheck tree-sitter-langs tree-sitter company consult orderless vertico gruvbox-theme)) '(recentf-mode t) '(tab-bar-mode t) '(tab-width 4) '(tool-bar-mode nil) '(xref-show-definitions-function 'consult-xref)) (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. ) (put 'downcase-region 'disabled nil)