From 589237ea50fb95ca67454bed03f20e0e175543fc Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Sat, 19 Feb 2022 20:43:21 +0000 Subject: [PATCH] feat(emacs): implement super tab This is a port of the original super tab I had in vim. It has a hierarchy of checks for actions when using the tab so I can use tab for snippet expanding, expanding emmet expressions. Currently this dose not support tab for cycling though completions, and I am sure there will be some bugs in some situations. --- .../core/files/emacs/src/development.el | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/site-modules/core/files/emacs/src/development.el b/site-modules/core/files/emacs/src/development.el index d4e90cc..28bdd00 100644 --- a/site-modules/core/files/emacs/src/development.el +++ b/site-modules/core/files/emacs/src/development.el @@ -32,11 +32,16 @@ (let ((yas/fallback-behavior 'return-nil)) (yas/expand))) -(defun aa/company-tab () - (interactive) - (if (or (not yas/minor-mode) - (null (do-yas-expand))) - (company-complete-common-or-cycle))) +(defun aa/expand () + (interactive) + (if (or (not yas/minor-mode) + (null (do-yas-expand))) + (if (string-empty-p (thing-at-point 'word 'no-properties)) + (indent-for-tab-command) + (if (fboundp 'emmet-expand-yas) + (emmet-expand-yas))))) + +(define-key evil-insert-state-map (kbd "C-e") 'aa/expand) (use-package company :after lsp-mode @@ -44,8 +49,8 @@ (:map company-active-map ("RET" . company-complete) ("C-l" . yas-next-field-or-maybe-expand) - ("" . aa/company-tab) - ("TAB" . aa/company-tab)) + ("" . aa/expand) + ("TAB" . aa/expand)) :config (setq company-idle-delay 0) (setq company-echo-delay 0) @@ -125,18 +130,12 @@ (use-package string-inflection :defer t) -(defun aa/global-tab () - (interactive) - (if (or (not yas/minor-mode) - (null (do-yas-expand))) - (indent-for-tab-command))) - (define-minor-mode aa-tab-mode - "Runs fmt on file save when this mode is turned on" + "Tab mode by me" :lighter " aa-tab" :global nil - (global-set-key (kbd "") 'aa/global-tab) - (global-set-key (kbd "TAB") 'aa/global-tab)) + (global-set-key (kbd "") 'aa/expand) + (global-set-key (kbd "TAB") 'aa/expand)) (define-globalized-minor-mode global-aa-tab-mode aa-tab-mode (lambda () (aa-tab-mode 1)))