diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2020-08-08 11:37:43 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2020-08-08 11:37:43 +0200 |
commit | 44b31c1ed7f9c6668942ea122c0dd37b825ef29c (patch) | |
tree | f595cc3d4ad9a83e69a28f0a382de7478048fb8f /lisp/buff-menu.el | |
parent | cdbbc2081ed2da3a641926e76341ed413fb5b9f9 (diff) | |
download | emacs-44b31c1ed7f9c6668942ea122c0dd37b825ef29c.tar.gz |
Make the name column in 'list-buffers' have a dynamic width
* lisp/buff-menu.el (Buffer-menu--dynamic-name-width): New
function (bug#30692).
(Buffer-menu-name-width): Default to using it.
(list-buffers--refresh): Call it.
* lisp/emacs-lisp/seq.el (seq-max): Add autoload cookie.
Diffstat (limited to 'lisp/buff-menu.el')
-rw-r--r-- | lisp/buff-menu.el | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el index 9fe0dbae381..359d6381e8b 100644 --- a/lisp/buff-menu.el +++ b/lisp/buff-menu.el @@ -69,11 +69,26 @@ minus `Buffer-menu-size-width'. This use is deprecated." "use `Buffer-menu-name-width' and `Buffer-menu-size-width' instead." "24.3") -(defcustom Buffer-menu-name-width 19 - "Width of buffer name column in the Buffer Menu." - :type 'number +(defun Buffer-menu--dynamic-name-width (buffers) + "Return a name column width based on the current window width. +The width will never exceed the actual width of the buffer names, +but will never be narrower than 19 characters." + (max 19 + ;; This gives 19 on an 80 column window, and take up + ;; proportionally more space as the window widens. + (min (truncate (/ (window-width) 4.2)) + (seq-max (mapcar (lambda (b) + (length (buffer-name b))) + buffers))))) + +(defcustom Buffer-menu-name-width #'Buffer-menu--dynamic-name-width + "Width of buffer name column in the Buffer Menu. +This can either be a number (used directly) or a function that +will be called with the list of buffers and should return a +number." + :type '(choice function number) :group 'Buffer-menu - :version "24.3") + :version "28.1") (defcustom Buffer-menu-size-width 7 "Width of buffer size column in the Buffer Menu." @@ -646,25 +661,11 @@ means list those buffers and no others." (defun list-buffers--refresh (&optional buffer-list old-buffer) ;; Set up `tabulated-list-format'. - (let ((name-width Buffer-menu-name-width) - (size-width Buffer-menu-size-width) + (let ((size-width Buffer-menu-size-width) (marked-buffers (Buffer-menu-marked-buffers)) (buffer-menu-buffer (current-buffer)) (show-non-file (not Buffer-menu-files-only)) - entries) - ;; Handle obsolete variable: - (if Buffer-menu-buffer+size-width - (setq name-width (- Buffer-menu-buffer+size-width size-width))) - (setq tabulated-list-format - (vector '("C" 1 t :pad-right 0) - '("R" 1 t :pad-right 0) - '("M" 1 t) - `("Buffer" ,name-width t) - `("Size" ,size-width tabulated-list-entry-size-> - :right-align t) - `("Mode" ,Buffer-menu-mode-width t) - '("File" 1 t))) - (setq tabulated-list-use-header-line Buffer-menu-use-header-line) + entries name-width) ;; Collect info for each buffer we're interested in. (dolist (buffer (or buffer-list (buffer-list (if Buffer-menu-use-frame-buffer-list @@ -694,6 +695,22 @@ means list those buffers and no others." nil nil buffer))) (Buffer-menu--pretty-file-name file))) entries))))) + (setq name-width (if (functionp Buffer-menu-name-width) + (funcall Buffer-menu-name-width (mapcar #'car entries)) + Buffer-menu-name-width)) + ;; Handle obsolete variable: + (if Buffer-menu-buffer+size-width + (setq name-width (- Buffer-menu-buffer+size-width size-width))) + (setq tabulated-list-format + (vector '("C" 1 t :pad-right 0) + '("R" 1 t :pad-right 0) + '("M" 1 t) + `("Buffer" ,name-width t) + `("Size" ,size-width tabulated-list-entry-size-> + :right-align t) + `("Mode" ,Buffer-menu-mode-width t) + '("File" 1 t))) + (setq tabulated-list-use-header-line Buffer-menu-use-header-line) (setq tabulated-list-entries (nreverse entries))) (tabulated-list-init-header)) |