mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-09 15:50:40 -08:00
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.
This commit is contained in:
parent
cdbbc2081e
commit
44b31c1ed7
3 changed files with 46 additions and 20 deletions
8
etc/NEWS
8
etc/NEWS
|
|
@ -130,6 +130,14 @@ same for a button.
|
|||
|
||||
* Changes in Specialized Modes and Packages in Emacs 28.1
|
||||
|
||||
** Miscellaneous
|
||||
|
||||
---
|
||||
*** The width of the buffer-name column in 'list-buffers' is now dynamic.
|
||||
The width now depends of the width of the window, but will never be
|
||||
wider than the length of the longest buffer name, except that it will
|
||||
never be narrower than 19 characters.
|
||||
|
||||
** Windows
|
||||
|
||||
*** The key prefix 'C-x 4 1' displays next command buffer in the same window.
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -492,6 +492,7 @@ keys. Keys are compared using `equal'."
|
|||
SEQUENCE must be a sequence of numbers or markers."
|
||||
(apply #'min (seq-into sequence 'list)))
|
||||
|
||||
;;;###autoload
|
||||
(cl-defgeneric seq-max (sequence)
|
||||
"Return the largest element of SEQUENCE.
|
||||
SEQUENCE must be a sequence of numbers or markers."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue