;; 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)
(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)
(require 'ert)
(require 'man)
+(require 'seq)
(defconst man-tests-parse-man-k-tests
'(;; GNU/Linux: man-db-2.6.1
(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