~alivema4ever/ubuntu/trusty/weechat/lp-1299347-fix

« back to all changes in this revision

Viewing changes to src/gui/gui-completion.c

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bouthenot
  • Date: 2013-01-23 18:44:36 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20130123184436-pillcj7jmtyyj00j
Tags: 0.4.0-1
* New upstream release.
* Bump Standards-Version to 3.9.4
* Remove UPGRADE_0.3 from doc (no more included in upstream sources).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org>
 
2
 * gui-completion.c - word completion according to context (used by all GUI)
 
3
 *
 
4
 * Copyright (C) 2003-2013 Sebastien Helleu <flashcode@flashtux.org>
3
5
 *
4
6
 * This file is part of WeeChat, the extensible chat client.
5
7
 *
17
19
 * along with WeeChat.  If not, see <http://www.gnu.org/licenses/>.
18
20
 */
19
21
 
20
 
/*
21
 
 * gui-completion.c: word completion according to context (used by all GUI)
22
 
 */
23
 
 
24
22
#ifdef HAVE_CONFIG_H
25
23
#include "config.h"
26
24
#endif
50
48
 
51
49
 
52
50
/*
53
 
 * gui_completion_buffer_init: init completion for a buffer
 
51
 * Initializes completion for a buffer.
54
52
 */
55
53
 
56
54
void
82
80
}
83
81
 
84
82
/*
85
 
 * gui_completion_partial_list_add: add an item to partial completions list
 
83
 * Adds an item to partial completion list.
 
84
 *
 
85
 * Returns pointer to new item, NULL if error.
86
86
 */
87
87
 
88
88
struct t_gui_completion_partial *
109
109
}
110
110
 
111
111
/*
112
 
 * gui_completion_partial_free: remove an item from partial completions list
 
112
 * Removes an item from partial completion list.
113
113
 */
114
114
 
115
115
void
134
134
}
135
135
 
136
136
/*
137
 
 * gui_completion_partial_free: remove partial completions list
 
137
 * Removes partial completion list.
138
138
 */
139
139
 
140
140
void
148
148
}
149
149
 
150
150
/*
151
 
 * gui_completion_free_data: free data in completion
 
151
 * Frees data in completion.
152
152
 */
153
153
 
154
154
void
180
180
}
181
181
 
182
182
/*
183
 
 * gui_completion_free: free completion
 
183
 * Frees completion.
184
184
 */
185
185
 
186
186
void
191
191
}
192
192
 
193
193
/*
194
 
 * gui_completion_stop: stop completion (for example after 1 arg of command
195
 
 *                      with 1 arg)
 
194
 * Stops completion (for example after 1 argument of command with 1 argument).
196
195
 */
197
196
 
198
197
void
210
209
}
211
210
 
212
211
/*
213
 
 * gui_completion_search_command: search command hook
 
212
 * Searches for a command hook.
 
213
 *
 
214
 * Returns pointer to hook found, NULL if not found.
214
215
 */
215
216
 
216
217
struct t_hook *
241
242
}
242
243
 
243
244
/*
244
 
 * gui_completion_nick_has_ignored_chars: return 1 if nick has one or more
245
 
 *                                        ignored chars for nick comparison
 
245
 * Checks if nick has one or more ignored chars (for nick comparison).
 
246
 *
 
247
 * Returns:
 
248
 *   1: nick has one or more ignored chars
 
249
 *   0: nick has no ignored chars
246
250
 */
247
251
 
248
252
int
267
271
}
268
272
 
269
273
/*
270
 
 * gui_completion_nick_strdup_ignore_chars: duplicate a nick and ignore some
271
 
 *                                          chars
 
274
 * Duplicates a nick and ignores some chars.
 
275
 *
 
276
 * Note: result must be freed after use.
272
277
 */
273
278
 
274
279
char *
299
304
}
300
305
 
301
306
/*
302
 
 * gui_completion_nickncmp: locale and case independent string comparison
303
 
 *                          with max length for nicks (alpha or digits only)
 
307
 * Locale and case independent string comparison with max length for nicks
 
308
 * (alpha or digits only).
 
309
 *
 
310
 * Returns:
 
311
 *   < 0: base_word < nick
 
312
 *     0: base_word == nick
 
313
 *   > 0: base_word > nick
304
314
 */
305
315
 
306
316
int
328
338
}
329
339
 
330
340
/*
331
 
 * gui_completion_list_add: add a word to completion word list
 
341
 * Adds a word to completion list.
332
342
 */
333
343
 
334
344
void
362
372
}
363
373
 
364
374
/*
365
 
 * gui_completion_custom: custom completion by a plugin
 
375
 * Custom completion by a plugin.
366
376
 */
367
377
 
368
378
void
377
387
}
378
388
 
379
389
/*
380
 
 * gui_completion_build_list_template: build data list according to a template
 
390
 * Builds data list according to a template.
381
391
 */
382
392
 
383
393
void
455
465
}
456
466
 
457
467
/*
458
 
 * gui_completion_get_matching_template: get template matching arguments for
459
 
 *                                       command
 
468
 * Gets template matching arguments for command.
460
469
 */
461
470
 
462
471
int
463
472
gui_completion_get_matching_template (struct t_gui_completion *completion,
464
473
                                      struct t_hook *hook_command)
465
474
{
466
 
    int i, length;
 
475
    int i, length, fallback;
467
476
 
468
477
    /* without at least one argument, we can't find matching template! */
469
478
    if (completion->base_command_arg_index <= 1)
470
479
        return -1;
471
480
 
 
481
    fallback = -1;
 
482
 
472
483
    for (i = 0; i < HOOK_COMMAND(hook_command, cplt_num_templates); i++)
473
484
    {
474
485
        length = strlen (HOOK_COMMAND(hook_command, cplt_templates_static)[i]);
478
489
        {
479
490
            return i;
480
491
        }
 
492
        /*
 
493
         * try to find a fallback template if we don't find any matching
 
494
         * template, for example with these templates (command /set):
 
495
         *   %(config_options) %(config_option_values)
 
496
         *   diff %(config_options)|%*
 
497
         * if first argument is "diff", the match is ok (second template)
 
498
         * if first argument is not "diff", we will fallback on the first
 
499
         * template containing "%" (here first template)
 
500
         */
 
501
        if ((fallback < 0)
 
502
            && (strstr (HOOK_COMMAND(hook_command, cplt_templates_static)[i], "%")))
 
503
        {
 
504
            fallback = i;
 
505
        }
481
506
    }
482
507
 
483
 
    return -1;
 
508
    return fallback;
484
509
}
485
510
 
486
511
/*
487
 
 * gui_completion_get_template_for_args: get template according to user
488
 
 *                                       arguments for command
 
512
 * Gets template according to user arguments for command.
489
513
 */
490
514
 
491
515
char *
533
557
}
534
558
 
535
559
/*
536
 
 * gui_completion_build_list: build data list according to command and
537
 
 *                            argument index
 
560
 * Builds data list according to command and argument index.
538
561
 */
539
562
 
540
563
void
610
633
}
611
634
 
612
635
/*
613
 
 * gui_completion_find_context: find context for completion
 
636
 * Finds context for completion.
614
637
 */
615
638
 
616
639
void
773
796
}
774
797
 
775
798
/*
776
 
 * gui_completion_common_prefix_size: find common prefix size in matching items
777
 
 *                                    (case is ignored)
778
 
 *                                    if utf_char is not null, only words
779
 
 *                                    beginning with this char are compared
780
 
 *                                    (all other words are ignored)
781
 
 *                                    for example with items:
782
 
 *                                        FlashCode, flashy, flashouille
783
 
 *                                    common prefix size is 5 ("flash")
 
799
 * Finds common prefix size in matching items (case is ignored).
 
800
 *
 
801
 * If utf_char is not null, only words beginning with this char are compared
 
802
 * (all other words are ignored).
 
803
 *
 
804
 * For example with items:
 
805
 *   FlashCode, flashy, flashouille
 
806
 *   => common prefix size is 5 ("flash")
784
807
 */
785
808
 
786
809
int
818
841
}
819
842
 
820
843
/*
821
 
 * gui_completion_partial_build_list: build list with possible completions
822
 
 *                                    when a partial completion occurs
 
844
 * Builds list with possible completions when a partial completion occurs.
823
845
 */
824
846
 
825
847
void
888
910
}
889
911
 
890
912
/*
891
 
 * gui_completion_complete: complete word using matching items
 
913
 * Completes word using matching items.
892
914
 */
893
915
 
894
916
void
1059
1081
}
1060
1082
 
1061
1083
/*
1062
 
 * gui_completion_command: complete a command
 
1084
 * Completes a command.
1063
1085
 */
1064
1086
 
1065
1087
void
1087
1109
}
1088
1110
 
1089
1111
/*
1090
 
 * gui_completion_auto: auto complete: nick, filename or channel
 
1112
 * Auto-completes: nick, filename or channel.
1091
1113
 */
1092
1114
 
1093
1115
void
1114
1136
}
1115
1137
 
1116
1138
/*
1117
 
 * gui_completion_search: complete word according to context
 
1139
 * Completes word according to context.
1118
1140
 */
1119
1141
 
1120
1142
void
1182
1204
}
1183
1205
 
1184
1206
/*
1185
 
 * gui_completion_get_string: get a completion property as string
 
1207
 * Gets a completion property as string.
1186
1208
 */
1187
1209
 
1188
1210
const char *
1203
1225
}
1204
1226
 
1205
1227
/*
1206
 
 * gui_completion_hdata_completion_cb: return hdata for completion
 
1228
 * Returns hdata for completion.
1207
1229
 */
1208
1230
 
1209
1231
struct t_hdata *
1215
1237
    (void) data;
1216
1238
 
1217
1239
    hdata = hdata_new (NULL, hdata_name, NULL, NULL,
1218
 
                       0, NULL, NULL);
 
1240
                       0, 0, NULL, NULL);
1219
1241
    if (hdata)
1220
1242
    {
1221
1243
        HDATA_VAR(struct t_gui_completion, buffer, POINTER, 0, NULL, "buffer");
1242
1264
}
1243
1265
 
1244
1266
/*
1245
 
 * gui_completion_hdata_completion_partial_cb: return hdata for partial
1246
 
 *                                             completion
 
1267
 * Returns hdata for partial completion.
1247
1268
 */
1248
1269
 
1249
1270
struct t_hdata *
1255
1276
    (void) data;
1256
1277
 
1257
1278
    hdata = hdata_new (NULL, hdata_name, "prev_item", "next_item",
1258
 
                       0, NULL, NULL);
 
1279
                       0, 0, NULL, NULL);
1259
1280
    if (hdata)
1260
1281
    {
1261
1282
        HDATA_VAR(struct t_gui_completion_partial, word, STRING, 0, NULL, NULL);
1267
1288
}
1268
1289
 
1269
1290
/*
1270
 
 * gui_completion_print_log: print completion list in log (usually for crash dump)
 
1291
 * Prints completion list in WeeChat log file (usually for crash dump).
1271
1292
 */
1272
1293
 
1273
1294
void