From 3c4ff63bea662e2b89853894c5da69002a61ed5b Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 5 Oct 2017 12:41:36 +0300 Subject: 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) --- lisp/emacs-lisp/tabulated-list.el | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'lisp/emacs-lisp/tabulated-list.el') 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'.") (defvar-local tabulated-list-printer 'tabulated-list-print-entry "Function for inserting a Tabulated List entry at point. -It is called with two arguments, ID and COLS. ID is a Lisp -object identifying the entry, and COLS is a vector of column -descriptors, as documented in `tabulated-list-entries'.") +It is called with two mandatory arguments, ID and COLS, and one +optional argument, INDENT. ID is a Lisp object identifying the +entry, and COLS is a vector of column +descriptors, as documented in `tabulated-list-entries'. +INDENT, if present, is the initial indentation of the entry in +columns, it is used when `display-line-numbers' is in effect.") (defvar tabulated-list--near-rows) @@ -350,7 +353,7 @@ changing `tabulated-list-sort-key'." (funcall tabulated-list-entries) tabulated-list-entries)) (sorter (tabulated-list--get-sorter)) - entry-id saved-pt saved-col window-line) + entry-id saved-pt saved-col window-line lnum-width) (and remember-pos (setq entry-id (tabulated-list-get-id)) (setq saved-col (current-column)) @@ -371,6 +374,7 @@ changing `tabulated-list-sort-key'." (unless tabulated-list-use-header-line (tabulated-list-print-fake-header))) ;; Finally, print the resulting list. + (setq lnum-width (tabulated-list-line-number-width)) (while entries (let* ((elt (car entries)) (tabulated-list--near-rows @@ -383,9 +387,9 @@ changing `tabulated-list-sort-key'." (equal entry-id id) (setq entry-id nil saved-pt (point))) - ;; If the buffer this empty, simply print each elt. + ;; If the buffer is empty, simply print each elt. (if (or (not update) (eobp)) - (apply tabulated-list-printer elt) + (apply tabulated-list-printer (append elt (list lnum-width))) (while (let ((local-id (tabulated-list-get-id))) ;; If we find id, then nothing to update. (cond ((equal id local-id) @@ -398,7 +402,8 @@ changing `tabulated-list-sort-key'." ;; FIXME: Might be faster if ;; don't construct this list. (list local-id (tabulated-list-get-entry)))) - (apply tabulated-list-printer elt) + (apply tabulated-list-printer + (append elt (list lnum-width))) nil) ;; We find an entry that sorts before id, ;; it needs to be deleted. @@ -416,20 +421,22 @@ changing `tabulated-list-sort-key'." (recenter window-line))) (goto-char (point-min))))) -(defun tabulated-list-print-entry (id cols) +(defun tabulated-list-print-entry (id cols &optional indent) "Insert a Tabulated List entry at point. This is the default `tabulated-list-printer' function. ID is a Lisp object identifying the entry to print, and COLS is a vector -of column descriptors." +of column descriptors. +Optional argument INDENT is the initial indent of the entry, in +columns. This is used when `display-line-numbers' is in effect. +If INDENT is omitted or nil, it is treated as zero." (let ((beg (point)) (x (max tabulated-list-padding 0)) (ncols (length tabulated-list-format)) - (lnum-width (tabulated-list-line-number-width)) (inhibit-read-only t)) - (if display-line-numbers - (setq x (+ x lnum-width))) + (or indent (setq indent 0)) + (setq x (+ x indent)) (if (> tabulated-list-padding 0) - (insert (make-string (- x lnum-width) ?\s))) + (insert (make-string (- x indent) ?\s))) (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). (or (bound-and-true-p tabulated-list--near-rows) (list (or (tabulated-list-get-entry (point-at-bol 0)) -- cgit v1.2.3 From bd5326f879c089745c33871efc8682da5c206f80 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 5 Oct 2017 17:57:58 +0300 Subject: Fix breakage due to recent change in tabulated-list-print-entry * lisp/emacs-lisp/tabulated-list.el (tabulated-list-printer): Update the doc string. (tabulated-list-print-entry): Revert to using only 2 arguments. Update the doc string. (tabulated-list-entry-lnum-width): New defvar. (tabulated-list-print): Compute the width of line-number display once, then store that value in tabulated-list-entry-lnum-width, for tabulated-list-printer to use. (Bug#28704) --- lisp/emacs-lisp/tabulated-list.el | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'lisp/emacs-lisp/tabulated-list.el') diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index 6c5874598ae..d1d7c0a8042 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -98,12 +98,9 @@ This is commonly used to recompute `tabulated-list-entries'.") (defvar-local tabulated-list-printer 'tabulated-list-print-entry "Function for inserting a Tabulated List entry at point. -It is called with two mandatory arguments, ID and COLS, and one -optional argument, INDENT. ID is a Lisp object identifying the -entry, and COLS is a vector of column -descriptors, as documented in `tabulated-list-entries'. -INDENT, if present, is the initial indentation of the entry in -columns, it is used when `display-line-numbers' is in effect.") +It is called with two arguments, ID and COLS. ID is a Lisp +object identifying the entry, and COLS is a vector of column +descriptors, as documented in `tabulated-list-entries'.") (defvar tabulated-list--near-rows) @@ -332,6 +329,8 @@ Check the current row, the previous one and the next row." (string-width (if (stringp nt) nt (car nt))))) tabulated-list--near-rows))) +(defvar tabulated-list-entry-lnum-width nil) + (defun tabulated-list-print (&optional remember-pos update) "Populate the current Tabulated List mode buffer. This sorts the `tabulated-list-entries' list if sorting is @@ -353,7 +352,7 @@ changing `tabulated-list-sort-key'." (funcall tabulated-list-entries) tabulated-list-entries)) (sorter (tabulated-list--get-sorter)) - entry-id saved-pt saved-col window-line lnum-width) + entry-id saved-pt saved-col window-line) (and remember-pos (setq entry-id (tabulated-list-get-id)) (setq saved-col (current-column)) @@ -374,7 +373,7 @@ changing `tabulated-list-sort-key'." (unless tabulated-list-use-header-line (tabulated-list-print-fake-header))) ;; Finally, print the resulting list. - (setq lnum-width (tabulated-list-line-number-width)) + (setq tabulated-list-entry-lnum-width (tabulated-list-line-number-width)) (while entries (let* ((elt (car entries)) (tabulated-list--near-rows @@ -389,7 +388,7 @@ changing `tabulated-list-sort-key'." saved-pt (point))) ;; If the buffer is empty, simply print each elt. (if (or (not update) (eobp)) - (apply tabulated-list-printer (append elt (list lnum-width))) + (apply tabulated-list-printer elt) (while (let ((local-id (tabulated-list-get-id))) ;; If we find id, then nothing to update. (cond ((equal id local-id) @@ -402,8 +401,7 @@ changing `tabulated-list-sort-key'." ;; FIXME: Might be faster if ;; don't construct this list. (list local-id (tabulated-list-get-entry)))) - (apply tabulated-list-printer - (append elt (list lnum-width))) + (apply tabulated-list-printer elt) nil) ;; We find an entry that sorts before id, ;; it needs to be deleted. @@ -421,22 +419,18 @@ changing `tabulated-list-sort-key'." (recenter window-line))) (goto-char (point-min))))) -(defun tabulated-list-print-entry (id cols &optional indent) +(defun tabulated-list-print-entry (id cols) "Insert a Tabulated List entry at point. This is the default `tabulated-list-printer' function. ID is a Lisp object identifying the entry to print, and COLS is a vector -of column descriptors. -Optional argument INDENT is the initial indent of the entry, in -columns. This is used when `display-line-numbers' is in effect. -If INDENT is omitted or nil, it is treated as zero." +of column descriptors." (let ((beg (point)) (x (max tabulated-list-padding 0)) (ncols (length tabulated-list-format)) (inhibit-read-only t)) - (or indent (setq indent 0)) - (setq x (+ x indent)) + (setq x (+ x tabulated-list-entry-lnum-width)) (if (> tabulated-list-padding 0) - (insert (make-string (- x indent) ?\s))) + (insert (make-string (- x tabulated-list-entry-lnum-width) ?\s))) (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). (or (bound-and-true-p tabulated-list--near-rows) (list (or (tabulated-list-get-entry (point-at-bol 0)) -- cgit v1.2.3