Skip to content

Instantly share code, notes, and snippets.

@Johniel
Created April 7, 2012 09:03
Show Gist options
  • Save Johniel/2326697 to your computer and use it in GitHub Desktop.
Save Johniel/2326697 to your computer and use it in GitHub Desktop.
;; move tab position
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun tabbar-insert (tabs ctab nth)
(append (nthcar nth tabs)
(list ctab)
(nthcdr nth tabs)))
(defun tabbar-find-remove (ctabs ctab)
(let ((index 0)
(head '())
(rest ctabs))
(while (not (eq ctab (car rest)))
(incf index)
(setq head (append head (list (car rest))))
(setq rest (cdr rest)))
(list index (append head (cdr rest)))))
(defun tabbar-move-tab (&optional with-right?)
(let* ((ctabset (tabbar-current-tabset 't))
(ctabs (tabbar-tabs ctabset))
(ctab (tabbar-selected-tab ctabset)))
(if (and ctabset ctabs ctab)
(progn
(let* ((index-tabs (tabbar-find-remove ctabs ctab))
(index (first index-tabs))
(l (length ctabs)))
(setq index (if with-right?
(% (+ index 1) l)
(% (+ (- index 1) l) l)))
(set ctabset (tabbar-insert (second index-tabs) ctab index))
(put ctabset 'template nil)
(tabbar-display-update))))))
(defun tabbar-move-right ()
(interactive)
(tabbar-move-tab t))
(defun tabbar-move-left ()
(interactive)
(tabbar-move-tab))
(global-set-key [\C-home] 'tabbar-move-left)
(global-set-key [\C-end] 'tabbar-move-right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment