summaryrefslogtreecommitdiff
path: root/system/ksh-openbsd/patches/05-ksh-print-expansions-like-a-menu-with-numbers-in-vi-.diff
blob: 135f5054c3353804c41b79fe3b7edaf485830b68 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
From 91ebd29a64451742b65115fc27034c6a3d154f90 Mon Sep 17 00:00:00 2001
From: Alexander Polakov <polachok@gmail.com>
Date: Sun, 29 May 2011 15:41:53 +0400
Subject: [PATCH 5/8] ksh: print expansions like a "menu" (with numbers) in vi
 mode

 * adds an extra argument to x_print_expansions()
   - preserves the emacs mode behaviour

 Why: in vi mode one can use the expansion number to
      complete the word, but w/o numbers printed you
      have to *count* expansions with your eyes to
      find out the number. Stupid, huh?
---
 edit.c  |    7 +++++--
 edit.h  |    2 +-
 emacs.c |    4 ++--
 vi.c    |    4 ++--
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git edit.c edit.c
index 0b1ff7d..9cdcc6d 100644
--- edit.c
+++ edit.c
@@ -292,7 +292,7 @@ static void	glob_path(int flags, const char *pat, XPtrV *wp,
 				const char *path);
 
 void
-x_print_expansions(int nwords, char *const *words, int is_command)
+x_print_expansions(int nwords, char *const *words, int is_command, int menu)
 {
 	int use_copy = 0;
 	int prefix_len;
@@ -330,7 +330,10 @@ x_print_expansions(int nwords, char *const *words, int is_command)
 	 */
 	x_putc('\r');
 	x_putc('\n');
-	pr_list(use_copy ? (char **) XPptrv(l) : words);
+	if (menu)
+		pr_menu(use_copy ? (char **) XPptrv(l) : words);
+	else
+		pr_list(use_copy ? (char **) XPptrv(l) : words);
 
 	if (use_copy)
 		XPfree(l); /* not x_free_words() */
diff --git edit.h edit.h
index 37ccf28..258affe 100644
--- edit.h
+++ edit.h
@@ -52,7 +52,7 @@ void	x_puts(const char *);
 bool	x_mode(bool);
 int	promptlen(const char *, const char **);
 int	x_do_comment(char *, int, int *);
-void	x_print_expansions(int, char *const *, int);
+void	x_print_expansions(int, char *const *, int, int);
 int	x_cf_glob(int, const char *, int, int, int *, int *, char ***, int *);
 int	x_longest_prefix(int , char *const *);
 int	x_basename(const char *, const char *);
diff --git emacs.c emacs.c
index 0bfda96..3b2d083 100644
--- emacs.c
+++ emacs.c
@@ -1684,7 +1684,7 @@ do_complete(int flags,	/* XCF_{COMMAND,FILE,COMMAND_FILE} */
 	}
 
 	if (type == CT_LIST) {
-		x_print_expansions(nwords, words, is_command);
+		x_print_expansions(nwords, words, is_command, 0);
 		x_redraw(0);
 		x_free_words(nwords, words);
 		return;
@@ -1707,7 +1707,7 @@ do_complete(int flags,	/* XCF_{COMMAND,FILE,COMMAND_FILE} */
 	}
 
 	if (type == CT_COMPLIST && !completed) {
-		x_print_expansions(nwords, words, is_command);
+		x_print_expansions(nwords, words, is_command, 0);
 		completed = 1;
 	}
 
diff --git vi.c vi.c
index 6eb5d8c..95d192c 100644
--- vi.c
+++ vi.c
@@ -1990,7 +1990,7 @@ complete_word(int command, int count, int flags)
 		count--;
 		if (count >= nwords) {
 			vi_error();
-			x_print_expansions(nwords, words, is_command);
+			x_print_expansions(nwords, words, is_command, 1);
 			x_free_words(nwords, words);
 			redraw_line(0);
 			return -1;
@@ -2064,7 +2064,7 @@ print_expansions(struct edstate *e, int flags)
 		vi_error();
 		return -1;
 	}
-	x_print_expansions(nwords, words, is_command);
+	x_print_expansions(nwords, words, is_command, 1);
 	x_free_words(nwords, words);
 	redraw_line(0);
 	return 0;
-- 
1.7.5