diff options
-rw-r--r-- | attic/elisp/misc.el | 138 | ||||
-rw-r--r-- | custom/jao-custom-completion.el | 129 |
2 files changed, 150 insertions, 117 deletions
diff --git a/attic/elisp/misc.el b/attic/elisp/misc.el index 2565637..3e31fc0 100644 --- a/attic/elisp/misc.el +++ b/attic/elisp/misc.el @@ -1,4 +1,4 @@ -;;; -*- lexical-binding: t; -*- +;; -*- lexical-binding: t; -*- ;;; ace window (use-package ace-window @@ -319,6 +319,116 @@ (interactive) (jao-notify "Volume" (format "%s%%" (jao-player-volume)))) +;;; corfu +(use-package corfu + :ensure t + :init (setq corfu-echo-documentation 0.25 + corfu-cycle t + corfu-count 15 + corfu-quit-no-match t + corfu-auto t + corfu-commit-predicate nil + corfu-preview-current nil + corfu-preselect-first t + corfu-min-width 20 + corfu-max-width 100) + :config + + ;; show eldoc string immediately after accepted completion too + (with-eval-after-load "eldoc" + (eldoc-add-command-completions "corfu-")) + + (defun jao-corfu-no-auto () (setq-local corfu-auto nil) (corfu-mode)) + + (add-hook 'eshell-mode-hook #'jao-corfu-no-auto) + + (defun jao-corfu--active-p () + (and (>= corfu--index 0) (/= corfu--index corfu--preselect))) + + (defun jao-corfu-quit-or-insert () + (interactive) + (if (jao-corfu--active-p) (corfu-insert) (corfu-quit))) + + (defun jao-corfu-quit-or-previous () + (interactive) + (if (jao-corfu--active-p) + (corfu-previous) + (corfu-quit) + (previous-line))) + + :bind (:map corfu-map + ("C-<return>" . corfu-insert) + ("\r" . jao-corfu-quit-or-insert) + ("C-p" . jao-corfu-quit-or-previous))) + +(defun corfu-in-minibuffer () + (when (not (bound-and-true-p vertico--input)) + (setq-local corfu-echo-documentation nil) + (corfu-mode 1))) + +(defun jao-corfu-maybe-enable () + (when (and (not jao-wayland-enabled) (display-graphic-p)) + (add-hook 'minibuffer-setup-hook #'corfu-in-minibuffer 1) + (global-corfu-mode 1))) + +(add-hook 'after-init-hook #'jao-corfu-maybe-enable) + +;;; company +(use-package company + :ensure t + :custom ((company-backends '(company-capf + ;; company-bbdb + company-files + company-dabbrev + company-keywords)) + (company-global-modes '(not slack-message-buffer-mode + circe-channel-mode + telega-chat-mode)) + (company-format-margin-function nil) ;; #'company-text-icons-margin + (company-idle-delay 0.2) + (company-lighter "") + (company-lighter-base "") + (company-show-numbers nil) + (company-selection-wrap-around t) + (company-tooltip-limit 15) + (company-tooltip-align-annotations t) + (company-tooltip-offset-display 'lines)) ;; 'scrollbar + + :config + (defun jao-complete-at-point () + "Complete using company unless we're in the minibuffer." + (interactive) + (if (or (not company-mode) (window-minibuffer-p)) + (completion-at-point) + (company-manual-begin))) + + (defun jao-company-use-in-tab () + (global-set-key [remap completion-at-point] #'jao-complete-at-point) + (global-set-key [remap completion-symbol] #'jao-complete-at-point) + (global-set-key (kbd "M-TAB") #'jao-complete-at-point)) + + (jao-company-use-in-tab) + + :bind (:map company-active-map + + ("<tab>" . company-complete-common-or-cycle) + ("TAB" . company-complete-common-or-cycle) + + ("C-h" . company-show-doc-buffer) + ("M-." . company-show-location) + ("C-<return>" . company-complete-selection) + ([remap return] . company-abort) + ("RET" . company-abort) + + :filter (or (not (derived-mode-p 'eshell-mode)) + (company-explicit-action-p)) + ("<return>" . company-complete-selection) + ("RET" . company-complete-selection)) + :diminish) + +(unless (display-graphic-p) (global-company-mode 1)) + + ;;; pdf-tools (use-package pdf-tools :ensure t @@ -343,6 +453,32 @@ ("k" . pdf-view-previous-line-or-previous-page) ("K" . pdf-view-scroll-down-or-previous-page)))) +;;; eldoc for magit status/log buffers +(defun jao-magit-eldoc-for-commit (_callback) + (when-let ((commit (magit-commit-at-point))) + (with-temp-buffer + (magit-git-insert "show" + "--format=format:%an <%ae>, %ar" + (format "--stat=%d" (window-width)) + commit) + (goto-char (point-min)) + (put-text-property (point-min) (line-end-position) 'face 'bold) + (buffer-string)))) + +(defun jao-magit-eldoc-setup () + (add-hook 'eldoc-documentation-functions + #'jao-magit-eldoc-for-commit nil t) + (eldoc-mode 1)) + +(add-hook 'magit-log-mode-hook #'jao-magit-eldoc-setup) +(add-hook 'magit-status-mode-hook #'jao-magit-eldoc-setup) + +(with-eval-after-load "eldoc" + (eldoc-add-command 'magit-next-line) + (eldoc-add-command 'magit-previous-line) + (eldoc-add-command 'magit-section-forward) + (eldoc-add-command 'magit-section-backward)) + ;;; outline mode for notmuch tree view (defun jao-notmuch-tree--msg-prefix (msg) diff --git a/custom/jao-custom-completion.el b/custom/jao-custom-completion.el index 8e8e7fc..0f8b854 100644 --- a/custom/jao-custom-completion.el +++ b/custom/jao-custom-completion.el @@ -34,6 +34,7 @@ (defun jao-completion--crm-indicator (args) "Add prompt indicator to `completing-read-multiple' filter ARGS." (cons (concat "[CRM] " (car args)) (cdr args))) + (advice-add #'completing-read-multiple :filter-args #'jao-completion--crm-indicator) @@ -49,14 +50,13 @@ orderless-regexp))) (defun jao-orderless--set-locally () - (setq-local completion-styles - '(substring partial-completion orderless) - + (setq-local completion-styles '(orderless basic) completion-category-overrides '((file (styles partial-completion orderless)) (command (styles orderless+initialism))) orderless-matching-styles '(orderless-literal orderless-regexp orderless-prefixes))) + (add-hook 'minibuffer-setup-hook #'jao-orderless--set-locally)) ;;; marginalia @@ -73,112 +73,6 @@ (marginalia-mode 1) -;;; corfu -(use-package corfu - :ensure t - :init (setq corfu-echo-documentation 0.25 - corfu-cycle t - corfu-count 15 - corfu-quit-no-match t - corfu-auto t - corfu-commit-predicate nil - corfu-preview-current nil - corfu-preselect-first t - corfu-min-width 20 - corfu-max-width 100) - :config - - ;; show eldoc string immediately after accepted completion too - (with-eval-after-load "eldoc" - (eldoc-add-command-completions "corfu-")) - - (defun jao-corfu-no-auto () (setq-local corfu-auto nil) (corfu-mode)) - - (add-hook 'eshell-mode-hook #'jao-corfu-no-auto) - - (defun jao-corfu--active-p () - (and (>= corfu--index 0) (/= corfu--index corfu--preselect))) - - (defun jao-corfu-quit-or-insert () - (interactive) - (if (jao-corfu--active-p) (corfu-insert) (corfu-quit))) - - (defun jao-corfu-quit-or-previous () - (interactive) - (if (jao-corfu--active-p) - (corfu-previous) - (corfu-quit) - (previous-line))) - - :bind (:map corfu-map - ("C-<return>" . corfu-insert) - ("\r" . jao-corfu-quit-or-insert) - ("C-p" . jao-corfu-quit-or-previous))) - -(defun corfu-in-minibuffer () - (when (not (bound-and-true-p vertico--input)) - (setq-local corfu-echo-documentation nil) - (corfu-mode 1))) - -(when (display-graphic-p) - (add-hook 'minibuffer-setup-hook #'corfu-in-minibuffer 1) - (global-corfu-mode 1)) - -;;; company -(use-package company - :ensure t - :custom ((company-backends '(company-capf - ;; company-bbdb - company-files - company-dabbrev - company-keywords)) - (company-global-modes '(not slack-message-buffer-mode - circe-channel-mode - telega-chat-mode)) - (company-format-margin-function nil) ;; #'company-text-icons-margin - (company-idle-delay 0.2) - (company-lighter "") - (company-lighter-base "") - (company-show-numbers nil) - (company-selection-wrap-around t) - (company-tooltip-limit 15) - (company-tooltip-align-annotations t) - (company-tooltip-offset-display 'lines)) ;; 'scrollbar - - :config - (defun jao-complete-at-point () - "Complete using company unless we're in the minibuffer." - (interactive) - (if (or (not company-mode) (window-minibuffer-p)) - (completion-at-point) - (company-manual-begin))) - - (defun jao-company-use-in-tab () - (global-set-key [remap completion-at-point] #'jao-complete-at-point) - (global-set-key [remap completion-symbol] #'jao-complete-at-point) - (global-set-key (kbd "M-TAB") #'jao-complete-at-point)) - - (jao-company-use-in-tab) - - :bind (:map company-active-map - - ("<tab>" . company-complete-common-or-cycle) - ("TAB" . company-complete-common-or-cycle) - - ("C-h" . company-show-doc-buffer) - ("M-." . company-show-location) - ("C-<return>" . company-complete-selection) - ([remap return] . company-abort) - ("RET" . company-abort) - - :filter (or (not (derived-mode-p 'eshell-mode)) - (company-explicit-action-p)) - ("<return>" . company-complete-selection) - ("RET" . company-complete-selection)) - :diminish) - -(unless (display-graphic-p) (global-company-mode 1)) - ;;; vertico (use-package vertico :ensure t @@ -190,13 +84,6 @@ :config - ;; (setq completion-in-region-function - ;; (lambda (&rest args) - ;; (apply (if (and (not window-system) vertico-mode) - ;; #'consult-completion-in-region - ;; #'completion--in-region) - ;; args))) - (defun jao-vertico--display-candidates (lines) (move-overlay vertico--candidates-ov (point-min) (point-min)) (overlay-put vertico--candidates-ov 'after-string (apply #'concat lines)) @@ -248,6 +135,16 @@ :config + (defun jao-consult--completion-in-region (&rest args) + (apply (if (and (not (bound-and-true-p corfu-mode)) + (not (bound-and-true-p company-mode)) + (bound-and-true-p vertico-mode)) + #'consult-completion-in-region + #'completion--in-region) + args)) + + (setq completion-in-region-function #'jao-consult--completion-in-region) + (defun jao-find-file (arg) (interactive "P") (call-interactively (if arg 'consult-file-externally 'find-file))) |