如何过滤缓冲区列表以仅显示在Windows中不可见的缓冲区

时间:2014-02-28 22:01:09

标签: elisp

我希望这个函数不返回在windows中可见的缓冲区。

即。我想从结果中消除当前帧中挂出的任何缓冲区。

我知道函数'window-list'返回windows中可见的缓冲区,但我不知道如何使window-list成为-filter函数的谓词。

(defun projectile-project-buffers-non-visible ()
  "Get a list of non visible project buffers."
  (let ((project-root (projectile-project-root)))
    (-filter (lambda (buffer)
               (projectile-project-buffer-p buffer project-root))
(buffer-list))))

2 个答案:

答案 0 :(得分:1)

这个怎么样?对于每个缓冲区,查看它是否由窗口显示。如果没有,请将其退回。

(defun not-visible-buffers (buffers)
  "given a list of buffers, return buffers which are not currently visible"
  (remove nil
        (mapcar
         '(lambda (buf)
        (unless (get-buffer-window-list buf) buf))
         buffers)
        ))

您可以按如下方式调用它:

(not-visible-buffers (buffer-list))

答案 1 :(得分:0)

看起来这样可行,但如果有人有更优雅的解决方案,我会保持开放状态。

  (defun projectile-project-buffers-non-visible ()
    "Get a list of non visible project buffers."
    (let ((project-root (projectile-project-root)))
      (-filter (lambda (buffer)
                 (and
                  (projectile-project-buffer-p buffer project-root)
                  (not (get-buffer-window buffer 'visible))))
               (buffer-list)
               )))