开发者

Emacs: How to toggle Buffer-menu-files-only by default

开发者 https://www.devze.com 2023-01-20 16:18 出处:网络
In buff-menu+.el (and also in buff-menu.el) there is a function called Buffer-menu-toggle-files-only which sets the variable Buffer-menu-files-only to t/nil.

In buff-menu+.el (and also in buff-menu.el) there is a function called Buffer-menu-toggle-files-only which sets the variable Buffer-menu-files-only to t/nil.

When showing the buffer list, I can toggle this with the key T so I can prevent non-file-buffers from being shown in the list. I would like to have this filter (files-only) set by default. How could I implement this in my init.el file?

I tried:

(ad开发者_如何学JAVAd-hook 'buffer-menu-mode-hook 'Buffer-menu-toggle-files-only 1)

but when I then show the buffer list, it says:

run-hooks: Wrong number of arguments: #[(arg) "..." [arg Buffer-menu-files-only prefix-numeric-value 0 t revert-buffer] 2 578818 "P"], 0

Can anybody give me a hint?


Try this:

(add-hook 'buffer-menu-mode-hook
          '(lambda ()
             (Buffer-menu-toggle-files-only 1)))

I don't use buffer-menu, so this is untested. But this is the form all my mode-hooks follow, and they all work.


The mode hook suggestion should work fine.

Another way to go is this:

    (defun my-list-buffers ()
      (interactive)
      (list-buffers t))

Also, I assume you already know that C-u C-x C-b lists only file buffers.


This works and makes exactly what you need.

(global-set-key (kbd "C-x C-b") 'my-buffer-menu)
(defun my-buffer-menu()
   (interactive)
   (buffer-menu)
   (Buffer-menu-toggle-files-only 1))
0

精彩评论

暂无评论...
验证码 换一张
取 消