summaryrefslogtreecommitdiff
path: root/system/mandoc/less.patch
blob: 51f79c4534ef050f1692c7206cf7193ed83802e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Default to using less(1) instead of more(1) if MANPAGER and PAGER are
unset, and also set a pretty prompt and smart case searching like man-db
does if less is used as a pager.

The name of the manpage is not available in the scope of the patched
function - maybe add it at some point.

--- mandoc-1.14.5/main.c	2019-03-10 04:56:43.000000000 -0500
+++ mandoc-1.14.5/main.c	2020-06-05 01:59:10.640524340 -0500
@@ -1316,11 +1316,25 @@ spawn_pager(struct tag_files *tag_files)
 	/* For less(1), use the tag file. */
 
 	use_ofn = 1;
-#if HAVE_LESS_T
 	if (*outst->tag_files->tfn != '\0' &&
 	    (cmdlen = strlen(argv[0])) >= 4) {
 		cp = argv[0] + cmdlen - 4;
 		if (strcmp(cp, "less") == 0) {
+			/*
+			 * Set a few options like man-db does.
+			 * -i: smart case search
+			 * -mPm: set prompt to following string terminated by $
+			 */
+			argv[argc++] = "-imPm" \
+				" Manual page" \
+				/*
+				 * print " (END)" if EOF, else % in file followed by % sign.
+				 * ?X if X:else not X.
+				 */
+				"?e (END):?pB %pB\\%.. " \
+				"(press h for help or q to quit)" \
+				"$";
+#if HAVE_LESS_T
 			argv[argc++] = mandoc_strdup("-T");
 			argv[argc++] = outst->tag_files->tfn;
 			if (tag_files->tagname != NULL) {
@@ -1327,7 +1342,7 @@ spawn_pager(struct tag_files *tag_files)
 				argv[argc++] = tag_target;
 				use_ofn = 0;
 			}
+#endif
 		}
 	}
-#endif
 	if (use_ofn) {