Skip to content

Instantly share code, notes, and snippets.

@ruliana
Created February 28, 2020 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruliana/196c87b97f69d6dd82ed59043840ce31 to your computer and use it in GitHub Desktop.
Save ruliana/196c87b97f69d6dd82ed59043840ce31 to your computer and use it in GitHub Desktop.
(defvar ronie/god-tab-mode-map (make-sparse-keymap))
(define-minor-mode ronie/god-tab-mode
"Make <tab> a 'god key' for editing code, according to the context and my preferences ;p"
:lighter " GT"
:keymap ronie/god-tab-mode-map
(if (bound-and-true-p ronie/god-tab-mode)
(message "Jumper mode activated!")
(message "Jumper mode deactivated!")))
(evil-define-key '(insert normal) ronie/god-tab-mode-map (kbd "<tab>") 'ronie/jump-forward)
(evil-define-key '(insert normal) ronie/god-tab-mode-map (kbd "S-<tab>") 'ronie/jump-backward)
(evil-define-key 'visual ronie/god-tab-mode-map (kbd "<tab>") 'ronie/indent-region)
(defun ronie/indent-region ()
"Indent the selected region"
(interactive)
(indent-region (region-beginning) (region-end)))
(defun ronie/jump-forward ()
"Jump out of nested parenthesis or after quotes and comas."
(interactive)
(cond ((and (bolp) (looking-at "[[:blank:]]*$"))
(indent-according-to-mode))
((and (bolp) (looking-at "[[:blank:]]+[^[:blank:]]"))
(indent-according-to-mode))
((and (looking-at "[[:blank:]]") (looking-back "[[:blank:]]+" (line-beginning-position)))
(indent-according-to-mode))
(t
(re-search-forward "['\",]\\|[][)(}{]+"))))
(defun ronie/jump-backward ()
"Jump out of nested parenthesis or before quotes and comas."
(interactive)
(re-search-backward "['\",]\\|[][)(}{]+"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment