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.
This commit is contained in:
parent
780509f29f
commit
f9464020d4
2 changed files with 52 additions and 16 deletions
20
lisp/man.el
20
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)
|
||||
|
|
|
@ -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 <stdio.h>
|
||||
|
||||
int printf(const char *format, ...);
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
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 <stdio.h>")
|
||||
(let ((button (button-at (match-beginning 0))))
|
||||
(should (and button (eq 'Man-xref-header-file (button-type button)))))
|
||||
(search-forward "#include <stdarg.h>")
|
||||
(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
|
||||
|
|
Loading…
Add table
Reference in a new issue