分享27.1自带的tab-line-mode配置

我是win10环境gccemacs,今天发现C-X 3开两个窗口,打开不同的文件,然后调用helm ocurr的窗口会发现helm弹出有一定的延迟,C-x 1只保留一个窗口helm弹出就很快没问题,用了profiler-start,profiler-stop,profiler-report发现耗时的是C语言实现redisplay_internal里,然后上本论坛搜索发现https://emacs-china.org/t/company-posframe-company-box/12720?u=lynnux 这里关闭doom-modeline是真的有效果,但关了doom-modeline还是不够快,然后试了各种minor mode,发现tabbar-ruler也会导致,去掉就没问题了。doom-modeline我直接删除掉了,但tabbar不用不行,需要找到替代品。试了 awesome-tab和centaur-tabs,还有sort-tab都达不到想的效果。 我想要的效果是:不分组,然后第1个tab就是当前的buffer,tab-bar-mode和tab-line-mode都试了,tab-bar是不管你开几个窗口,只有一个,而tab-line就可以每个buffer都有个tab,稍微定制下了,没想到竟然很容易达到之前用的tabbar-ruler的效果了,代码如下,主要特点:tab的buffer不分组,自己写了filter过滤不想要的buffer,然后buffer的顺序是(buffer-list)的顺序,也就是最近使用的buffer的最靠前。

;; from tabbar-ruler
(defcustom EmacsPortable-included-buffers '("*scratch*")
  "* Included buffers in tabbar."
  :type '(repeat (string :tag "Buffer Name"))
  :group 'EmacsPortable)
(defcustom EmacsPortable-excluded-buffers '("*Messages*" "*Completions*" "*ESS*")
  "* Excluded buffers in tabbar."
  :type '(repeat (string :tag "Buffer Name"))
  :group 'EmacsPortable)
(setq EmacsPortable-excluded-buffers '("*Messages*" "*Completions*" "*ESS*" "*Compile-Log*" "*Ibuffer*" "*SPEEDBAR*" "*etags tmp*" "*reg group-leader*" "*Pymacs*" "*grep*"))
(setq EmacsPortable-included-buffers '("*scratch*" "*shell*"))
(defun ep-tabbar-buffer-list ()
  "Return the list of buffers to show in tabs.
Exclude buffers whose name starts with a space or *, when they are not
visiting a file.  The current buffer is always included."
  (delq nil
        (mapcar #'(lambda (b)
                    (cond
                     ;; Always include the current buffer.
                     ((eq (current-buffer) b) b)
		   ((string-match "^TAGS\\(<[0-9]+>\\)?$" (format "%s" (buffer-name b))) nil)
                     ;; ((string= "TAGS" (format "%s" (buffer-name b))) nil)
                     ((buffer-file-name b) b)
		   ((member (buffer-name b) EmacsPortable-included-buffers) b)
		   ((member (buffer-name b) EmacsPortable-excluded-buffers) nil)
                     ((char-equal ?\  (aref (buffer-name b) 0)) nil)
                     ((char-equal ?* (aref (buffer-name b) 0)) nil)
                     ((buffer-live-p b) b)))
                (buffer-list))))
    (when (functionp 'global-tab-line-mode)
      (use-package tab-line
        :defer 0.5
        :init
        (setq tab-line-tabs-function 'ep-tabbar-buffer-list)
        :config
        (global-tab-line-mode 1)  
        )
2 个赞