emacs - 我如何计算 Emacs 中打开的缓冲区/文件的数量?

标签 emacs lisp

有时,我在 Emacs 中本想按 C-x 或 C-c 时不小心按了 C-x C-c。当然,这会在没有确认的情况下关闭所有打开的框架和缓冲区。我知道我可以让 Emacs 提示“你确定要退出吗?”,但我不想一直这样做,那样会很烦人。我只希望它在打开的文件(或缓冲区)超过 N 个时执行此操作。

所以我想按照以下方式将 C-x C-c 绑定(bind)到一个函数:

(if (< number of open buffers n)
    (save-buffers-kill-emacs)
    (are-you-sure))

但我不知道如何获取打开的缓冲区数(或打开的帧数,或打开的文件数等)。

最佳答案

这是我用的:

(defun count-buffers (&optional display-anyway)
  "Display or return the number of buffers."
  (interactive)
  (let ((buf-count (length (buffer-list))))
    (if (or (interactive-p) display-anyway)
    (message "%d buffers in this Emacs" buf-count)) buf-count))

我偷了它,但不记得从哪里偷来的。来自 John Sturdy ,听起来像个迷人的家伙;可从 his website 获得.

关于emacs - 我如何计算 Emacs 中打开的缓冲区/文件的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/350526/

相关文章:

plot - 如何使用 Racket 绘制 3 维图形

emacs - 让 emacs 在启动时打开东西

asynchronous - Scheme中的CSP风格异步编程(CHICKEN)

emacs - 设置 slime-enable-evaluate-in-emacs

html - 在 emacs 中使用 aspell 编辑 HTML 页面

emacs - 使用交互式 Emacs Lisp 函数替换文本的帮助

recursion - Clojure,对向量列表求和,沿途记录位置

list - 如何递归检查列表是否在 Lisp 中排序?

Emacs/CVS/OpenSSH : preventing password popup

emacs - 使用 elisp 在邪恶的迷你缓冲区中移动光标