diff options
| author | Eli Zaretskii | 2017-10-05 12:41:36 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-10-05 12:41:36 +0300 |
| commit | 3c4ff63bea662e2b89853894c5da69002a61ed5b (patch) | |
| tree | 922f65b677e8d48f2b046338c9350f8826dda3b5 | |
| parent | 7a1133f1ff002943ce32b5a05a7261bba520288c (diff) | |
| download | emacs-3c4ff63bea662e2b89853894c5da69002a61ed5b.tar.gz emacs-3c4ff63bea662e2b89853894c5da69002a61ed5b.zip | |
Speed up list-packages when 'visual' line numbers are displayed
* lisp/emacs-lisp/tabulated-list.el (tabulated-list-printer):
Update the doc string.
(tabulated-list-print-entry): Accept an additional optional
argument INDENT. Update the doc string.
(tabulated-list-print): Compute the width of line-number display
once, then call tabulated-list-printer with that value as 3rd
argument. (Bug#28704)
| -rw-r--r-- | lisp/emacs-lisp/tabulated-list.el | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index e940588db7b..6c5874598ae 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el | |||
| @@ -98,9 +98,12 @@ This is commonly used to recompute `tabulated-list-entries'.") | |||
| 98 | 98 | ||
| 99 | (defvar-local tabulated-list-printer 'tabulated-list-print-entry | 99 | (defvar-local tabulated-list-printer 'tabulated-list-print-entry |
| 100 | "Function for inserting a Tabulated List entry at point. | 100 | "Function for inserting a Tabulated List entry at point. |
| 101 | It is called with two arguments, ID and COLS. ID is a Lisp | 101 | It is called with two mandatory arguments, ID and COLS, and one |
| 102 | object identifying the entry, and COLS is a vector of column | 102 | optional argument, INDENT. ID is a Lisp object identifying the |
| 103 | descriptors, as documented in `tabulated-list-entries'.") | 103 | entry, and COLS is a vector of column |
| 104 | descriptors, as documented in `tabulated-list-entries'. | ||
| 105 | INDENT, if present, is the initial indentation of the entry in | ||
| 106 | columns, it is used when `display-line-numbers' is in effect.") | ||
| 104 | 107 | ||
| 105 | (defvar tabulated-list--near-rows) | 108 | (defvar tabulated-list--near-rows) |
| 106 | 109 | ||
| @@ -350,7 +353,7 @@ changing `tabulated-list-sort-key'." | |||
| 350 | (funcall tabulated-list-entries) | 353 | (funcall tabulated-list-entries) |
| 351 | tabulated-list-entries)) | 354 | tabulated-list-entries)) |
| 352 | (sorter (tabulated-list--get-sorter)) | 355 | (sorter (tabulated-list--get-sorter)) |
| 353 | entry-id saved-pt saved-col window-line) | 356 | entry-id saved-pt saved-col window-line lnum-width) |
| 354 | (and remember-pos | 357 | (and remember-pos |
| 355 | (setq entry-id (tabulated-list-get-id)) | 358 | (setq entry-id (tabulated-list-get-id)) |
| 356 | (setq saved-col (current-column)) | 359 | (setq saved-col (current-column)) |
| @@ -371,6 +374,7 @@ changing `tabulated-list-sort-key'." | |||
| 371 | (unless tabulated-list-use-header-line | 374 | (unless tabulated-list-use-header-line |
| 372 | (tabulated-list-print-fake-header))) | 375 | (tabulated-list-print-fake-header))) |
| 373 | ;; Finally, print the resulting list. | 376 | ;; Finally, print the resulting list. |
| 377 | (setq lnum-width (tabulated-list-line-number-width)) | ||
| 374 | (while entries | 378 | (while entries |
| 375 | (let* ((elt (car entries)) | 379 | (let* ((elt (car entries)) |
| 376 | (tabulated-list--near-rows | 380 | (tabulated-list--near-rows |
| @@ -383,9 +387,9 @@ changing `tabulated-list-sort-key'." | |||
| 383 | (equal entry-id id) | 387 | (equal entry-id id) |
| 384 | (setq entry-id nil | 388 | (setq entry-id nil |
| 385 | saved-pt (point))) | 389 | saved-pt (point))) |
| 386 | ;; If the buffer this empty, simply print each elt. | 390 | ;; If the buffer is empty, simply print each elt. |
| 387 | (if (or (not update) (eobp)) | 391 | (if (or (not update) (eobp)) |
| 388 | (apply tabulated-list-printer elt) | 392 | (apply tabulated-list-printer (append elt (list lnum-width))) |
| 389 | (while (let ((local-id (tabulated-list-get-id))) | 393 | (while (let ((local-id (tabulated-list-get-id))) |
| 390 | ;; If we find id, then nothing to update. | 394 | ;; If we find id, then nothing to update. |
| 391 | (cond ((equal id local-id) | 395 | (cond ((equal id local-id) |
| @@ -398,7 +402,8 @@ changing `tabulated-list-sort-key'." | |||
| 398 | ;; FIXME: Might be faster if | 402 | ;; FIXME: Might be faster if |
| 399 | ;; don't construct this list. | 403 | ;; don't construct this list. |
| 400 | (list local-id (tabulated-list-get-entry)))) | 404 | (list local-id (tabulated-list-get-entry)))) |
| 401 | (apply tabulated-list-printer elt) | 405 | (apply tabulated-list-printer |
| 406 | (append elt (list lnum-width))) | ||
| 402 | nil) | 407 | nil) |
| 403 | ;; We find an entry that sorts before id, | 408 | ;; We find an entry that sorts before id, |
| 404 | ;; it needs to be deleted. | 409 | ;; it needs to be deleted. |
| @@ -416,20 +421,22 @@ changing `tabulated-list-sort-key'." | |||
| 416 | (recenter window-line))) | 421 | (recenter window-line))) |
| 417 | (goto-char (point-min))))) | 422 | (goto-char (point-min))))) |
| 418 | 423 | ||
| 419 | (defun tabulated-list-print-entry (id cols) | 424 | (defun tabulated-list-print-entry (id cols &optional indent) |
| 420 | "Insert a Tabulated List entry at point. | 425 | "Insert a Tabulated List entry at point. |
| 421 | This is the default `tabulated-list-printer' function. ID is a | 426 | This is the default `tabulated-list-printer' function. ID is a |
| 422 | Lisp object identifying the entry to print, and COLS is a vector | 427 | Lisp object identifying the entry to print, and COLS is a vector |
| 423 | of column descriptors." | 428 | of column descriptors. |
| 429 | Optional argument INDENT is the initial indent of the entry, in | ||
| 430 | columns. This is used when `display-line-numbers' is in effect. | ||
| 431 | If INDENT is omitted or nil, it is treated as zero." | ||
| 424 | (let ((beg (point)) | 432 | (let ((beg (point)) |
| 425 | (x (max tabulated-list-padding 0)) | 433 | (x (max tabulated-list-padding 0)) |
| 426 | (ncols (length tabulated-list-format)) | 434 | (ncols (length tabulated-list-format)) |
| 427 | (lnum-width (tabulated-list-line-number-width)) | ||
| 428 | (inhibit-read-only t)) | 435 | (inhibit-read-only t)) |
| 429 | (if display-line-numbers | 436 | (or indent (setq indent 0)) |
| 430 | (setq x (+ x lnum-width))) | 437 | (setq x (+ x indent)) |
| 431 | (if (> tabulated-list-padding 0) | 438 | (if (> tabulated-list-padding 0) |
| 432 | (insert (make-string (- x lnum-width) ?\s))) | 439 | (insert (make-string (- x indent) ?\s))) |
| 433 | (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). | 440 | (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). |
| 434 | (or (bound-and-true-p tabulated-list--near-rows) | 441 | (or (bound-and-true-p tabulated-list--near-rows) |
| 435 | (list (or (tabulated-list-get-entry (point-at-bol 0)) | 442 | (list (or (tabulated-list-get-entry (point-at-bol 0)) |