From 2f677cf4457ae4a2fdf02cee658988da3a27dafc Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 4 Jan 2025 07:38:33 +0100 Subject: [PATCH] Fontify man page in 32 KiB chunks * lisp/man.el (man--bgproc-filter-fontify): New function. (Man-bgproc-filter): Use above new function; fontify in 32 KiB chunks. (Man-bgproc-sentinel): Use above new function. (man--bgproc-filter-last-pos): New variable. (Man-getpage-in-background): Set above new variable to 0. --- lisp/man.el | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lisp/man.el b/lisp/man.el index 54ca8cbae9f..470d6790ba2 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -417,6 +417,7 @@ Man-reverse (defvar-local Man-original-frame nil) (defvar-local Man-arguments nil) (put 'Man-arguments 'permanent-local t) +(defvar-local man--bgproc-filter-last-pos nil) (defvar-local Man--sections nil) (defvar-local Man--refpages nil) @@ -1243,8 +1244,9 @@ Man-getpage-in-background (Man-shell-file-name) shell-command-switch (format (Man-build-man-command) man-args)))) - (set-process-sentinel proc 'Man-bgproc-sentinel) - (set-process-filter proc 'Man-bgproc-filter)) + (set-process-sentinel proc #'Man-bgproc-sentinel) + (set-process-filter proc #'Man-bgproc-filter) + (setq man--bgproc-filter-last-pos 0)) (let* ((inhibit-read-only t) (exit-status (process-file @@ -1515,6 +1517,19 @@ man--maybe-fontify-manpage (Man-fontify-manpage) (Man-cleanup-manpage))) +(defun man--bgproc-filter-fontify () + (let ((inhibit-read-only t)) + (save-restriction + (narrow-to-region + (save-excursion + (goto-char man--bgproc-filter-last-pos) + ;; Process whole sections (Bug#36927). + (Man-previous-section 1) + (point)) + (point)) + (setq man--bgproc-filter-last-pos (point)) + (man--maybe-fontify-manpage)))) + (defun Man-bgproc-filter (process string) "Manpage background process filter. When manpage command is run asynchronously, PROCESS is the process @@ -1532,15 +1547,9 @@ Man-bgproc-filter (save-excursion (goto-char beg) (insert string) - (save-restriction - (narrow-to-region - (save-excursion - (goto-char beg) - ;; Process whole sections (Bug#36927). - (Man-previous-section 1) - (point)) - (point)) - (man--maybe-fontify-manpage)) + ;; Chunk the processing. + (when (>= (- beg man--bgproc-filter-last-pos) 0) + (man--bgproc-filter-fontify)) (set-marker (process-mark process) (point-max))))))))) (defun Man-bgproc-sentinel (process msg) @@ -1560,6 +1569,7 @@ Man-bgproc-sentinel (set-process-buffer process nil)) (with-current-buffer Man-buffer + (man--bgproc-filter-fontify) (save-excursion (let ((case-fold-search nil) (inhibit-read-only t)) -- 2.47.1