Create a gist now

Instantly share code, notes, and snippets.

(require 'evil)
(setq elscreen-tab-display-control nil
elscreen-tab-display-kill-screen nil)
(require 'elscreen)
(evil-define-command evil-tab-new ()
:repeat nil
(setq count (or count 1))
(when (null (elscreen-get-frame-confs (selected-frame)))
(elscreen-start))
(elscreen-create))
(evil-define-command evil-tab-edit (file)
:repeat nil
(interactive "<f>")
(evil-tab-new)
(evil-edit file))
(evil-define-command evil-tab-find-file-at-point (&optional count)
:repeat nil
(let ((buffer (current-buffer)))
(evil-tab-new)
(switch-to-buffer buffer))
(find-file-at-point))
(evil-define-command evil-tab-find-file-at-point-with-line (&optional count)
:repeat nil
(let ((buffer (current-buffer)))
(evil-tab-new)
(switch-to-buffer buffer))
(evil-find-file-at-point-with-line))
(evil-define-command evil-tab-close (&optional count)
:repeat nil
(interactive "P")
(let ((buffer (current-buffer)))
(elscreen-kill count)
(switch-to-buffer buffer)))
(evil-define-command evil-tab-only (&optional bang)
:repeat nil
(interactive "P")
(let ((buffer (current-buffer)))
(elscreen-kill-others count)
(switch-to-buffer buffer)))
(evil-define-command evil-tab-next (&optional count)
:repeat nil
(interactive "P")
(if count
(elscreen-goto count)
(elscreen-next)))
(evil-define-command evil-tab-previous (&optional count)
:repeat nil
(interactive "P")
(if count
(let* ((screens (length (elscreen-get-screen-list)))
(screen (- screens count 1)))
(when (>= screen 0)
(elscreen-goto screen)))
(elscreen-previous)))
(evil-define-command evil-tab-first ()
:repeat nil
(elscreen-goto 0))
(evil-define-command evil-tab-last ()
:repeat nil
(elscreen-goto (1- (length (elscreen-get-screen-list)))))
(defadvice evil-quit (around tabclose-or-quit activate)
(if (> (length (elscreen-get-screen-list)) 1)
(condition-case nil
(delete-window)
(error (evil-tab-close)))
ad-do-it))
(evil-ex-define-cmd "tabnew" #'evil-tab-new)
(evil-ex-define-cmd "tabe[dit]" #'evil-tab-edit)
(evil-ex-define-cmd "tabc[lose]" #'evil-tab-close)
(evil-ex-define-cmd "tabo[nly]" #'evil-tab-only)
(evil-ex-define-cmd "tabn[ext]" #'evil-tab-next)
(evil-ex-define-cmd "tabp[revious]" #'evil-tab-previous)
(evil-ex-define-cmd "tabN[ext]" #'evil-tab-previous)
(evil-ex-define-cmd "tabfir[st]" #'evil-tab-first)
(evil-ex-define-cmd "tabl[ast]" #'evil-tab-last)
(evil-ex-define-cmd "tabs" #'elscreen-display-screen-name-list)
(define-key evil-motion-state-map (kbd "gt") #'evil-tab-next)
(define-key evil-motion-state-map (kbd "gT") #'evil-tab-previous)
(define-key evil-window-map (kbd "gf") #'evil-tab-find-file-at-point)
(define-key evil-window-map (kbd "gF") #'evil-tab-find-file-at-point-with-line)
(provide 'evil-tab-page)
;;; evil-tab-page.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment