1

请问有人对如何within a function使用 Tabbar 2.0 和当前版本的 Emacs 指定 () 切换到特定选项卡组有任何想法吗?例如,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与此问题相关的唯一一个(除了)。

4

1 回答 1

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基于与特定帧关联的缓冲区对选项卡进行分组的自定义不兼容,该特殊列表嵌入在框架参数(独立于 generalbuffer-list和 general 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"))
于 2013-07-29T14:48:27.613 回答