Tabbar 2.0 - 自定义功能切换到特定选项卡组

时间:2013-07-29 01:52:49

标签: emacs

有没有人有任何想法,关于如何使用Tabbar 2.0和当前版本的Emacs指定(within a function)切换到特定标签组?例如,If the sky is blue, then switch to tab group "BLUE"(和/或该特定标签组中最近查看的标签/缓冲区)。

我编写了一些函数,允许我按帧组织选项卡组,使选项卡看起来与给定的帧相关联。但是,我的函数使用tabbar-forward-group循环遍历各个选项卡组,直到函数最终停在正确的组中 - 此方法非常慢。

函数tabbar-current-tabset用于确定具有焦点的当前选项卡组的名称。将其放在消息中时可以看到结果 - 例如(message "%s" tabbar-current-tabset)。它也可以在诸如的功能中使用。 。 。 (if (not (equal (format "%s" tabbar-current-tabset) "common"))。 。 。 (tabbar-forward-group)

我发现只有一个工作函数允许选择一个特定的标签组,称为ido-jump-to-tab-group(如下所述):https://github.com/bamanzi/dotemacs-full/blob/master/init.d/25-tabbar.el我正在寻找一种方法来选择特定标签组(硬编码到函数中),无需暂停以使用ido . . .手动选择它。我之所以提到这一点,是因为它可以帮助某人解决:If the sky is blue, then switch to tab group "BLUE"(和/或该特定标签组中最近查看的标签/缓冲区)。

(defun ido-jump-to-tab-group ()
  "Jump to a tabbar group."
  (interactive)
  (if (< emacs-major-version 24)
      (ido-common-initialization))
  (unless (and (featurep 'tabbar)
               tabbar-mode)
    (error "Error: tabbar-mode not turned on."))
  (set tabbar-tabsets-tabset (tabbar-map-tabsets 'tabbar-selected-tab)) ;; refresh groups
  (let* ( (groups (mapcar #'(lambda (group)
                              (format "%s" (cdr group)))
                          (tabbar-tabs tabbar-tabsets-tabset)))
          (group-name (ido-completing-read "Groups: " groups)) )
    (mapc #'(lambda (group)
              (when (string= group-name (format "%s" (cdr group)))
                  (message "Switch to group '%s', current buffer: %s" (cdr group) (car group))
                  (switch-to-buffer (car group)) ))
          (tabbar-tabs tabbar-tabsets-tabset))) )

在我的Google搜索过程中,我遇到了一个明显损坏的功能,它不能与Tabbar 2.0和当前版本的Emacs Trunk一起使用 - 它被称为tabbar+switch-grouphttps://gist.github.com/Johniel/4324127我提到这个功能是因为它是与此问题相关的唯一一个(ido-jump-to-tab-group除外)。

1 个答案:

答案 0 :(得分:2)

(defun goto-tab-group (group-name)
  "Jump to a specific tabbar group."
  (unless (and (featurep 'tabbar)
               tabbar-mode)
    (error "Error: tabbar-mode not turned on."))
  (set tabbar-tabsets-tabset (tabbar-map-tabsets 'tabbar-selected-tab)) ;; refresh groups
  (let* ( (groups (mapcar #'(lambda (group)
                              (format "%s" (cdr group)))
                          (tabbar-tabs tabbar-tabsets-tabset))))
    (mapc #'(lambda (group)
              (when (string= group-name (format "%s" (cdr group)))
                  (message "Switch to group '%s', current buffer: %s" (cdr group) (car group))
                  (switch-to-buffer (car group)) ))
          (tabbar-tabs tabbar-tabsets-tabset))) )

(defun example-using-goto-tab-group ()
(interactive)
(goto-tab-group "BLUE")) ;; predefined existing tab group

编辑(2014年9月27日):函数ido-jump-to-tab-group(在上面的问题中)和函数goto-tab-group(在上面的答案中)不兼容自定义tabbar-buffer-groups-function,根据与特定帧关联的缓冲区对选项卡进行分组,其中特殊列表嵌入在frame-parameter中(独立于常规buffer-list和常规buried-buffer-list)。以下功能可以解决这种不兼容问题。

  
(defun ido-switch-tab-group ()
  "Switch tab groups using ido."
(interactive)
  (let* (
      (tab-buffer-list (mapcar
          #'(lambda (b)
              (with-current-buffer b
                (list (current-buffer)
                      (buffer-name)
                      (funcall tabbar-buffer-groups-function) )))
               (funcall tabbar-buffer-list-function)))
      (groups (delete-dups
        (mapcar #'(lambda (group)
          (car (car (cdr (cdr group))))) tab-buffer-list)))
      (group-name (ido-completing-read "Groups: " groups)) )
    (catch 'done
      (mapc
        #'(lambda (group)
          (when (equal group-name (car (car (cdr (cdr group)))))
            (throw 'done (switch-to-buffer (car (cdr group))))))
        tab-buffer-list) )))

(defun switch-tab-group (group-name)
  "Switch to a specific tab group."
  (let ((tab-buffer-list (mapcar
          #'(lambda (b)
              (with-current-buffer b
                (list (current-buffer)
                      (buffer-name)
                      (funcall tabbar-buffer-groups-function) )))
               (funcall tabbar-buffer-list-function))))
    (catch 'done
      (mapc
        #'(lambda (group)
          (when (equal group-name (format "%s" (car (car (cdr (cdr group))))))
            (throw 'done (switch-to-buffer (car (cdr group))))))
        tab-buffer-list) )))

(defun switch-to-tab-group-n ()
"Switch to a predefined existing tab group named `N`."
(interactive)
  (switch-tab-group "N"))

(defun switch-to-tab-group-a ()
"Switch to a predefined existing tab group named `A`."
(interactive)
  (switch-tab-group "A"))