diff options
author | Thanos Apollo <[email protected]> | 2024-12-11 00:39:02 +0200 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-12-18 23:31:05 +0200 |
commit | 5d5430eacac6e99704a415db5ec27e158465f424 (patch) | |
tree | 456ade4236903a8a85e5ac1c2c4c6c452b71f455 | |
parent | ce701997efaf5fe7a006269764d51d03030b2c39 (diff) |
emacs: Update completions & adjust search funcs
-rw-r--r-- | .config/emacs/init.el | 149 |
1 files changed, 101 insertions, 48 deletions
diff --git a/.config/emacs/init.el b/.config/emacs/init.el index 63edd54..e8e184f 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -54,33 +54,6 @@ (setf auto-insert-alist '((python-mode . "python.template")) auto-insert-directory (locate-user-emacs-file "insert")) -;;;; Completions -(add-to-list 'completion-styles 'initials t) -(setf tab-always-indent 'icomplete-force-complete) -(require 'completion-preview) - - -(define-key completion-in-region-mode-map (kbd "M-n") 'minibuffer-next-completion) -(define-key completion-in-region-mode-map (kbd "M-p") 'minibuffer-previous-completion) - -(setf completion-styles '(flex) - completion-auto-select t - completion-auto-help 'always - completion-cycle-threshold 1 - completions-format 'vertical - completions-sort 'historical - completions-max-height 20) - -;; Fido -(require 'icomplete) -(fido-vertical-mode) -(define-key icomplete-fido-mode-map (kbd "TAB") #'icomplete-fido-ret) - -(when (> emacs-major-version 29) - (global-completion-preview-mode)) - -;; Search -(setf search-default-mode #'char-fold-to-regexp) ;; make it easier to search Greek chars ;; Set and load custom.el (setf custom-file (locate-user-emacs-file "custom.el")) @@ -88,6 +61,7 @@ ;; Imenu ;; Enable use-package support for imenu +;; NOTE: Load this before use-package! (setf use-package-enable-imenu-support t) (require 'imenu) @@ -96,6 +70,36 @@ (global-set-key (kbd "C-c m") 'imenu) + +;;;; Completions & Minibuffer + +(use-package completion-preview + :ensure t + :config + (global-completion-preview-mode) + ;; Enable completion-preview in org-mode + (push 'org-self-insert-command completion-preview-commands)) + +(use-package icomplete + :ensure t + :config + (setf completion-styles '(basic flex) + completion-auto-select t ;; Show completion on first call + completion-auto-help 'visible ;; Display *Completions* upon first request + completions-format 'one-column ;; Use only one column + completions-sort 'historical ;; Order based on minibuffer history + completions-max-height 20 ;; Limit completions to 15 + completion-ignore-case t) + ;; Minibuffer completions + (fido-vertical-mode) + :bind (:map icomplete-fido-mode-map + ("TAB" . 'icomplete-fido-ret))) + +;; (define-key minibuffer-local-completion-map (kbd "SPC") 'self-insert-command) + +;; Search +(setf search-default-mode #'char-fold-to-regexp) ;; make it easier to search Greek chars + ;; Registers & Misc nav (setf register-use-preview t) @@ -103,11 +107,62 @@ (global-set-key (kbd "C-x C-b") 'switch-to-prev-buffer) (global-set-key (kbd "C-x M-b") 'ibuffer) +(defun switch-to-window-with-buffer (buffer-name) + "Switch to a window displaying a buffer named BUFFER-NAME, if it exists." + (let ((target-window nil)) + (walk-windows (lambda (w) + (when (string= (buffer-name (window-buffer w)) buffer-name) + (setq target-window w))) + nil t) + (if target-window + (select-window target-window) + (message "No window is displaying buffer '%s'" buffer-name)))) + +(defun thanos/occur (regexp &optional nlines region) + "Run `occur' and switch to *Occur* buffer." + (interactive (nconc (occur-read-primary-args) + (and (use-region-p) (list (region-bounds))))) + (let* ((start (and (caar region) (max (caar region) (point-min)))) + (end (and (cdar region) (min (cdar region) (point-max)))) + (in-region (or start end)) + (bufs (if (not in-region) (list (current-buffer)) + (let ((ol (make-overlay + (or start (point-min)) + (or end (point-max))))) + (overlay-put ol 'occur--orig-point (point)) + (list ol))))) + (occur-1 regexp nlines bufs)) + (switch-to-window-with-buffer "*Occur*") + (forward-line)) + +(defun thanos/close-window (buffer-name) + "Go to occurrence and quit the *Occur* window." + (let ((occur-window (get-buffer-window buffer-name))) + (when occur-window + (quit-window nil occur-window)))) + +(defun thanos/occur-mode-goto-occurrence-close-occur-window () + "Go to occurrence and quit the *Occur* window." + (interactive) + (occur-mode-goto-occurrence) + (thanos/close-window "*Occur*")) + +(defun thanos/compile-goto-error (&optional event) + "." + (interactive (list last-input-event)) + (compile-goto-error) + (thanos/close-window "*grep*")) + + +(define-key occur-mode-map (kbd "RET") 'thanos/occur-mode-goto-occurrence-close-occur-window) +(define-key grep-mode-map (kbd "C-o") 'thanos/compile-goto-error) + (defvar-keymap thanos/search-map "g" #'grep-find "l" #'lgrep "f" #'find-name-dired - "s" #'occur) + "o" #'thanos/occur + "C-o" #'occur) (global-set-key (kbd "C-c s") thanos/search-map) @@ -130,6 +185,14 @@ ("\\<\\(TODO\\):" 1 font-lock-warning-face t) ("\\<\\(NOTE\\):" 1 font-lock-warning-face t)))) +(setf tab-always-indent 'icomplete-force-complete) + +(use-package flyspell + :ensure t + :config + (setf ispell-alternate-dictionary + (expand-file-name "~/.hunspell.d/en_med.dic"))) + (use-package org :ensure t :config @@ -204,7 +267,6 @@ (use-package emacs :ensure nil :config - (if is-zeus (display-battery-mode 0) (display-battery-mode 1)) @@ -370,8 +432,6 @@ ;; org-roam-ui-update-on-save t ;; org-roam-ui-open-on-start t)) - - (unless (or is-phone is-uranus) (use-package modus-themes :ensure t @@ -544,11 +604,6 @@ :config (eshell-syntax-highlighting-global-mode 1)) -(use-package emojify - :ensure t - :hook (erc-mode . emojify-mode) - :commands emojify-mode) - (use-package flycheck :ensure t :config @@ -684,11 +739,6 @@ :config (setf sudo-edit-local-method "sudo")) -(use-package dabbrev - :defer t - :config - (setf dabbrev-ignored-buffer-regexps '("\\.\\(?:pdf\\|jpe?g\\|png\\)\\'"))) - ;; My packages (when (or is-zeus is-hermes) (use-package yeetube @@ -766,10 +816,11 @@ gnosis-image-width (and is-hermes 150) gnosis-image-height (and is-hermes 150)) (gnosis-modeline-mode) - (setf gnosis-custom-values '((:deck "Bulgarian" (:amnesia 0.55 :proto (0 1 3))) - (:deck "Unking" (:amnesia 0.45)) - (:tag "vocabulary" (:amnesia 0.65 :proto (0 1 3))))) - :bind (("C-c g" . 'thanos/gnosis-map) + (setf gnosis-custom-values + '((:deck "Bulgarian" (:amnesia 0.55 :proto (0 1 3))) + (:deck "Unking" (:amnesia 0.45)) + (:tag "vocabulary" (:amnesia 0.65 :proto (0 1 3))))) + :bind (("C-M-r" . 'thanos/gnosis-map) :map thanos/gnosis-map ("a" . 'gnosis-add-note) ("d" . 'gnosis-dashboard))) @@ -780,13 +831,15 @@ (use-package org-gnosis :vc t :load-path "~/Dev/emacs-lisp/org-gnosis" + :ensure t :init (define-prefix-command 'thanos/notes-map) (define-prefix-command 'thanos/journal-map) :config (setf org-gnosis-dir "~/Notes" - org-gnosis-journal-template - "* Daily Notes\n\n* Goals\n+ [] Πρωινὴ Προσευχή\n+ [] Ἑσπερινή Προσευχή\n\n* Extras" + org-gnosis-journal-templates + '(("Default" + "* Daily Notes\n\n* Goals\n+ [] Πρωινὴ Προσευχή\n+ [] Ἑσπερινή Προσευχή\n\n* Extras")) org-gnosis-show-tags t) (defun thanos/org-open-at-point () @@ -929,7 +982,7 @@ rss.xml" anna piracy) :stream t :key (password-store-get "claude/api1")) - :bind (("C-c g" . 'gptel-send) + :bind (("C-c G" . 'gptel-send) :map gptel-mode-map ("C-c h" . 'gptel-menu))) |