From f9464020d403be8344f8293297b27276872571d4 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 18 Aug 2019 18:10:50 -0400 Subject: [PATCH] Handle more subprocess chunking in M-x man (Bug#36927) * lisp/man.el (Man-bgproc-filter): Make sure not to chop man sections by narrowing. (Man-highlight-references0): Revert previous fix, as it's no longer needed. * test/lisp/man-tests.el (man-tests-filter-strings): New function. (man-bgproc-filter-buttonize-includes): New test. --- lisp/man.el | 20 ++++-------------- test/lisp/man-tests.el | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/lisp/man.el b/lisp/man.el index 89d514423b6..cef3d598eb9 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -1296,21 +1296,7 @@ default type, `Man-xref-man-page' is used for the buttons." ;; Based on `Man-build-references-alist' (when (or (null start-section) ;; Search regardless of sections. ;; Section header is in this chunk. - (Man-find-section start-section) - ;; Section header was in one of the previous chunks. - (save-excursion - (save-restriction - (let ((orig-pos (point))) - (widen) - (if (Man-find-section start-section) - ;; We are in the right section of the next - ;; section is either not yet in the buffer, or - ;; it starts after the position where we should - ;; start highlighting. - (progn - (forward-line 1) - (or (null (re-search-forward Man-heading-regexp nil t)) - (> (point) orig-pos)))))))) + (Man-find-section start-section)) (let ((end (if start-section (progn (forward-line 1) @@ -1384,7 +1370,9 @@ command is run. Second argument STRING is the entire string of output." (narrow-to-region (save-excursion (goto-char beg) - (line-beginning-position)) + ;; Process whole sections (Bug#36927). + (Man-previous-section 1) + (point)) (point)) (if Man-fontify-manpage-flag (Man-fontify-manpage) diff --git a/test/lisp/man-tests.el b/test/lisp/man-tests.el index dca0ff19398..9932e03f21a 100644 --- a/test/lisp/man-tests.el +++ b/test/lisp/man-tests.el @@ -24,6 +24,7 @@ (require 'ert) (require 'man) +(require 'seq) (defconst man-tests-parse-man-k-tests '(;; GNU/Linux: man-db-2.6.1 @@ -113,6 +114,53 @@ in the cdr of the element.") (dolist (test man-tests-parse-man-k-tests) (should (man-tests-parse-man-k-test-case test)))) +(defun man-tests-filter-strings (buffer strings) + "Run `Man-bgproc-filter' on each of STRINGS. +The formatted result will be inserted into BUFFER." + (let ((proc (start-process "dummy man-tests proc" (current-buffer) "cat"))) + (set-process-query-on-exit-flag proc nil) + (dolist (str strings) + (Man-bgproc-filter proc str)))) + +(ert-deftest man-bgproc-filter-buttonize-includes () + ;; Test with abridged version of printf man page (Bug#36927). + (let ((str "\ +PRINTF(3) Linux Programmer's Manual PRINTF(3) + +NAME + printf, fprintf, dprintf, sprintf, snprintf, vprintf, vfprintf, + +SYNOPSIS + #include + + int printf(const char *format, ...); + + #include + + int vsprintf(char *str, const char *format, va_list ap); + +DESCRIPTION + The functions in the printf() family produce output according\n")) + (with-temp-buffer + (dolist (chunks + (list + ;; Test a few different kinds of chunking. + (list str) + (seq-mapcat (lambda (line) + (list line "\n")) + (split-string str "\n")) + (mapcar #'string str))) + (erase-buffer) + (man-tests-filter-strings (current-buffer) chunks) + (goto-char (point-min)) + (ert-info ((format "%S" chunks) :prefix "Input: ") + (search-forward "#include ") + (let ((button (button-at (match-beginning 0)))) + (should (and button (eq 'Man-xref-header-file (button-type button))))) + (search-forward "#include ") + (let ((button (button-at (match-beginning 0)))) + (should (and button (eq 'Man-xref-header-file (button-type button)))))))))) + (provide 'man-tests) ;;; man-tests.el ends here -- 2.39.2