xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit c1cc5a60a4fcf332dfc3f9cb08ebe329ea57938a

Make command completion work with marks.
Author: xaizek
Author date (UTC): 2011-06-19 11:27
Committer name: xaizek
Committer date (UTC): 2011-06-19 11:27
Parent(s): b81ebbf7119809094c97ffe623b2747eefcd0c1b
Signing key:
Tree: f0887148a060841d153601c33bde771319967f2a
File Lines added Lines deleted
ChangeLog 2 0
TODO 0 1
src/cmdline.c 7 47
src/commands.c 75 5
src/commands.h 1 0
File ChangeLog changed (mode: 100644) (index 82861333f..b7fc18fbf)
37 37
38 38 Added gv normal mode command. Added gv normal mode command.
39 39
40 Made command completion work with marks.
41
40 42 0.6 to 0.6.1 0.6 to 0.6.1
41 43
42 44 Added :set command. Added :set command.
File TODO changed (mode: 100644) (index 19069b124..0a308c56c)
... ... Basic things that need to be done.
5 5 Better documentation. Better documentation.
6 6 Handle commands that are too long to be passed directly to the shell (fixed??). Handle commands that are too long to be passed directly to the shell (fixed??).
7 7 Make ga work in background. Make ga work in background.
8 Make command completion work when marks are given.
9 8
10 9 Vi specific features that need to be added. Vi specific features that need to be added.
11 10 Finish implementing range and count for user commands (what commands left?). Finish implementing range and count for user commands (what commands left?).
File src/cmdline.c changed (mode: 100644) (index b23ae84c7..d21c40f21)
... ... insert_completed_command(struct line_stats *stat, const char *complete_command)
1068 1068 void *p; void *p;
1069 1069 wchar_t *buf; wchar_t *buf;
1070 1070
1071 i = mbstowcs(NULL, complete_command, 0) + 1;
1072 if((buf = (wchar_t *) malloc((i + 1) * sizeof(wchar_t))) == NULL)
1073 {
1071 if((buf = to_wide(complete_command)) == NULL)
1074 1072 return -1; return -1;
1075 }
1076 mbstowcs(buf, complete_command, i);
1077 1073
1078 i += wcslen(q);
1074 i = wcslen(buf) + wcslen(q) + 1;
1079 1075
1080 1076 wcsdel(stat->line, 1, q - stat->line); wcsdel(stat->line, 1, q - stat->line);
1081 1077
 
... ... insert_completed_command(struct line_stats *stat, const char *complete_command)
1096 1092 else else
1097 1093 { {
1098 1094 int i; int i;
1099 void *p;
1095 wchar_t *p;
1100 1096
1101 i = mbstowcs(NULL, complete_command, 0) + 1;
1102 if((p = realloc(stat->line, (stat->len + i) * sizeof(wchar_t))) == NULL)
1103 {
1097 if((p = to_wide(complete_command)) == NULL)
1104 1098 return -1; return -1;
1105 }
1106 stat->line = (wchar_t *) p;
1099
1100 i = wcslen(p) + 1;
1101 stat->line = p;
1107 1102
1108 1103 q = wcschr(stat->line, L' '); q = wcschr(stat->line, L' ');
1109 1104 if(q == NULL) if(q == NULL)
 
... ... insert_completed_command(struct line_stats *stat, const char *complete_command)
1124 1119 return 0; return 0;
1125 1120 } }
1126 1121
1127 static int
1128 get_buildin_id(const char *cmd_line)
1129 {
1130 const char *p, *q;
1131 char buf[128];
1132
1133 while(cmd_line[0] != '\0' && isspace(cmd_line[0]))
1134 {
1135 cmd_line++;
1136 }
1137
1138 if(cmd_line[0] == '!')
1139 return COM_EXECUTE;
1140
1141 if((p = strchr(cmd_line, ' ')) == NULL)
1142 p = cmd_line + strlen(cmd_line);
1143
1144 q = p - 1;
1145 if(q >= cmd_line && *q == '!')
1146 {
1147 q--;
1148 p--;
1149 }
1150 while(q >= cmd_line && isalpha(*q))
1151 q--;
1152 q++;
1153
1154 snprintf(buf, p - q + 1, "%s", q);
1155
1156 if(buf[0] == '\0')
1157 return -1;
1158
1159 return command_is_reserved(buf);
1160 }
1161
1162 1122 static int static int
1163 1123 line_completion(struct line_stats *stat) line_completion(struct line_stats *stat)
1164 1124 { {
File src/commands.c changed (mode: 100644) (index 578383b55..f13e204ff)
... ... command_is_reserved(char *name)
150 150 return -1; return -1;
151 151 } }
152 152
153 /* len could be NULL */
154 static const char *
155 get_cmd_name_info(const char *cmd_line, size_t *len)
156 {
157 const char *p, *q;
158
159 while(cmd_line[0] != '\0' && isspace(cmd_line[0]))
160 {
161 cmd_line++;
162 }
163
164 if(cmd_line[0] == '!')
165 return COM_EXECUTE;
166
167 if((p = strchr(cmd_line, ' ')) == NULL)
168 p = cmd_line + strlen(cmd_line);
169
170 q = p - 1;
171 if(q >= cmd_line && *q == '!')
172 {
173 q--;
174 p--;
175 }
176 while(q >= cmd_line && isalpha(*q))
177 q--;
178 q++;
179
180 if(q[0] == '\'' && q[1] != '\0')
181 q += 2;
182 if(q[0] == '\'' && q[1] != '\0')
183 q += 2;
184
185 if(len != NULL)
186 *len = p - q;
187 return q;
188 }
189
190 int
191 get_buildin_id(const char *cmd_line)
192 {
193 char buf[128];
194 size_t len;
195 const char *p;
196
197 p = get_cmd_name_info(cmd_line, &len);
198
199 snprintf(buf, len + 1, "%s", p);
200
201 if(buf[0] == '\0')
202 return -1;
203
204 return command_is_reserved(buf);
205 }
206
153 207 int int
154 208 command_is_being_used(char *command) command_is_being_used(char *command)
155 209 { {
 
... ... command_is_being_used(char *command)
162 216 return 0; return 0;
163 217 } }
164 218
219 static char *
220 add_prefixes(const char *str, const char *completed)
221 {
222 char *result;
223 const char *p;
224 p = get_cmd_name_info(str, NULL);
225
226 result = malloc(p - str + strlen(completed) + 1);
227 if(result == NULL)
228 return NULL;
229
230 snprintf(result, p - str + 1, "%s", str);
231 strcat(result, completed);
232 return result;
233 }
234
165 235 /* On the first call to this function, /* On the first call to this function,
166 236 * the string to be parsed should be specified in str. * the string to be parsed should be specified in str.
167 237 * In each subsequent call that should parse the same string, str should be NULL * In each subsequent call that should parse the same string, str should be NULL
 
... ... command_completion(char *str, int users_only)
186 256 else else
187 257 offset++; offset++;
188 258
189 pos_b = users_only ? -1 : command_is_reserved(string);
259 pos_b = users_only ? -1 : get_buildin_id(string);
190 260 pos_u = is_user_command(string); pos_u = is_user_command(string);
191 261
192 262 i = 0; i = 0;
 
... ... command_completion(char *str, int users_only)
224 294 else if(pos_b != -1 && pos_u != -1) else if(pos_b != -1 && pos_u != -1)
225 295 { {
226 296 if(strcmp(reserved_commands[pos_b], command_list[pos_u].name) < 0) if(strcmp(reserved_commands[pos_b], command_list[pos_u].name) < 0)
227 return strdup(reserved_commands[pos_b]);
297 return add_prefixes(string, strdup(reserved_commands[pos_b]));
228 298 else else
229 return strdup(command_list[pos_u].name);
299 return add_prefixes(string, strdup(command_list[pos_u].name));
230 300 } }
231 301 else else
232 302 { {
233 303 if(pos_b != -1) if(pos_b != -1)
234 return strdup(reserved_commands[pos_b]);
304 return add_prefixes(string, strdup(reserved_commands[pos_b]));
235 305 else else
236 return strdup(command_list[pos_u].name);
306 return add_prefixes(string, strdup(command_list[pos_u].name));
237 307 } }
238 308 } }
239 309
File src/commands.h changed (mode: 100644) (index 8c3e9d1cb..4fdaff250)
... ... int execute_command(FileView *view, char *action);
101 101 int sort_this(const void *one, const void *two); int sort_this(const void *one, const void *two);
102 102 int is_user_command(char *command); int is_user_command(char *command);
103 103 int command_is_reserved(char *command); int command_is_reserved(char *command);
104 int get_buildin_id(const char *cmd_line);
104 105 char * command_completion(char *str, int users_only); char * command_completion(char *str, int users_only);
105 106 char * expand_macros(FileView *view, char *command, char *args, int *menu, char * expand_macros(FileView *view, char *command, char *args, int *menu,
106 107 int *split); int *split);
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master