summaryrefslogtreecommitdiffhomepage
path: root/attic/elisp
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-09-26 04:25:34 +0100
committerjao <jao@gnu.org>2022-09-26 04:25:34 +0100
commit46e40d80f1168755c13781a2df74c0a5b65a2a08 (patch)
treeea3a24a29bd40d5270a4dc2551c1ded5e7bf9d12 /attic/elisp
parentd8fe62a92149fe6348fa8fae8a9066475b5292e6 (diff)
downloadelibs-46e40d80f1168755c13781a2df74c0a5b65a2a08.tar.gz
elibs-46e40d80f1168755c13781a2df74c0a5b65a2a08.tar.bz2
trying consult completion in region for a while
Diffstat (limited to 'attic/elisp')
-rw-r--r--attic/elisp/misc.el138
1 files changed, 137 insertions, 1 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)