Skip to content

Commit

Permalink
feat(corfu): add variables to control smart tab
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonBreezes committed Mar 13, 2024
1 parent 4719505 commit 4a12dd5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
12 changes: 12 additions & 0 deletions modules/completion/corfu/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ Possible values are:
and immediatelly exit if in the minibuffer;
- nil: Pass-through without inserting.")

(defvar +corfu-want-tab-prefer-expand-snippets t
"If non-nil, prefer expanding snippets over selecting completions with
TAB.")

(defvar +corfu-want-tab-prefer-navigating-snippets t
"If non-nil, prefer navigating active snippets over selecting
completions with TAB/<backtab>.")

(defvar +corfu-want-tab-prefer-navigating-org-tables nil
"If non-nil, prefer navigating org tables over selecting completions with
TAB/<backtab>.")

;;
;;; Packages
(use-package! corfu
Expand Down
3 changes: 0 additions & 3 deletions modules/config/default/+evil-bindings.el
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@
#'evil-jump-item)
;; Extend smart tab for specific modes. This way, we process the entire
;; smart tab logic and only fall back to these commands at the end.
(:when (modulep! :completion corfu)
(:after corfu :map corfu-map
[remap indent-for-tab-command] #'corfu-next))
(:when (modulep! :lang org)
(:after org :map org-mode-map
[remap indent-for-tab-command]
Expand Down
24 changes: 15 additions & 9 deletions modules/config/default/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -487,25 +487,31 @@ Continues comments if executed from a commented line. Consults
`(menu-item "Select next candidate or expand/traverse snippet" corfu-next
:filter ,(lambda (cmd)
(cond ((and (modulep! :editor snippets)
+corfu-want-tab-prefer-navigating-snippets
(+yas-active-p))
#'yas-next-field-or-maybe-expand)
((and (modulep! :editor snippets)
+corfu-want-tab-prefer-expand-snippets
(yas-maybe-expand-abbrev-key-filter 'yas-expand))
#'yas-expand)
(t
cmd)))))
((and (modulep! :lang org)
+corfu-want-tab-prefer-navigating-org-tables
(org-at-table-p))
#'org-table-next-field)
(t cmd)))))
(cmds-s-tab
`(menu-item "Select previous candidate or expand/traverse snippet"
corfu-previous
:filter ,(lambda (cmd)
(cond ((and (modulep! :editor snippets)
+corfu-want-tab-prefer-navigating-snippets
(+yas-active-p))
#'yas-prev-field)
((and (modulep! :editor snippets)
(yas-maybe-expand-abbrev-key-filter 'yas-expand))
#'yas-expand)
(t
cmd))))))
((and (modulep! :lang org)
+corfu-want-tab-prefer-navigating-org-tables
(org-at-table-p))
#'org-table-previous-field)
(t cmd))))))
(map! :when (modulep! :completion corfu)
:map corfu-map
[backspace] cmds-del
Expand All @@ -514,8 +520,8 @@ Continues comments if executed from a commented line. Consults
:gi "RET" cmds-ret
"S-TAB" cmds-s-tab
[backtab] cmds-s-tab
"TAB" cmds-tab
[tab] cmds-tab))
:gi "TAB" cmds-tab
:gi [tab] cmds-tab))

;; Smarter C-a/C-e for both Emacs and Evil. C-a will jump to indentation.
;; Pressing it again will send you to the true bol. Same goes for C-e, except
Expand Down

0 comments on commit 4a12dd5

Please sign in to comment.