我可以自定义 Emacs 缓冲区菜单的格式吗?

我可以自定义 Emacs 缓冲区菜单的格式吗?

Emacs 缓冲区菜单显示两列:一列显示缓冲区名称,一列显示文件名和完整路径。我们项目中的路径可能很长,跨越多个屏幕。所以我不想在缓冲区菜单中显示它们。我该如何实现呢?额外方法:使用路径的工具提示。

答案1

由于 Emacs 附带源代码,我擅自调整了鼠标缓冲区菜单。我将其放入我的程序中init.el以覆盖创建 的默认实现mouse-buffer-menu-alist。这个程序取消了文件名,只显示缓冲区名称。对于我的需求来说,这已经足够了:

(defun mouse-buffer-menu-alist (buffers)
  (let (tail
    (maxlen 0)
    head)
    (setq buffers
      (sort buffers
        (function (lambda (elt1 elt2)
                (string< (buffer-name elt1) (buffer-name elt2))))))
    (setq tail buffers)
    (while tail
      (or (eq ?\s (aref (buffer-name (car tail)) 0))
      (setq maxlen
        (max maxlen
             (length (buffer-name (car tail))))))
      (setq tail (cdr tail)))
    (setq tail buffers)
    (while tail
      (let ((elt (car tail)))
    (if (/= (aref (buffer-name elt) 0) ?\s)
        (setq head
          (cons
           (cons
            (format
             (format "%%-%ds  %%s%%s" maxlen)
             (buffer-name elt)
             (if (buffer-modified-p elt) "*" " ")
             (with-current-buffer elt
               (if buffer-read-only "%" " "))
                     )
            elt)
           head))))
      (setq tail (cdr tail)))
    ;; Compensate for the reversal that the above loop does.
    (nreverse head)))

相关内容