conf-tabbar.el 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. (provide 'conf-tabbar)
  2. ;(require 'tabbar-ruler)
  3. (setq tabbar-ruler-global-tabbar t) ; If you want tabbar
  4. ;;(setq tabbar-ruler-global-ruler t) ; if you want a global ruler
  5. ;;(setq tabbar-ruler-popup-menu t) ; If you want a popup menu.
  6. ;;(setq tabbar-ruler-popup-toolbar t) ; If you want a popup toolbar
  7. ;;(setq tabbar-ruler-popup-scrollbar t) ; If you want to only show the scroll bar when your mouse is moving.
  8. (custom-set-variables
  9. '(tabbar-mode t nil (tabbar))
  10. '(ide-skel-tabbar-mwheel-mode nil (tabbar))
  11. '(tabbar-scroll-left-button (quote (("") "")))
  12. '(tabbar-scroll-right-button (quote (("") "")))
  13. '(tabbar-button-highlight ((t (:inherit tabbar-button))))
  14. '(tabbar-highlight ((t nil)))
  15. )
  16. ;(setq tabbar-cycle-scope (quote tabs))
  17. ;(setq table-time-before-update 0.1)
  18. ;(setq tabbar-use-images t)
  19. ;; Add a buffer modification state indicator in the tab label, and place a
  20. ;; space around the label to make it looks less crowd.
  21. (defadvice tabbar-buffer-tab-label (after fixup_tab_label_space_and_flag activate)
  22. (setq ad-return-value
  23. (if (and (buffer-modified-p (tabbar-tab-value tab))
  24. (buffer-file-name (tabbar-tab-value tab)))
  25. (concat " + " (concat ad-return-value " "))
  26. (concat " " (concat ad-return-value " ")))))
  27. ;; Called each time the modification state of the buffer changed.
  28. (defun ztl-modification-state-change ()
  29. (tabbar-set-template tabbar-current-tabset nil)
  30. (tabbar-display-update))
  31. ;; First-change-hook is called BEFORE the change is made.
  32. (defun ztl-on-buffer-modification ()
  33. (set-buffer-modified-p t)
  34. (ztl-modification-state-change))
  35. (add-hook 'after-save-hook 'ztl-modification-state-change)
  36. ;; This doesn't work for revert, I don't know.
  37. ;;(add-hook 'after-revert-hook 'ztl-modification-state-change)
  38. (add-hook 'first-change-hook 'ztl-on-buffer-modification)
  39. (defun tabbar-buffer-groups ()
  40. "Return the list of group names the current buffer belongs to.
  41. Return a list of one element based on major mode."
  42. (list
  43. (cond
  44. ((or (get-buffer-process (current-buffer))
  45. ;; Check if the major mode derives from `comint-mode' or
  46. ;; `compilation-mode'.
  47. (tabbar-buffer-mode-derived-p
  48. major-mode '(comint-mode compilation-mode)))
  49. "Process"
  50. )
  51. ((member (buffer-name)
  52. '("*scratch*" "*Help*" "*Completions*"))
  53. "Common"
  54. )
  55. ;((string-equal "*" (substring (buffer-name) 0 1))
  56. ; "Common"
  57. ; )
  58. ((member (buffer-name)
  59. '("*Backtrace*" "*Compile-Log*" "*Messages*"))
  60. "Debugger"
  61. )
  62. ((member (buffer-name)
  63. '("xyz" "day" "m3" "abi" "for" "nws" "eng" "f_g" "tim" "tmp"))
  64. "Main"
  65. )
  66. ((memq major-mode '(python-mode php-mode emacs-lisp-mode sh-mode makefile-gmake-mode perl-mode c-mode c++-mode django-mode python-django))
  67. "Programming"
  68. )
  69. ((memq major-mode '(nxhtml-mode web-mode avascript-mode js-mode js2-mode javascript js2-refactor emmet-mode css-mode-hook css-mode))
  70. "Web"
  71. )
  72. ((eq major-mode 'dired-mode)
  73. "Dired"
  74. )
  75. ((memq major-mode
  76. '(help-mode apropos-mode Info-mode Man-mode))
  77. "Common"
  78. )
  79. ((memq major-mode
  80. '(rmail-mode
  81. rmail-edit-mode vm-summary-mode vm-mode mail-mode
  82. mh-letter-mode mh-show-mode mh-folder-mode
  83. gnus-summary-mode message-mode gnus-group-mode
  84. gnus-article-mode score-mode gnus-browse-killed-mode))
  85. "Mail"
  86. )
  87. (t
  88. ;; Return `mode-name' if not blank, `major-mode' otherwise.
  89. (if (and (stringp mode-name)
  90. ;; Take care of preserving the match-data because this
  91. ;; function is called when updating the header line.
  92. (save-match-data (string-match "[^ ]" mode-name)))
  93. mode-name
  94. (symbol-name major-mode))
  95. ))))
  96. ;; tabbar grouping method
  97. (defun tabbar-buffer-groups-by-dir ()
  98. "Put all files in the same directory into the same tab bar"
  99. (with-current-buffer (current-buffer)
  100. (let ((dir (expand-file-name default-directory)))
  101. (cond ;; assign group name until one clause succeeds, so the order is important
  102. ((eq major-mode 'dired-mode)
  103. (list "Dired"))
  104. ((memq major-mode
  105. '(help-mode apropos-mode Info-mode Man-mode))
  106. (list "Help"))
  107. ((string-match-p "\*.*\*" (buffer-name))
  108. (list "Misc"))
  109. (t (list dir))))))
  110. ;; Show ALL Tabs
  111. (setq tbbr-md "all")
  112. (defun toggle-tabbar-mode ()
  113. "Toggles tabbar modes - all buffers vs. defined in the `tabbar-buffer-groups'."
  114. (interactive)
  115. (if (string= tbbr-md "groups")
  116. (progn ;; then
  117. (setq tabbar-buffer-groups-function
  118. (lambda ()
  119. (list "All")))
  120. (setq tbbr-md "all"))
  121. (progn ;; else
  122. (setq tabbar-buffer-groups-function 'tabbar-buffer-groups)
  123. (setq tbbr-md "groups"))))
  124. ;(defun tabbar-switch-to-default-grouping ()
  125. ; (interactive)
  126. ; (setq tabbar-buffer-groups-function 'tabbar-buffer-groups))
  127. (defun tabbar-switch-to-grouping-by-dir ()
  128. (interactive)
  129. (setq tabbar-buffer-groups-function 'tabbar-buffer-groups-by-dir))
  130. (defun switch-tabbar (num)
  131. (let* ((tabs (tabbar-tabs
  132. (tabbar-current-tabset)
  133. ;; (tabbar-get-tabset "All Buffers")
  134. ))
  135. (tab (nth
  136. (if (> num 0) (- num 1) (+ (length tabs) num))
  137. tabs)))
  138. (if tab (switch-to-buffer (car tab)))))
  139. ;; Shortcuts
  140. (global-set-key (kbd "C-1") (lambda () (interactive) (switch-tabbar 1)))
  141. (global-set-key (kbd "C-2") (lambda () (interactive) (switch-tabbar 2)))
  142. (global-set-key (kbd "C-3") (lambda () (interactive) (switch-tabbar 3)))
  143. (global-set-key (kbd "C-4") (lambda () (interactive) (switch-tabbar 4)))
  144. (global-set-key (kbd "C-5") (lambda () (interactive) (switch-tabbar 5)))
  145. (global-set-key (kbd "C-6") (lambda () (interactive) (switch-tabbar 6)))
  146. (global-set-key (kbd "C-7") (lambda () (interactive) (switch-tabbar 7)))
  147. (global-set-key (kbd "C-8") (lambda () (interactive) (switch-tabbar 8)))
  148. (global-set-key (kbd "C-9") (lambda () (interactive) (switch-tabbar 9)))
  149. (global-set-key (kbd "C-0") (lambda () (interactive) (switch-tabbar -1)))
  150. (global-set-key (kbd "C-x <up>") 'tabbar-forward-tab)
  151. (global-set-key (kbd "C-x <down>") 'tabbar-backward-tab)
  152. (global-set-key (kbd "C-x <right>") 'tabbar-forward-group)
  153. (global-set-key (kbd "C-x <left>") 'tabbar-backward-group)
  154. (global-set-key (kbd "C-M-g") 'toggle-tabbar-mode)
  155. (global-set-key (kbd "M-g") 'tabbar-switch-to-grouping-by-dir)
  156. ;(global-set-key (kbd "C-M-g") 'tabbar-switch-to-default-grouping)
  157. (global-set-key (kbd "C-c C-t") 'tabbar-ruler-move)
  158. ;; Apariencia
  159. (setq tabbar-separator '(0.0))
  160. (setq tabbar-background-color "#001214") ;; the color of the tabbar background
  161. (set-face-attribute 'tabbar-default nil :background "black")
  162. (set-face-attribute 'tabbar-unselected nil :background "black" :foreground "white" :box '(:line-width 1 :color "cyan" ))
  163. (set-face-attribute 'tabbar-selected nil :background "cyan" :foreground "black" :box '(:line-width 1 :color "cyan" ))
  164. (set-face-attribute 'tabbar-button nil :box '(:line-width 1 :color "black" :style released-button));
  165. (set-face-attribute 'tabbar-highlight nil :underline nil)
  166. (set-face-attribute 'tabbar-separator nil :height 0.5)