2016-08-29 22:49:24 +02:00
|
|
|
/* vi:set ts=8 sts=4 sw=4 noet:
|
2004-06-13 20:20:40 +00:00
|
|
|
*
|
|
|
|
* VIM - Vi IMproved by Bram Moolenaar
|
|
|
|
*
|
|
|
|
* Do ":help uganda" in Vim to read copying and usage conditions.
|
|
|
|
* Do ":help credits" in Vim to see a list of people who contributed.
|
|
|
|
* See README.txt for an overview of the Vim source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_cmds2.c: some more functions for command line commands
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "vim.h"
|
|
|
|
#include "version.h"
|
|
|
|
|
2016-01-29 22:03:47 +01:00
|
|
|
static void cmd_source(char_u *fname, exarg_T *eap);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
2016-03-15 23:10:59 +01:00
|
|
|
# if defined(FEAT_TIMERS) || defined(PROTO)
|
|
|
|
static timer_T *first_timer = NULL;
|
2016-09-05 22:45:28 +02:00
|
|
|
static long last_timer_id = 0;
|
2016-03-15 23:10:59 +01:00
|
|
|
|
2019-05-08 21:59:25 +02:00
|
|
|
/*
|
|
|
|
* Return time left until "due". Negative if past "due".
|
|
|
|
*/
|
2018-05-10 18:05:56 +02:00
|
|
|
long
|
2017-11-18 18:52:04 +01:00
|
|
|
proftime_time_left(proftime_T *due, proftime_T *now)
|
2017-09-18 21:50:47 +02:00
|
|
|
{
|
2019-02-17 17:44:42 +01:00
|
|
|
# ifdef MSWIN
|
2017-09-18 21:50:47 +02:00
|
|
|
LARGE_INTEGER fr;
|
|
|
|
|
2017-11-18 18:52:04 +01:00
|
|
|
if (now->QuadPart > due->QuadPart)
|
2017-09-18 21:50:47 +02:00
|
|
|
return 0;
|
|
|
|
QueryPerformanceFrequency(&fr);
|
2017-11-18 18:52:04 +01:00
|
|
|
return (long)(((double)(due->QuadPart - now->QuadPart)
|
2017-09-18 21:50:47 +02:00
|
|
|
/ (double)fr.QuadPart) * 1000);
|
|
|
|
# else
|
2017-11-18 18:52:04 +01:00
|
|
|
if (now->tv_sec > due->tv_sec)
|
2017-09-18 21:50:47 +02:00
|
|
|
return 0;
|
2017-11-18 18:52:04 +01:00
|
|
|
return (due->tv_sec - now->tv_sec) * 1000
|
|
|
|
+ (due->tv_usec - now->tv_usec) / 1000;
|
2017-09-18 21:50:47 +02:00
|
|
|
# endif
|
|
|
|
}
|
2016-09-01 21:26:20 +02:00
|
|
|
|
2016-03-15 23:10:59 +01:00
|
|
|
/*
|
|
|
|
* Insert a timer in the list of timers.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
insert_timer(timer_T *timer)
|
|
|
|
{
|
|
|
|
timer->tr_next = first_timer;
|
|
|
|
timer->tr_prev = NULL;
|
|
|
|
if (first_timer != NULL)
|
|
|
|
first_timer->tr_prev = timer;
|
|
|
|
first_timer = timer;
|
2016-06-02 14:30:04 +02:00
|
|
|
did_add_timer = TRUE;
|
2016-03-15 23:10:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a timer out of the list of timers.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
remove_timer(timer_T *timer)
|
|
|
|
{
|
|
|
|
if (timer->tr_prev == NULL)
|
|
|
|
first_timer = timer->tr_next;
|
|
|
|
else
|
|
|
|
timer->tr_prev->tr_next = timer->tr_next;
|
|
|
|
if (timer->tr_next != NULL)
|
|
|
|
timer->tr_next->tr_prev = timer->tr_prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_timer(timer_T *timer)
|
|
|
|
{
|
2019-06-01 13:28:35 +02:00
|
|
|
free_callback(&timer->tr_callback);
|
2016-09-05 22:45:28 +02:00
|
|
|
vim_free(timer);
|
2016-03-15 23:10:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a timer and return it. NULL if out of memory.
|
|
|
|
* Caller should set the callback.
|
|
|
|
*/
|
|
|
|
timer_T *
|
|
|
|
create_timer(long msec, int repeat)
|
|
|
|
{
|
2019-05-28 23:08:19 +02:00
|
|
|
timer_T *timer = ALLOC_CLEAR_ONE(timer_T);
|
2016-09-10 19:17:42 +02:00
|
|
|
long prev_id = last_timer_id;
|
2016-03-15 23:10:59 +01:00
|
|
|
|
|
|
|
if (timer == NULL)
|
|
|
|
return NULL;
|
2016-09-10 19:17:42 +02:00
|
|
|
if (++last_timer_id <= prev_id)
|
2016-09-05 22:45:28 +02:00
|
|
|
/* Overflow! Might cause duplicates... */
|
|
|
|
last_timer_id = 0;
|
|
|
|
timer->tr_id = last_timer_id;
|
2016-03-15 23:10:59 +01:00
|
|
|
insert_timer(timer);
|
|
|
|
if (repeat != 0)
|
|
|
|
timer->tr_repeat = repeat - 1;
|
2016-08-06 22:05:07 +02:00
|
|
|
timer->tr_interval = msec;
|
2016-03-15 23:10:59 +01:00
|
|
|
|
|
|
|
profile_setlimit(msec, &timer->tr_due);
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Invoke the callback of "timer".
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
timer_callback(timer_T *timer)
|
|
|
|
{
|
|
|
|
typval_T rettv;
|
|
|
|
typval_T argv[2];
|
|
|
|
|
|
|
|
argv[0].v_type = VAR_NUMBER;
|
2016-09-05 22:45:28 +02:00
|
|
|
argv[0].vval.v_number = (varnumber_T)timer->tr_id;
|
2016-03-15 23:10:59 +01:00
|
|
|
argv[1].v_type = VAR_UNKNOWN;
|
|
|
|
|
2019-08-03 18:17:11 +02:00
|
|
|
call_callback(&timer->tr_callback, -1, &rettv, 1, argv);
|
2016-03-15 23:10:59 +01:00
|
|
|
clear_tv(&rettv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call timers that are due.
|
|
|
|
* Return the time in msec until the next timer is due.
|
2017-07-07 14:50:44 +02:00
|
|
|
* Returns -1 if there are no pending timers.
|
2016-03-15 23:10:59 +01:00
|
|
|
*/
|
|
|
|
long
|
2016-06-12 21:18:43 +02:00
|
|
|
check_due_timer(void)
|
2016-03-15 23:10:59 +01:00
|
|
|
{
|
|
|
|
timer_T *timer;
|
2016-09-05 22:45:28 +02:00
|
|
|
timer_T *timer_next;
|
2016-03-15 23:10:59 +01:00
|
|
|
long this_due;
|
2016-03-16 23:24:43 +01:00
|
|
|
long next_due = -1;
|
2016-03-15 23:10:59 +01:00
|
|
|
proftime_T now;
|
|
|
|
int did_one = FALSE;
|
2017-08-26 23:43:28 +02:00
|
|
|
int need_update_screen = FALSE;
|
2016-09-05 22:45:28 +02:00
|
|
|
long current_id = last_timer_id;
|
2016-03-15 23:10:59 +01:00
|
|
|
|
2017-07-08 22:37:34 +02:00
|
|
|
/* Don't run any timers while exiting or dealing with an error. */
|
|
|
|
if (exiting || aborting())
|
2017-07-07 14:50:44 +02:00
|
|
|
return next_due;
|
|
|
|
|
2016-09-05 22:45:28 +02:00
|
|
|
profile_start(&now);
|
|
|
|
for (timer = first_timer; timer != NULL && !got_int; timer = timer_next)
|
2016-03-15 23:10:59 +01:00
|
|
|
{
|
2016-09-05 22:45:28 +02:00
|
|
|
timer_next = timer->tr_next;
|
|
|
|
|
|
|
|
if (timer->tr_id == -1 || timer->tr_firing || timer->tr_paused)
|
|
|
|
continue;
|
2017-11-18 18:52:04 +01:00
|
|
|
this_due = proftime_time_left(&timer->tr_due, &now);
|
2016-09-05 22:45:28 +02:00
|
|
|
if (this_due <= 1)
|
2016-03-15 23:10:59 +01:00
|
|
|
{
|
2018-05-12 15:38:26 +02:00
|
|
|
/* Save and restore a lot of flags, because the timer fires while
|
|
|
|
* waiting for a character, which might be halfway a command. */
|
2017-06-24 16:03:06 +02:00
|
|
|
int save_timer_busy = timer_busy;
|
|
|
|
int save_vgetc_busy = vgetc_busy;
|
2017-09-06 23:40:10 +02:00
|
|
|
int save_did_emsg = did_emsg;
|
|
|
|
int save_called_emsg = called_emsg;
|
2019-06-25 06:28:02 +02:00
|
|
|
int save_must_redraw = must_redraw;
|
|
|
|
int save_trylevel = trylevel;
|
2017-09-06 23:40:10 +02:00
|
|
|
int save_did_throw = did_throw;
|
2017-09-14 22:55:37 +02:00
|
|
|
int save_ex_pressedreturn = get_pressedreturn();
|
2019-06-25 04:12:16 +02:00
|
|
|
int save_may_garbage_collect = may_garbage_collect;
|
2017-09-06 23:40:10 +02:00
|
|
|
except_T *save_current_exception = current_exception;
|
2018-05-12 15:38:26 +02:00
|
|
|
vimvars_save_T vvsave;
|
2017-06-24 16:03:06 +02:00
|
|
|
|
2017-09-06 23:40:10 +02:00
|
|
|
/* Create a scope for running the timer callback, ignoring most of
|
|
|
|
* the current scope, such as being inside a try/catch. */
|
2017-06-24 16:03:06 +02:00
|
|
|
timer_busy = timer_busy > 0 || vgetc_busy > 0;
|
|
|
|
vgetc_busy = 0;
|
2017-07-08 22:37:34 +02:00
|
|
|
called_emsg = FALSE;
|
2017-09-06 23:40:10 +02:00
|
|
|
did_emsg = FALSE;
|
|
|
|
did_uncaught_emsg = FALSE;
|
2017-08-26 23:43:28 +02:00
|
|
|
must_redraw = 0;
|
2017-09-06 23:40:10 +02:00
|
|
|
trylevel = 0;
|
|
|
|
did_throw = FALSE;
|
|
|
|
current_exception = NULL;
|
2019-06-25 04:12:16 +02:00
|
|
|
may_garbage_collect = FALSE;
|
2018-05-12 15:38:26 +02:00
|
|
|
save_vimvars(&vvsave);
|
2019-06-25 04:12:16 +02:00
|
|
|
|
2016-09-05 22:45:28 +02:00
|
|
|
timer->tr_firing = TRUE;
|
|
|
|
timer_callback(timer);
|
|
|
|
timer->tr_firing = FALSE;
|
2017-09-06 23:40:10 +02:00
|
|
|
|
2016-09-05 22:45:28 +02:00
|
|
|
timer_next = timer->tr_next;
|
|
|
|
did_one = TRUE;
|
2017-06-24 16:03:06 +02:00
|
|
|
timer_busy = save_timer_busy;
|
|
|
|
vgetc_busy = save_vgetc_busy;
|
2017-09-06 23:40:10 +02:00
|
|
|
if (did_uncaught_emsg)
|
2017-07-08 22:37:34 +02:00
|
|
|
++timer->tr_emsg_count;
|
2017-09-06 23:40:10 +02:00
|
|
|
did_emsg = save_did_emsg;
|
|
|
|
called_emsg = save_called_emsg;
|
|
|
|
trylevel = save_trylevel;
|
|
|
|
did_throw = save_did_throw;
|
|
|
|
current_exception = save_current_exception;
|
2018-05-12 15:38:26 +02:00
|
|
|
restore_vimvars(&vvsave);
|
2017-08-26 23:43:28 +02:00
|
|
|
if (must_redraw != 0)
|
|
|
|
need_update_screen = TRUE;
|
|
|
|
must_redraw = must_redraw > save_must_redraw
|
|
|
|
? must_redraw : save_must_redraw;
|
2017-09-14 22:55:37 +02:00
|
|
|
set_pressedreturn(save_ex_pressedreturn);
|
2019-06-25 04:12:16 +02:00
|
|
|
may_garbage_collect = save_may_garbage_collect;
|
2016-09-05 22:45:28 +02:00
|
|
|
|
|
|
|
/* Only fire the timer again if it repeats and stop_timer() wasn't
|
|
|
|
* called while inside the callback (tr_id == -1). */
|
2017-07-08 22:37:34 +02:00
|
|
|
if (timer->tr_repeat != 0 && timer->tr_id != -1
|
|
|
|
&& timer->tr_emsg_count < 3)
|
2016-03-15 23:10:59 +01:00
|
|
|
{
|
2016-09-05 22:45:28 +02:00
|
|
|
profile_setlimit(timer->tr_interval, &timer->tr_due);
|
2017-11-18 18:52:04 +01:00
|
|
|
this_due = proftime_time_left(&timer->tr_due, &now);
|
2016-09-05 22:45:28 +02:00
|
|
|
if (this_due < 1)
|
|
|
|
this_due = 1;
|
|
|
|
if (timer->tr_repeat > 0)
|
|
|
|
--timer->tr_repeat;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this_due = -1;
|
|
|
|
remove_timer(timer);
|
|
|
|
free_timer(timer);
|
2016-03-15 23:10:59 +01:00
|
|
|
}
|
|
|
|
}
|
2016-09-05 22:45:28 +02:00
|
|
|
if (this_due > 0 && (next_due == -1 || next_due > this_due))
|
|
|
|
next_due = this_due;
|
2016-03-15 23:10:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (did_one)
|
2017-08-26 23:43:28 +02:00
|
|
|
redraw_after_callback(need_update_screen);
|
2016-03-15 23:10:59 +01:00
|
|
|
|
2017-11-18 22:13:31 +01:00
|
|
|
#ifdef FEAT_BEVAL_TERM
|
2017-11-18 18:52:04 +01:00
|
|
|
if (bevalexpr_due_set)
|
|
|
|
{
|
|
|
|
this_due = proftime_time_left(&bevalexpr_due, &now);
|
|
|
|
if (this_due <= 1)
|
|
|
|
{
|
|
|
|
bevalexpr_due_set = FALSE;
|
|
|
|
if (balloonEval == NULL)
|
|
|
|
{
|
2019-05-28 23:08:19 +02:00
|
|
|
balloonEval = ALLOC_CLEAR_ONE(BalloonEval);
|
2017-11-18 18:52:04 +01:00
|
|
|
balloonEvalForTerm = TRUE;
|
|
|
|
}
|
|
|
|
if (balloonEval != NULL)
|
2019-05-08 21:59:25 +02:00
|
|
|
{
|
2017-11-18 18:52:04 +01:00
|
|
|
general_beval_cb(balloonEval, 0);
|
2019-05-08 21:59:25 +02:00
|
|
|
setcursor();
|
|
|
|
out_flush();
|
|
|
|
}
|
2017-11-18 18:52:04 +01:00
|
|
|
}
|
2018-04-24 15:19:04 +02:00
|
|
|
else if (next_due == -1 || next_due > this_due)
|
2017-11-18 18:52:04 +01:00
|
|
|
next_due = this_due;
|
|
|
|
}
|
|
|
|
#endif
|
2018-05-10 18:05:56 +02:00
|
|
|
#ifdef FEAT_TERMINAL
|
|
|
|
/* Some terminal windows may need their buffer updated. */
|
|
|
|
next_due = term_check_timers(next_due, &now);
|
|
|
|
#endif
|
2017-11-18 18:52:04 +01:00
|
|
|
|
2016-09-05 22:45:28 +02:00
|
|
|
return current_id != last_timer_id ? 1 : next_due;
|
2016-03-15 23:10:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a timer by ID. Returns NULL if not found;
|
|
|
|
*/
|
|
|
|
timer_T *
|
2016-09-05 22:45:28 +02:00
|
|
|
find_timer(long id)
|
2016-03-15 23:10:59 +01:00
|
|
|
{
|
|
|
|
timer_T *timer;
|
|
|
|
|
2016-09-05 22:45:28 +02:00
|
|
|
if (id >= 0)
|
|
|
|
{
|
|
|
|
for (timer = first_timer; timer != NULL; timer = timer->tr_next)
|
|
|
|
if (timer->tr_id == id)
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
return NULL;
|
2016-03-15 23:10:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop a timer and delete it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
stop_timer(timer_T *timer)
|
|
|
|
{
|
2016-09-05 22:45:28 +02:00
|
|
|
if (timer->tr_firing)
|
|
|
|
/* Free the timer after the callback returns. */
|
|
|
|
timer->tr_id = -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
remove_timer(timer);
|
|
|
|
free_timer(timer);
|
|
|
|
}
|
2016-03-15 23:10:59 +01:00
|
|
|
}
|
2016-05-31 21:13:04 +02:00
|
|
|
|
2016-08-07 18:22:53 +02:00
|
|
|
void
|
|
|
|
stop_all_timers(void)
|
|
|
|
{
|
2016-09-05 22:45:28 +02:00
|
|
|
timer_T *timer;
|
|
|
|
timer_T *timer_next;
|
|
|
|
|
|
|
|
for (timer = first_timer; timer != NULL; timer = timer_next)
|
|
|
|
{
|
|
|
|
timer_next = timer->tr_next;
|
|
|
|
stop_timer(timer);
|
|
|
|
}
|
2016-08-07 18:22:53 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 22:05:07 +02:00
|
|
|
void
|
|
|
|
add_timer_info(typval_T *rettv, timer_T *timer)
|
|
|
|
{
|
|
|
|
list_T *list = rettv->vval.v_list;
|
|
|
|
dict_T *dict = dict_alloc();
|
|
|
|
dictitem_T *di;
|
|
|
|
long remaining;
|
|
|
|
proftime_T now;
|
|
|
|
|
|
|
|
if (dict == NULL)
|
|
|
|
return;
|
|
|
|
list_append_dict(list, dict);
|
|
|
|
|
2018-07-08 16:50:37 +02:00
|
|
|
dict_add_number(dict, "id", timer->tr_id);
|
|
|
|
dict_add_number(dict, "time", (long)timer->tr_interval);
|
2016-08-06 22:05:07 +02:00
|
|
|
|
|
|
|
profile_start(&now);
|
2017-11-18 18:52:04 +01:00
|
|
|
remaining = proftime_time_left(&timer->tr_due, &now);
|
2018-07-08 16:50:37 +02:00
|
|
|
dict_add_number(dict, "remaining", (long)remaining);
|
2016-08-06 22:05:07 +02:00
|
|
|
|
2018-07-08 16:50:37 +02:00
|
|
|
dict_add_number(dict, "repeat",
|
|
|
|
(long)(timer->tr_repeat < 0 ? -1 : timer->tr_repeat + 1));
|
|
|
|
dict_add_number(dict, "paused", (long)(timer->tr_paused));
|
2016-08-06 22:05:07 +02:00
|
|
|
|
|
|
|
di = dictitem_alloc((char_u *)"callback");
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
if (dict_add(dict, di) == FAIL)
|
|
|
|
vim_free(di);
|
|
|
|
else
|
2019-06-01 13:28:35 +02:00
|
|
|
put_callback(&timer->tr_callback, &di->di_tv);
|
2016-08-06 22:05:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_timer_info_all(typval_T *rettv)
|
|
|
|
{
|
|
|
|
timer_T *timer;
|
|
|
|
|
|
|
|
for (timer = first_timer; timer != NULL; timer = timer->tr_next)
|
2016-09-05 22:45:28 +02:00
|
|
|
if (timer->tr_id != -1)
|
|
|
|
add_timer_info(rettv, timer);
|
2016-08-06 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
2016-05-31 21:13:04 +02:00
|
|
|
/*
|
|
|
|
* Mark references in partials of timers.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
set_ref_in_timer(int copyID)
|
|
|
|
{
|
|
|
|
int abort = FALSE;
|
|
|
|
timer_T *timer;
|
|
|
|
typval_T tv;
|
|
|
|
|
2019-06-20 03:45:36 +02:00
|
|
|
for (timer = first_timer; !abort && timer != NULL; timer = timer->tr_next)
|
2016-05-31 21:13:04 +02:00
|
|
|
{
|
2019-06-01 13:28:35 +02:00
|
|
|
if (timer->tr_callback.cb_partial != NULL)
|
2016-07-29 22:15:09 +02:00
|
|
|
{
|
|
|
|
tv.v_type = VAR_PARTIAL;
|
2019-06-01 13:28:35 +02:00
|
|
|
tv.vval.v_partial = timer->tr_callback.cb_partial;
|
2016-07-29 22:15:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tv.v_type = VAR_FUNC;
|
2019-06-01 13:28:35 +02:00
|
|
|
tv.vval.v_string = timer->tr_callback.cb_name;
|
2016-07-29 22:15:09 +02:00
|
|
|
}
|
2016-05-31 21:13:04 +02:00
|
|
|
abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
|
|
|
|
}
|
|
|
|
return abort;
|
|
|
|
}
|
2016-07-30 22:47:56 +02:00
|
|
|
|
|
|
|
# if defined(EXITFREE) || defined(PROTO)
|
|
|
|
void
|
|
|
|
timer_free_all()
|
|
|
|
{
|
|
|
|
timer_T *timer;
|
|
|
|
|
|
|
|
while (first_timer != NULL)
|
|
|
|
{
|
|
|
|
timer = first_timer;
|
|
|
|
remove_timer(timer);
|
|
|
|
free_timer(timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
2016-03-15 23:10:59 +01:00
|
|
|
# endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If 'autowrite' option set, try to write the file.
|
|
|
|
* Careful: autocommands may make "buf" invalid!
|
|
|
|
*
|
|
|
|
* return FAIL for failure, OK otherwise
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
autowrite(buf_T *buf, int forceit)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2007-02-13 05:19:30 +00:00
|
|
|
int r;
|
2016-07-10 22:11:16 +02:00
|
|
|
bufref_T bufref;
|
2007-02-13 05:19:30 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
if (!(p_aw || p_awa) || !p_write
|
|
|
|
#ifdef FEAT_QUICKFIX
|
2007-02-13 05:19:30 +00:00
|
|
|
/* never autowrite a "nofile" or "nowrite" buffer */
|
|
|
|
|| bt_dontwrite(buf)
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
2007-02-13 05:19:30 +00:00
|
|
|
|| (!forceit && buf->b_p_ro) || buf->b_ffname == NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
return FAIL;
|
2016-07-10 22:11:16 +02:00
|
|
|
set_bufref(&bufref, buf);
|
2007-02-13 05:19:30 +00:00
|
|
|
r = buf_write_all(buf, forceit);
|
|
|
|
|
|
|
|
/* Writing may succeed but the buffer still changed, e.g., when there is a
|
|
|
|
* conversion error. We do want to return FAIL then. */
|
2016-07-10 22:11:16 +02:00
|
|
|
if (bufref_valid(&bufref) && bufIsChanged(buf))
|
2007-02-13 05:19:30 +00:00
|
|
|
r = FAIL;
|
|
|
|
return r;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-08-30 13:07:17 +02:00
|
|
|
* Flush all buffers, except the ones that are readonly or are never written.
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
autowrite_all(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
buf_T *buf;
|
|
|
|
|
|
|
|
if (!(p_aw || p_awa) || !p_write)
|
|
|
|
return;
|
2016-07-24 22:04:11 +02:00
|
|
|
FOR_ALL_BUFFERS(buf)
|
2018-08-30 13:07:17 +02:00
|
|
|
if (bufIsChanged(buf) && !buf->b_p_ro && !bt_dontwrite(buf))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2016-07-10 22:11:16 +02:00
|
|
|
bufref_T bufref;
|
|
|
|
|
|
|
|
set_bufref(&bufref, buf);
|
2018-03-04 18:08:14 +01:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
(void)buf_write_all(buf, FALSE);
|
2018-03-04 18:08:14 +01:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* an autocommand may have deleted the buffer */
|
2016-07-10 22:11:16 +02:00
|
|
|
if (!bufref_valid(&bufref))
|
2004-06-13 20:20:40 +00:00
|
|
|
buf = firstbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-11-09 03:31:51 +01:00
|
|
|
* Return TRUE if buffer was changed and cannot be abandoned.
|
|
|
|
* For flags use the CCGD_ values.
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
check_changed(buf_T *buf, int flags)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2016-07-10 22:11:16 +02:00
|
|
|
int forceit = (flags & CCGD_FORCEIT);
|
|
|
|
bufref_T bufref;
|
|
|
|
|
|
|
|
set_bufref(&bufref, buf);
|
2013-11-09 03:31:51 +01:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
if ( !forceit
|
|
|
|
&& bufIsChanged(buf)
|
2013-11-09 03:31:51 +01:00
|
|
|
&& ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1)
|
|
|
|
&& (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
|
|
|
|
if ((p_confirm || cmdmod.confirm) && p_write)
|
|
|
|
{
|
|
|
|
buf_T *buf2;
|
|
|
|
int count = 0;
|
|
|
|
|
2013-11-09 03:31:51 +01:00
|
|
|
if (flags & CCGD_ALLBUF)
|
2016-07-24 22:04:11 +02:00
|
|
|
FOR_ALL_BUFFERS(buf2)
|
2004-06-13 20:20:40 +00:00
|
|
|
if (bufIsChanged(buf2)
|
|
|
|
&& (buf2->b_ffname != NULL
|
|
|
|
# ifdef FEAT_BROWSE
|
|
|
|
|| cmdmod.browse
|
|
|
|
# endif
|
|
|
|
))
|
|
|
|
++count;
|
2016-07-10 22:11:16 +02:00
|
|
|
if (!bufref_valid(&bufref))
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Autocommand deleted buffer, oops! It's not changed now. */
|
|
|
|
return FALSE;
|
2018-03-04 18:08:14 +01:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
dialog_changed(buf, count > 1);
|
2018-03-04 18:08:14 +01:00
|
|
|
|
2016-07-10 22:11:16 +02:00
|
|
|
if (!bufref_valid(&bufref))
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Autocommand deleted buffer, oops! It's not changed now. */
|
|
|
|
return FALSE;
|
|
|
|
return bufIsChanged(buf);
|
|
|
|
}
|
|
|
|
#endif
|
2013-11-09 03:31:51 +01:00
|
|
|
if (flags & CCGD_EXCMD)
|
2017-08-17 16:55:13 +02:00
|
|
|
no_write_message();
|
2013-11-09 03:31:51 +01:00
|
|
|
else
|
2018-02-19 23:10:02 +01:00
|
|
|
no_write_message_nobang(curbuf);
|
2004-06-13 20:20:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) || defined(PROTO)
|
|
|
|
|
|
|
|
#if defined(FEAT_BROWSE) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* When wanting to write a file without a file name, ask the user for a name.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
browse_save_fname(buf_T *buf)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (buf->b_fname == NULL)
|
|
|
|
{
|
|
|
|
char_u *fname;
|
|
|
|
|
2004-10-11 10:16:09 +00:00
|
|
|
fname = do_browse(BROWSE_SAVE, (char_u *)_("Save As"),
|
|
|
|
NULL, NULL, NULL, NULL, buf);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (fname != NULL)
|
|
|
|
{
|
|
|
|
if (setfname(buf, fname, NULL, TRUE) == OK)
|
|
|
|
buf->b_flags |= BF_NOTEDITED;
|
|
|
|
vim_free(fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2011-05-19 18:26:40 +02:00
|
|
|
* Ask the user what to do when abandoning a changed buffer.
|
2004-06-13 20:20:40 +00:00
|
|
|
* Must check 'write' option first!
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
dialog_changed(
|
|
|
|
buf_T *buf,
|
|
|
|
int checkall) /* may abandon all changed buffers */
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2011-04-11 21:35:11 +02:00
|
|
|
char_u buff[DIALOG_MSG_SIZE];
|
2004-06-13 20:20:40 +00:00
|
|
|
int ret;
|
|
|
|
buf_T *buf2;
|
2012-04-25 17:32:18 +02:00
|
|
|
exarg_T ea;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2017-08-21 22:06:02 +02:00
|
|
|
dialog_msg(buff, _("Save changes to \"%s\"?"), buf->b_fname);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (checkall)
|
|
|
|
ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1);
|
|
|
|
else
|
|
|
|
ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1);
|
|
|
|
|
2019-05-09 21:48:37 +02:00
|
|
|
// Init ea pseudo-structure, this is needed for the check_overwrite()
|
|
|
|
// function.
|
|
|
|
vim_memset(&ea, 0, sizeof(ea));
|
2012-04-25 17:32:18 +02:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
if (ret == VIM_YES)
|
|
|
|
{
|
|
|
|
#ifdef FEAT_BROWSE
|
|
|
|
/* May get file name, when there is none */
|
|
|
|
browse_save_fname(buf);
|
|
|
|
#endif
|
2012-04-25 17:32:18 +02:00
|
|
|
if (buf->b_fname != NULL && check_overwrite(&ea, buf,
|
|
|
|
buf->b_fname, buf->b_ffname, FALSE) == OK)
|
|
|
|
/* didn't hit Cancel */
|
2004-06-13 20:20:40 +00:00
|
|
|
(void)buf_write_all(buf, FALSE);
|
|
|
|
}
|
|
|
|
else if (ret == VIM_NO)
|
|
|
|
{
|
2019-06-08 18:07:21 +02:00
|
|
|
unchanged(buf, TRUE, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else if (ret == VIM_ALL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Write all modified files that can be written.
|
|
|
|
* Skip readonly buffers, these need to be confirmed
|
|
|
|
* individually.
|
|
|
|
*/
|
2016-07-24 22:04:11 +02:00
|
|
|
FOR_ALL_BUFFERS(buf2)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (bufIsChanged(buf2)
|
|
|
|
&& (buf2->b_ffname != NULL
|
|
|
|
#ifdef FEAT_BROWSE
|
|
|
|
|| cmdmod.browse
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
&& !buf2->b_p_ro)
|
|
|
|
{
|
2016-07-10 22:11:16 +02:00
|
|
|
bufref_T bufref;
|
|
|
|
|
|
|
|
set_bufref(&bufref, buf2);
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_BROWSE
|
|
|
|
/* May get file name, when there is none */
|
|
|
|
browse_save_fname(buf2);
|
|
|
|
#endif
|
2012-04-25 17:32:18 +02:00
|
|
|
if (buf2->b_fname != NULL && check_overwrite(&ea, buf2,
|
|
|
|
buf2->b_fname, buf2->b_ffname, FALSE) == OK)
|
|
|
|
/* didn't hit Cancel */
|
2004-06-13 20:20:40 +00:00
|
|
|
(void)buf_write_all(buf2, FALSE);
|
2018-03-04 18:08:14 +01:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* an autocommand may have deleted the buffer */
|
2016-07-10 22:11:16 +02:00
|
|
|
if (!bufref_valid(&bufref))
|
2004-06-13 20:20:40 +00:00
|
|
|
buf2 = firstbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ret == VIM_DISCARDALL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* mark all buffers as unchanged
|
|
|
|
*/
|
2016-07-24 22:04:11 +02:00
|
|
|
FOR_ALL_BUFFERS(buf2)
|
2019-06-08 18:07:21 +02:00
|
|
|
unchanged(buf2, TRUE, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return TRUE if the buffer "buf" can be abandoned, either by making it
|
|
|
|
* hidden, autowriting it or unloading it.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
can_abandon(buf_T *buf, int forceit)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2017-08-03 22:44:55 +02:00
|
|
|
return ( buf_hide(buf)
|
2004-06-13 20:20:40 +00:00
|
|
|
|| !bufIsChanged(buf)
|
|
|
|
|| buf->b_nwindows > 1
|
|
|
|
|| autowrite(buf, forceit) == OK
|
|
|
|
|| forceit);
|
|
|
|
}
|
|
|
|
|
2012-03-23 18:39:18 +01:00
|
|
|
/*
|
|
|
|
* Add a buffer number to "bufnrs", unless it's already there.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
add_bufnum(int *bufnrs, int *bufnump, int nr)
|
2012-03-23 18:39:18 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < *bufnump; ++i)
|
|
|
|
if (bufnrs[i] == nr)
|
|
|
|
return;
|
|
|
|
bufnrs[*bufnump] = nr;
|
|
|
|
*bufnump = *bufnump + 1;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Return TRUE if any buffer was changed and cannot be abandoned.
|
|
|
|
* That changed buffer becomes the current buffer.
|
2018-03-10 20:28:12 +01:00
|
|
|
* When "unload" is TRUE the current buffer is unloaded instead of making it
|
2016-01-02 22:25:52 +01:00
|
|
|
* hidden. This is used for ":q!".
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
check_changed_any(
|
|
|
|
int hidden, /* Only check hidden buffers */
|
|
|
|
int unload)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2012-03-23 18:39:18 +01:00
|
|
|
int ret = FALSE;
|
2004-06-13 20:20:40 +00:00
|
|
|
buf_T *buf;
|
|
|
|
int save;
|
2012-03-23 18:39:18 +01:00
|
|
|
int i;
|
|
|
|
int bufnum = 0;
|
|
|
|
int bufcount = 0;
|
|
|
|
int *bufnrs;
|
|
|
|
tabpage_T *tp;
|
2004-06-13 20:20:40 +00:00
|
|
|
win_T *wp;
|
|
|
|
|
2018-03-10 20:28:12 +01:00
|
|
|
/* Make a list of all buffers, with the most important ones first. */
|
2016-07-24 22:04:11 +02:00
|
|
|
FOR_ALL_BUFFERS(buf)
|
2012-03-23 18:39:18 +01:00
|
|
|
++bufcount;
|
|
|
|
|
|
|
|
if (bufcount == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-05-28 23:08:19 +02:00
|
|
|
bufnrs = ALLOC_MULT(int, bufcount);
|
2012-03-23 18:39:18 +01:00
|
|
|
if (bufnrs == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* curbuf */
|
|
|
|
bufnrs[bufnum++] = curbuf->b_fnum;
|
2018-03-10 20:28:12 +01:00
|
|
|
|
|
|
|
/* buffers in current tab */
|
2012-03-23 18:39:18 +01:00
|
|
|
FOR_ALL_WINDOWS(wp)
|
|
|
|
if (wp->w_buffer != curbuf)
|
|
|
|
add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
|
|
|
|
|
2018-03-10 20:28:12 +01:00
|
|
|
/* buffers in other tabs */
|
2016-07-24 22:04:11 +02:00
|
|
|
FOR_ALL_TABPAGES(tp)
|
2012-03-23 18:39:18 +01:00
|
|
|
if (tp != curtab)
|
|
|
|
for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
|
|
|
|
add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
|
2018-03-10 20:28:12 +01:00
|
|
|
|
|
|
|
/* any other buffer */
|
2016-07-24 22:04:11 +02:00
|
|
|
FOR_ALL_BUFFERS(buf)
|
2012-03-23 18:39:18 +01:00
|
|
|
add_bufnum(bufnrs, &bufnum, buf->b_fnum);
|
|
|
|
|
|
|
|
for (i = 0; i < bufnum; ++i)
|
|
|
|
{
|
|
|
|
buf = buflist_findnr(bufnrs[i]);
|
|
|
|
if (buf == NULL)
|
|
|
|
continue;
|
|
|
|
if ((!hidden || buf->b_nwindows == 0) && bufIsChanged(buf))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2016-07-10 22:11:16 +02:00
|
|
|
bufref_T bufref;
|
|
|
|
|
|
|
|
set_bufref(&bufref, buf);
|
2018-03-10 20:28:12 +01:00
|
|
|
#ifdef FEAT_TERMINAL
|
|
|
|
if (term_job_running(buf->b_term))
|
|
|
|
{
|
|
|
|
if (term_try_stop_job(buf) == FAIL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2012-03-23 18:39:18 +01:00
|
|
|
/* Try auto-writing the buffer. If this fails but the buffer no
|
2019-04-04 18:15:38 +02:00
|
|
|
* longer exists it's not changed, that's OK. */
|
2013-11-09 03:31:51 +01:00
|
|
|
if (check_changed(buf, (p_awa ? CCGD_AW : 0)
|
|
|
|
| CCGD_MULTWIN
|
2016-07-10 22:11:16 +02:00
|
|
|
| CCGD_ALLBUF) && bufref_valid(&bufref))
|
2012-03-23 18:39:18 +01:00
|
|
|
break; /* didn't save - still changes */
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-23 18:39:18 +01:00
|
|
|
if (i >= bufnum)
|
|
|
|
goto theend;
|
|
|
|
|
2018-03-10 20:28:12 +01:00
|
|
|
/* Get here if "buf" cannot be abandoned. */
|
2012-03-23 18:39:18 +01:00
|
|
|
ret = TRUE;
|
2004-06-13 20:20:40 +00:00
|
|
|
exiting = FALSE;
|
|
|
|
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
|
|
|
|
/*
|
|
|
|
* When ":confirm" used, don't give an error message.
|
|
|
|
*/
|
|
|
|
if (!(p_confirm || cmdmod.confirm))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* There must be a wait_return for this message, do_buffer()
|
|
|
|
* may cause a redraw. But wait_return() is a no-op when vgetc()
|
|
|
|
* is busy (Quit used from window menu), then make sure we don't
|
|
|
|
* cause a scroll up. */
|
2006-04-07 21:40:07 +00:00
|
|
|
if (vgetc_busy > 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
msg_row = cmdline_row;
|
|
|
|
msg_col = 0;
|
|
|
|
msg_didout = FALSE;
|
|
|
|
}
|
2017-08-03 22:44:55 +02:00
|
|
|
if (
|
|
|
|
#ifdef FEAT_TERMINAL
|
|
|
|
term_job_running(buf->b_term)
|
2019-01-13 23:38:42 +01:00
|
|
|
? semsg(_("E947: Job still running in buffer \"%s\""),
|
2017-08-03 22:44:55 +02:00
|
|
|
buf->b_fname)
|
|
|
|
:
|
|
|
|
#endif
|
2019-01-13 23:38:42 +01:00
|
|
|
semsg(_("E162: No write since last change for buffer \"%s\""),
|
2012-10-03 18:25:00 +02:00
|
|
|
buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
save = no_wait_return;
|
|
|
|
no_wait_return = FALSE;
|
|
|
|
wait_return(FALSE);
|
|
|
|
no_wait_return = save;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find a window that contains the buffer. */
|
|
|
|
if (buf != curbuf)
|
2012-03-23 18:39:18 +01:00
|
|
|
FOR_ALL_TAB_WINDOWS(tp, wp)
|
2004-06-13 20:20:40 +00:00
|
|
|
if (wp->w_buffer == buf)
|
|
|
|
{
|
2016-07-10 22:11:16 +02:00
|
|
|
bufref_T bufref;
|
|
|
|
|
|
|
|
set_bufref(&bufref, buf);
|
2018-03-04 18:08:14 +01:00
|
|
|
|
2012-03-23 18:39:18 +01:00
|
|
|
goto_tabpage_win(tp, wp);
|
2018-03-04 18:08:14 +01:00
|
|
|
|
2019-03-02 10:13:42 +01:00
|
|
|
// Paranoia: did autocmd wipe out the buffer with changes?
|
2016-07-10 22:11:16 +02:00
|
|
|
if (!bufref_valid(&bufref))
|
2012-03-23 18:39:18 +01:00
|
|
|
goto theend;
|
|
|
|
goto buf_found;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2012-03-23 18:39:18 +01:00
|
|
|
buf_found:
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Open the changed buffer in the current window. */
|
|
|
|
if (buf != curbuf)
|
2016-01-02 22:25:52 +01:00
|
|
|
set_curbuf(buf, unload ? DOBUF_UNLOAD : DOBUF_GOTO);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2012-03-23 18:39:18 +01:00
|
|
|
theend:
|
|
|
|
vim_free(bufnrs);
|
|
|
|
return ret;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return FAIL if there is no file name, OK if there is one
|
|
|
|
* give error message for FAIL
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
check_fname(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (curbuf->b_ffname == NULL)
|
|
|
|
{
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_(e_noname));
|
2004-06-13 20:20:40 +00:00
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flush the contents of a buffer, unless it has no file name
|
|
|
|
*
|
|
|
|
* return FAIL for failure, OK otherwise
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
buf_write_all(buf_T *buf, int forceit)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
buf_T *old_curbuf = curbuf;
|
|
|
|
|
|
|
|
retval = (buf_write(buf, buf->b_ffname, buf->b_fname,
|
|
|
|
(linenr_T)1, buf->b_ml.ml_line_count, NULL,
|
|
|
|
FALSE, forceit, TRUE, FALSE));
|
|
|
|
if (curbuf != old_curbuf)
|
2004-07-12 15:53:54 +00:00
|
|
|
{
|
2017-03-16 17:23:31 +01:00
|
|
|
msg_source(HL_ATTR(HLF_W));
|
2019-01-19 17:43:09 +01:00
|
|
|
msg(_("Warning: Entered other buffer unexpectedly (check autocommands)"));
|
2004-07-12 15:53:54 +00:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-09-08 18:46:31 +02:00
|
|
|
* ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo"
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ex_listdo(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
2006-02-24 23:53:04 +00:00
|
|
|
win_T *wp;
|
|
|
|
tabpage_T *tp;
|
2015-02-27 20:33:37 +01:00
|
|
|
buf_T *buf = curbuf;
|
2004-06-13 20:20:40 +00:00
|
|
|
int next_fnum = 0;
|
2018-03-04 18:08:14 +01:00
|
|
|
#if defined(FEAT_SYN_HL)
|
2004-06-13 20:20:40 +00:00
|
|
|
char_u *save_ei = NULL;
|
|
|
|
#endif
|
2004-12-19 22:46:22 +00:00
|
|
|
char_u *p_shm_save;
|
2015-09-08 18:46:31 +02:00
|
|
|
#ifdef FEAT_QUICKFIX
|
2015-09-09 22:35:29 +02:00
|
|
|
int qf_size = 0;
|
2015-09-08 18:46:31 +02:00
|
|
|
int qf_idx;
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2016-02-23 18:55:43 +01:00
|
|
|
#ifndef FEAT_QUICKFIX
|
|
|
|
if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo ||
|
|
|
|
eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
|
|
|
|
{
|
|
|
|
ex_ni(eap);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-04 18:08:14 +01:00
|
|
|
#if defined(FEAT_SYN_HL)
|
2006-04-05 20:41:53 +00:00
|
|
|
if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo)
|
2019-08-03 13:29:46 +02:00
|
|
|
{
|
2005-01-21 11:55:25 +00:00
|
|
|
/* Don't do syntax HL autocommands. Skipping the syntax file is a
|
|
|
|
* great speed improvement. */
|
|
|
|
save_ei = au_event_disable(",Syntax");
|
2019-08-03 13:29:46 +02:00
|
|
|
|
|
|
|
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
|
|
|
buf->b_flags &= ~BF_SYN_SET;
|
|
|
|
buf = curbuf;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
2014-08-06 18:17:11 +02:00
|
|
|
#ifdef FEAT_CLIPBOARD
|
|
|
|
start_global_changes();
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (eap->cmdidx == CMD_windo
|
2006-02-24 23:53:04 +00:00
|
|
|
|| eap->cmdidx == CMD_tabdo
|
2017-08-03 22:44:55 +02:00
|
|
|
|| buf_hide(curbuf)
|
2013-11-09 03:31:51 +01:00
|
|
|
|| !check_changed(curbuf, CCGD_AW
|
|
|
|
| (eap->forceit ? CCGD_FORCEIT : 0)
|
|
|
|
| CCGD_EXCMD))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
i = 0;
|
2015-01-07 16:54:21 +01:00
|
|
|
/* start at the eap->line1 argument/window/buffer */
|
2006-02-24 23:53:04 +00:00
|
|
|
wp = firstwin;
|
|
|
|
tp = first_tabpage;
|
2015-01-07 16:54:21 +01:00
|
|
|
switch (eap->cmdidx)
|
|
|
|
{
|
|
|
|
case CMD_windo:
|
|
|
|
for ( ; wp != NULL && i + 1 < eap->line1; wp = wp->w_next)
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
case CMD_tabdo:
|
|
|
|
for( ; tp != NULL && i + 1 < eap->line1; tp = tp->tp_next)
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
case CMD_argdo:
|
|
|
|
i = eap->line1 - 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
/* set pcmark now */
|
|
|
|
if (eap->cmdidx == CMD_bufdo)
|
2015-09-08 18:46:31 +02:00
|
|
|
{
|
2015-02-27 20:33:37 +01:00
|
|
|
/* Advance to the first listed buffer after "eap->line1". */
|
2015-09-08 18:46:31 +02:00
|
|
|
for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1
|
2015-02-27 20:33:37 +01:00
|
|
|
|| !buf->b_p_bl); buf = buf->b_next)
|
|
|
|
if (buf->b_fnum > eap->line2)
|
|
|
|
{
|
|
|
|
buf = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2015-09-08 18:46:31 +02:00
|
|
|
if (buf != NULL)
|
2015-02-27 20:33:37 +01:00
|
|
|
goto_buffer(eap, DOBUF_FIRST, FORWARD, buf->b_fnum);
|
2015-09-08 18:46:31 +02:00
|
|
|
}
|
|
|
|
#ifdef FEAT_QUICKFIX
|
|
|
|
else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo
|
|
|
|
|| eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
|
|
|
|
{
|
2019-05-04 15:05:28 +02:00
|
|
|
qf_size = qf_get_valid_size(eap);
|
2015-09-08 18:46:31 +02:00
|
|
|
if (qf_size <= 0 || eap->line1 > qf_size)
|
|
|
|
buf = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ex_cc(eap);
|
|
|
|
|
|
|
|
buf = curbuf;
|
|
|
|
i = eap->line1 - 1;
|
|
|
|
if (eap->addr_count <= 0)
|
|
|
|
/* default is all the quickfix/location list entries */
|
|
|
|
eap->line2 = qf_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
setpcmark();
|
|
|
|
listcmd_busy = TRUE; /* avoids setting pcmark below */
|
|
|
|
|
2015-02-27 20:33:37 +01:00
|
|
|
while (!got_int && buf != NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (eap->cmdidx == CMD_argdo)
|
|
|
|
{
|
|
|
|
/* go to argument "i" */
|
|
|
|
if (i == ARGCOUNT)
|
|
|
|
break;
|
|
|
|
/* Don't call do_argfile() when already there, it will try
|
|
|
|
* reloading the file. */
|
2004-09-02 19:12:26 +00:00
|
|
|
if (curwin->w_arg_idx != i || !editing_arg_idx(curwin))
|
2004-12-19 22:46:22 +00:00
|
|
|
{
|
|
|
|
/* Clear 'shm' to avoid that the file message overwrites
|
|
|
|
* any output from the command. */
|
|
|
|
p_shm_save = vim_strsave(p_shm);
|
|
|
|
set_option_value((char_u *)"shm", 0L, (char_u *)"", 0);
|
2004-06-13 20:20:40 +00:00
|
|
|
do_argfile(eap, i);
|
2004-12-19 22:46:22 +00:00
|
|
|
set_option_value((char_u *)"shm", 0L, p_shm_save, 0);
|
|
|
|
vim_free(p_shm_save);
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
if (curwin->w_arg_idx != i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (eap->cmdidx == CMD_windo)
|
|
|
|
{
|
2006-02-24 23:53:04 +00:00
|
|
|
/* go to window "wp" */
|
|
|
|
if (!win_valid(wp))
|
|
|
|
break;
|
|
|
|
win_goto(wp);
|
2007-05-03 20:11:13 +00:00
|
|
|
if (curwin != wp)
|
|
|
|
break; /* something must be wrong */
|
2006-02-24 23:53:04 +00:00
|
|
|
wp = curwin->w_next;
|
|
|
|
}
|
|
|
|
else if (eap->cmdidx == CMD_tabdo)
|
|
|
|
{
|
|
|
|
/* go to window "tp" */
|
|
|
|
if (!valid_tabpage(tp))
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
2013-05-06 04:50:35 +02:00
|
|
|
goto_tabpage_tp(tp, TRUE, TRUE);
|
2006-02-24 23:53:04 +00:00
|
|
|
tp = tp->tp_next;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else if (eap->cmdidx == CMD_bufdo)
|
|
|
|
{
|
|
|
|
/* Remember the number of the next listed buffer, in case
|
|
|
|
* ":bwipe" is used or autocommands do something strange. */
|
|
|
|
next_fnum = -1;
|
|
|
|
for (buf = curbuf->b_next; buf != NULL; buf = buf->b_next)
|
|
|
|
if (buf->b_p_bl)
|
|
|
|
{
|
|
|
|
next_fnum = buf->b_fnum;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 16:54:21 +01:00
|
|
|
++i;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* execute the command */
|
|
|
|
do_cmdline(eap->arg, eap->getline, eap->cookie,
|
|
|
|
DOCMD_VERBOSE + DOCMD_NOWAIT);
|
|
|
|
|
|
|
|
if (eap->cmdidx == CMD_bufdo)
|
|
|
|
{
|
|
|
|
/* Done? */
|
2015-01-07 16:54:21 +01:00
|
|
|
if (next_fnum < 0 || next_fnum > eap->line2)
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
/* Check if the buffer still exists. */
|
2016-07-24 22:04:11 +02:00
|
|
|
FOR_ALL_BUFFERS(buf)
|
2004-06-13 20:20:40 +00:00
|
|
|
if (buf->b_fnum == next_fnum)
|
|
|
|
break;
|
|
|
|
if (buf == NULL)
|
|
|
|
break;
|
2004-12-19 22:46:22 +00:00
|
|
|
|
|
|
|
/* Go to the next buffer. Clear 'shm' to avoid that the file
|
|
|
|
* message overwrites any output from the command. */
|
|
|
|
p_shm_save = vim_strsave(p_shm);
|
|
|
|
set_option_value((char_u *)"shm", 0L, (char_u *)"", 0);
|
2004-06-13 20:20:40 +00:00
|
|
|
goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum);
|
2004-12-19 22:46:22 +00:00
|
|
|
set_option_value((char_u *)"shm", 0L, p_shm_save, 0);
|
|
|
|
vim_free(p_shm_save);
|
|
|
|
|
2015-09-08 18:46:31 +02:00
|
|
|
/* If autocommands took us elsewhere, quit here. */
|
2004-06-13 20:20:40 +00:00
|
|
|
if (curbuf->b_fnum != next_fnum)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-08 18:46:31 +02:00
|
|
|
#ifdef FEAT_QUICKFIX
|
|
|
|
if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo
|
|
|
|
|| eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
|
|
|
|
{
|
|
|
|
if (i >= qf_size || i >= eap->line2)
|
|
|
|
break;
|
|
|
|
|
|
|
|
qf_idx = qf_get_cur_idx(eap);
|
|
|
|
|
|
|
|
ex_cnext(eap);
|
|
|
|
|
|
|
|
/* If jumping to the next quickfix entry fails, quit here */
|
|
|
|
if (qf_get_cur_idx(eap) == qf_idx)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
if (eap->cmdidx == CMD_windo)
|
|
|
|
{
|
|
|
|
validate_cursor(); /* cursor may have moved */
|
2018-03-04 20:14:14 +01:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* required when 'scrollbind' has been set */
|
|
|
|
if (curwin->w_p_scb)
|
|
|
|
do_check_scrollbind(TRUE);
|
|
|
|
}
|
2015-01-07 16:54:21 +01:00
|
|
|
|
|
|
|
if (eap->cmdidx == CMD_windo || eap->cmdidx == CMD_tabdo)
|
|
|
|
if (i+1 > eap->line2)
|
|
|
|
break;
|
|
|
|
if (eap->cmdidx == CMD_argdo && i >= eap->line2)
|
|
|
|
break;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
listcmd_busy = FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-04 18:08:14 +01:00
|
|
|
#if defined(FEAT_SYN_HL)
|
2005-02-02 23:07:25 +00:00
|
|
|
if (save_ei != NULL)
|
|
|
|
{
|
2019-08-03 13:29:46 +02:00
|
|
|
buf_T *bnext;
|
|
|
|
aco_save_T aco;
|
|
|
|
|
2005-02-02 23:07:25 +00:00
|
|
|
au_event_restore(save_ei);
|
2019-08-03 13:29:46 +02:00
|
|
|
|
|
|
|
for (buf = firstbuf; buf != NULL; buf = bnext)
|
|
|
|
{
|
|
|
|
bnext = buf->b_next;
|
|
|
|
if (buf->b_nwindows > 0 && (buf->b_flags & BF_SYN_SET))
|
|
|
|
{
|
|
|
|
buf->b_flags &= ~BF_SYN_SET;
|
|
|
|
|
|
|
|
// buffer was opened while Syntax autocommands were disabled,
|
|
|
|
// need to trigger them now.
|
|
|
|
if (buf == curbuf)
|
|
|
|
apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
|
2005-02-02 23:07:25 +00:00
|
|
|
curbuf->b_fname, TRUE, curbuf);
|
2019-08-03 13:29:46 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
aucmd_prepbuf(&aco, buf);
|
|
|
|
apply_autocmds(EVENT_SYNTAX, buf->b_p_syn,
|
|
|
|
buf->b_fname, TRUE, buf);
|
|
|
|
aucmd_restbuf(&aco);
|
|
|
|
}
|
|
|
|
|
|
|
|
// start over, in case autocommands messed things up.
|
|
|
|
bnext = firstbuf;
|
|
|
|
}
|
|
|
|
}
|
2005-02-02 23:07:25 +00:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
2014-08-06 18:17:11 +02:00
|
|
|
#ifdef FEAT_CLIPBOARD
|
|
|
|
end_global_changes();
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
/*
|
|
|
|
* ":compiler[!] {name}"
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ex_compiler(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *buf;
|
|
|
|
char_u *old_cur_comp = NULL;
|
|
|
|
char_u *p;
|
|
|
|
|
|
|
|
if (*eap->arg == NUL)
|
|
|
|
{
|
|
|
|
/* List all compiler scripts. */
|
|
|
|
do_cmdline_cmd((char_u *)"echo globpath(&rtp, 'compiler/*.vim')");
|
|
|
|
/* ) keep the indenter happy... */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-24 18:54:09 +02:00
|
|
|
buf = alloc(STRLEN(eap->arg) + 14);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (buf != NULL)
|
|
|
|
{
|
|
|
|
if (eap->forceit)
|
|
|
|
{
|
|
|
|
/* ":compiler! {name}" sets global options */
|
|
|
|
do_cmdline_cmd((char_u *)
|
|
|
|
"command -nargs=* CompilerSet set <args>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* ":compiler! {name}" sets local options.
|
|
|
|
* To remain backwards compatible "current_compiler" is always
|
|
|
|
* used. A user's compiler plugin may set it, the distributed
|
|
|
|
* plugin will then skip the settings. Afterwards set
|
2010-01-19 16:13:50 +01:00
|
|
|
* "b:current_compiler" and restore "current_compiler".
|
|
|
|
* Explicitly prepend "g:" to make it work in a function. */
|
|
|
|
old_cur_comp = get_var_value((char_u *)"g:current_compiler");
|
2004-06-13 20:20:40 +00:00
|
|
|
if (old_cur_comp != NULL)
|
|
|
|
old_cur_comp = vim_strsave(old_cur_comp);
|
|
|
|
do_cmdline_cmd((char_u *)
|
|
|
|
"command -nargs=* CompilerSet setlocal <args>");
|
|
|
|
}
|
2010-01-19 16:13:50 +01:00
|
|
|
do_unlet((char_u *)"g:current_compiler", TRUE);
|
2005-01-31 19:19:04 +00:00
|
|
|
do_unlet((char_u *)"b:current_compiler", TRUE);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
sprintf((char *)buf, "compiler/%s.vim", eap->arg);
|
2016-03-12 22:11:39 +01:00
|
|
|
if (source_runtime(buf, DIP_ALL) == FAIL)
|
2019-01-13 23:38:42 +01:00
|
|
|
semsg(_("E666: compiler not supported: %s"), eap->arg);
|
2004-06-13 20:20:40 +00:00
|
|
|
vim_free(buf);
|
|
|
|
|
|
|
|
do_cmdline_cmd((char_u *)":delcommand CompilerSet");
|
|
|
|
|
|
|
|
/* Set "b:current_compiler" from "current_compiler". */
|
2010-01-19 16:13:50 +01:00
|
|
|
p = get_var_value((char_u *)"g:current_compiler");
|
2004-06-13 20:20:40 +00:00
|
|
|
if (p != NULL)
|
|
|
|
set_internal_string_var((char_u *)"b:current_compiler", p);
|
|
|
|
|
|
|
|
/* Restore "current_compiler" for ":compiler {name}". */
|
|
|
|
if (!eap->forceit)
|
|
|
|
{
|
|
|
|
if (old_cur_comp != NULL)
|
|
|
|
{
|
2010-01-19 16:13:50 +01:00
|
|
|
set_internal_string_var((char_u *)"g:current_compiler",
|
2004-06-13 20:20:40 +00:00
|
|
|
old_cur_comp);
|
|
|
|
vim_free(old_cur_comp);
|
|
|
|
}
|
|
|
|
else
|
2010-01-19 16:13:50 +01:00
|
|
|
do_unlet((char_u *)"g:current_compiler", TRUE);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2016-03-12 22:47:14 +01:00
|
|
|
* ":runtime [what] {name}"
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ex_runtime(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2016-03-12 22:47:14 +01:00
|
|
|
char_u *arg = eap->arg;
|
|
|
|
char_u *p = skiptowhite(arg);
|
|
|
|
int len = (int)(p - arg);
|
|
|
|
int flags = eap->forceit ? DIP_ALL : 0;
|
|
|
|
|
|
|
|
if (STRNCMP(arg, "START", len) == 0)
|
|
|
|
{
|
|
|
|
flags += DIP_START + DIP_NORTP;
|
|
|
|
arg = skipwhite(arg + len);
|
|
|
|
}
|
|
|
|
else if (STRNCMP(arg, "OPT", len) == 0)
|
|
|
|
{
|
|
|
|
flags += DIP_OPT + DIP_NORTP;
|
|
|
|
arg = skipwhite(arg + len);
|
|
|
|
}
|
|
|
|
else if (STRNCMP(arg, "PACK", len) == 0)
|
|
|
|
{
|
|
|
|
flags += DIP_START + DIP_OPT + DIP_NORTP;
|
|
|
|
arg = skipwhite(arg + len);
|
|
|
|
}
|
|
|
|
else if (STRNCMP(arg, "ALL", len) == 0)
|
|
|
|
{
|
|
|
|
flags += DIP_START + DIP_OPT;
|
|
|
|
arg = skipwhite(arg + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
source_runtime(arg, flags);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
source_callback(char_u *fname, void *cookie UNUSED)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2006-04-05 20:41:53 +00:00
|
|
|
(void)do_source(fname, FALSE, DOSO_NONE);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 14:44:08 +01:00
|
|
|
/*
|
|
|
|
* Find the file "name" in all directories in "path" and invoke
|
|
|
|
* "callback(fname, cookie)".
|
|
|
|
* "name" can contain wildcards.
|
|
|
|
* When "flags" has DIP_ALL: source all files, otherwise only the first one.
|
|
|
|
* When "flags" has DIP_DIR: find directories instead of files.
|
|
|
|
* When "flags" has DIP_ERR: give an error message if there is no match.
|
|
|
|
*
|
|
|
|
* return FAIL when no file could be sourced, OK otherwise.
|
|
|
|
*/
|
2016-03-12 21:28:26 +01:00
|
|
|
int
|
2016-02-21 23:02:49 +01:00
|
|
|
do_in_path(
|
|
|
|
char_u *path,
|
2016-01-30 15:52:46 +01:00
|
|
|
char_u *name,
|
2016-03-03 17:13:03 +01:00
|
|
|
int flags,
|
2016-01-30 15:52:46 +01:00
|
|
|
void (*callback)(char_u *fname, void *ck),
|
|
|
|
void *cookie)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *rtp;
|
|
|
|
char_u *np;
|
|
|
|
char_u *buf;
|
|
|
|
char_u *rtp_copy;
|
|
|
|
char_u *tail;
|
|
|
|
int num_files;
|
|
|
|
char_u **files;
|
|
|
|
int i;
|
|
|
|
int did_one = FALSE;
|
|
|
|
#ifdef AMIGA
|
|
|
|
struct Process *proc = (struct Process *)FindTask(0L);
|
|
|
|
APTR save_winptr = proc->pr_WindowPtr;
|
|
|
|
|
|
|
|
/* Avoid a requester here for a volume that doesn't exist. */
|
|
|
|
proc->pr_WindowPtr = (APTR)-1L;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Make a copy of 'runtimepath'. Invoking the callback may change the
|
|
|
|
* value. */
|
2016-02-21 23:02:49 +01:00
|
|
|
rtp_copy = vim_strsave(path);
|
2004-06-13 20:20:40 +00:00
|
|
|
buf = alloc(MAXPATHL);
|
|
|
|
if (buf != NULL && rtp_copy != NULL)
|
|
|
|
{
|
2013-06-10 21:27:29 +02:00
|
|
|
if (p_verbose > 1 && name != NULL)
|
2005-05-31 22:22:17 +00:00
|
|
|
{
|
|
|
|
verbose_enter();
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("Searching for \"%s\" in \"%s\""),
|
2016-02-21 23:02:49 +01:00
|
|
|
(char *)name, (char *)path);
|
2005-05-31 22:22:17 +00:00
|
|
|
verbose_leave();
|
|
|
|
}
|
2005-05-18 22:24:46 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Loop over all entries in 'runtimepath'. */
|
|
|
|
rtp = rtp_copy;
|
2016-03-03 17:13:03 +01:00
|
|
|
while (*rtp != NUL && ((flags & DIP_ALL) || !did_one))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2016-08-06 19:01:55 +02:00
|
|
|
size_t buflen;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Copy the path from 'runtimepath' to buf[]. */
|
|
|
|
copy_option_part(&rtp, buf, MAXPATHL, ",");
|
2016-08-06 19:01:55 +02:00
|
|
|
buflen = STRLEN(buf);
|
|
|
|
|
|
|
|
/* Skip after or non-after directories. */
|
|
|
|
if (flags & (DIP_NOAFTER | DIP_AFTER))
|
|
|
|
{
|
|
|
|
int is_after = buflen >= 5
|
|
|
|
&& STRCMP(buf + buflen - 5, "after") == 0;
|
|
|
|
|
|
|
|
if ((is_after && (flags & DIP_NOAFTER))
|
|
|
|
|| (!is_after && (flags & DIP_AFTER)))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-06-10 21:27:29 +02:00
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
(*callback)(buf, (void *) &cookie);
|
|
|
|
if (!did_one)
|
|
|
|
did_one = (cookie == NULL);
|
|
|
|
}
|
2016-08-06 19:01:55 +02:00
|
|
|
else if (buflen + STRLEN(name) + 2 < MAXPATHL)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
add_pathsep(buf);
|
|
|
|
tail = buf + STRLEN(buf);
|
|
|
|
|
|
|
|
/* Loop over all patterns in "name" */
|
|
|
|
np = name;
|
2016-03-03 17:13:03 +01:00
|
|
|
while (*np != NUL && ((flags & DIP_ALL) || !did_one))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* Append the pattern from "name" to buf[]. */
|
|
|
|
copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)),
|
|
|
|
"\t ");
|
|
|
|
|
|
|
|
if (p_verbose > 2)
|
2005-05-31 22:22:17 +00:00
|
|
|
{
|
|
|
|
verbose_enter();
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("Searching for \"%s\""), buf);
|
2005-05-31 22:22:17 +00:00
|
|
|
verbose_leave();
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Expand wildcards, invoke the callback for each match. */
|
|
|
|
if (gen_expand_wildcards(1, &buf, &num_files, &files,
|
2016-03-03 17:13:03 +01:00
|
|
|
(flags & DIP_DIR) ? EW_DIR : EW_FILE) == OK)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < num_files; ++i)
|
|
|
|
{
|
2005-04-15 21:13:42 +00:00
|
|
|
(*callback)(files[i], cookie);
|
2004-06-13 20:20:40 +00:00
|
|
|
did_one = TRUE;
|
2016-03-03 17:13:03 +01:00
|
|
|
if (!(flags & DIP_ALL))
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
FreeWild(num_files, files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vim_free(buf);
|
|
|
|
vim_free(rtp_copy);
|
2016-03-06 14:44:08 +01:00
|
|
|
if (!did_one && name != NULL)
|
2005-05-31 22:22:17 +00:00
|
|
|
{
|
2016-03-06 14:44:08 +01:00
|
|
|
char *basepath = path == p_rtp ? "runtimepath" : "packpath";
|
|
|
|
|
|
|
|
if (flags & DIP_ERR)
|
2019-01-13 23:38:42 +01:00
|
|
|
semsg(_(e_dirnotf), basepath, name);
|
2016-03-06 14:44:08 +01:00
|
|
|
else if (p_verbose > 0)
|
|
|
|
{
|
|
|
|
verbose_enter();
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("not found in '%s': \"%s\""), basepath, name);
|
2016-03-06 14:44:08 +01:00
|
|
|
verbose_leave();
|
|
|
|
}
|
2005-05-31 22:22:17 +00:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
#ifdef AMIGA
|
|
|
|
proc->pr_WindowPtr = save_winptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return did_one ? OK : FAIL;
|
|
|
|
}
|
|
|
|
|
2016-02-21 23:02:49 +01:00
|
|
|
/*
|
2017-06-27 14:43:55 +02:00
|
|
|
* Find "name" in "path". When found, invoke the callback function for
|
2016-02-21 23:02:49 +01:00
|
|
|
* it: callback(fname, "cookie")
|
2016-03-12 22:11:39 +01:00
|
|
|
* When "flags" has DIP_ALL repeat for all matches, otherwise only the first
|
|
|
|
* one is used.
|
2016-02-21 23:02:49 +01:00
|
|
|
* Returns OK when at least one match found, FAIL otherwise.
|
|
|
|
*
|
2017-06-27 14:43:55 +02:00
|
|
|
* If "name" is NULL calls callback for each entry in "path". Cookie is
|
2016-02-21 23:02:49 +01:00
|
|
|
* passed by reference in this case, setting it to NULL indicates that callback
|
|
|
|
* has done its job.
|
|
|
|
*/
|
2017-06-27 14:43:55 +02:00
|
|
|
static int
|
|
|
|
do_in_path_and_pp(
|
|
|
|
char_u *path,
|
2016-02-21 23:02:49 +01:00
|
|
|
char_u *name,
|
2016-03-12 22:11:39 +01:00
|
|
|
int flags,
|
2016-02-21 23:02:49 +01:00
|
|
|
void (*callback)(char_u *fname, void *ck),
|
|
|
|
void *cookie)
|
|
|
|
{
|
2016-03-12 22:47:14 +01:00
|
|
|
int done = FAIL;
|
2016-03-12 22:11:39 +01:00
|
|
|
char_u *s;
|
|
|
|
int len;
|
|
|
|
char *start_dir = "pack/*/start/*/%s";
|
|
|
|
char *opt_dir = "pack/*/opt/*/%s";
|
|
|
|
|
2016-03-12 22:47:14 +01:00
|
|
|
if ((flags & DIP_NORTP) == 0)
|
2017-06-27 14:43:55 +02:00
|
|
|
done = do_in_path(path, name, flags, callback, cookie);
|
2016-03-12 22:11:39 +01:00
|
|
|
|
2016-03-12 22:47:14 +01:00
|
|
|
if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START))
|
2016-03-12 22:11:39 +01:00
|
|
|
{
|
2016-03-17 21:51:03 +01:00
|
|
|
len = (int)(STRLEN(start_dir) + STRLEN(name));
|
2016-03-12 22:11:39 +01:00
|
|
|
s = alloc(len);
|
|
|
|
if (s == NULL)
|
|
|
|
return FAIL;
|
|
|
|
vim_snprintf((char *)s, len, start_dir, name);
|
|
|
|
done = do_in_path(p_pp, s, flags, callback, cookie);
|
|
|
|
vim_free(s);
|
|
|
|
}
|
|
|
|
|
2016-03-12 22:47:14 +01:00
|
|
|
if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT))
|
2016-03-12 22:11:39 +01:00
|
|
|
{
|
2016-03-17 21:51:03 +01:00
|
|
|
len = (int)(STRLEN(opt_dir) + STRLEN(name));
|
2016-03-12 22:11:39 +01:00
|
|
|
s = alloc(len);
|
|
|
|
if (s == NULL)
|
|
|
|
return FAIL;
|
|
|
|
vim_snprintf((char *)s, len, opt_dir, name);
|
|
|
|
done = do_in_path(p_pp, s, flags, callback, cookie);
|
|
|
|
vim_free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return done;
|
2016-02-21 23:02:49 +01:00
|
|
|
}
|
|
|
|
|
2017-06-27 14:43:55 +02:00
|
|
|
/*
|
|
|
|
* Just like do_in_path_and_pp(), using 'runtimepath' for "path".
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
do_in_runtimepath(
|
|
|
|
char_u *name,
|
|
|
|
int flags,
|
|
|
|
void (*callback)(char_u *fname, void *ck),
|
|
|
|
void *cookie)
|
|
|
|
{
|
|
|
|
return do_in_path_and_pp(p_rtp, name, flags, callback, cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Source the file "name" from all directories in 'runtimepath'.
|
|
|
|
* "name" can contain wildcards.
|
|
|
|
* When "flags" has DIP_ALL: source all files, otherwise only the first one.
|
|
|
|
*
|
|
|
|
* return FAIL when no file could be sourced, OK otherwise.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
source_runtime(char_u *name, int flags)
|
|
|
|
{
|
|
|
|
return source_in_path(p_rtp, name, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just like source_runtime(), but use "path" instead of 'runtimepath'.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
source_in_path(char_u *path, char_u *name, int flags)
|
|
|
|
{
|
|
|
|
return do_in_path_and_pp(path, name, flags, source_callback, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-04 18:08:14 +01:00
|
|
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
|
|
|
|
2016-03-03 14:23:10 +01:00
|
|
|
/*
|
2016-03-04 22:12:23 +01:00
|
|
|
* Expand wildcards in "pat" and invoke do_source() for each match.
|
2016-03-03 14:23:10 +01:00
|
|
|
*/
|
|
|
|
static void
|
2016-03-04 22:12:23 +01:00
|
|
|
source_all_matches(char_u *pat)
|
2016-03-03 14:23:10 +01:00
|
|
|
{
|
2016-03-04 22:12:23 +01:00
|
|
|
int num_files;
|
|
|
|
char_u **files;
|
|
|
|
int i;
|
2016-03-03 14:23:10 +01:00
|
|
|
|
2016-03-04 22:12:23 +01:00
|
|
|
if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK)
|
2016-03-03 14:23:10 +01:00
|
|
|
{
|
2016-03-04 22:12:23 +01:00
|
|
|
for (i = 0; i < num_files; ++i)
|
|
|
|
(void)do_source(files[i], FALSE, DOSO_NONE);
|
|
|
|
FreeWild(num_files, files);
|
2016-03-03 14:23:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-04 17:47:42 +01:00
|
|
|
/*
|
|
|
|
* Add the package directory to 'runtimepath'.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
add_pack_dir_to_rtp(char_u *fname)
|
2016-03-03 17:13:03 +01:00
|
|
|
{
|
2016-03-04 22:12:23 +01:00
|
|
|
char_u *p4, *p3, *p2, *p1, *p;
|
2018-09-08 18:21:16 +02:00
|
|
|
char_u *entry;
|
|
|
|
char_u *insp = NULL;
|
2016-03-03 17:13:03 +01:00
|
|
|
int c;
|
|
|
|
char_u *new_rtp;
|
|
|
|
int keep;
|
2016-05-31 21:37:36 +02:00
|
|
|
size_t oldlen;
|
|
|
|
size_t addlen;
|
2018-09-08 18:21:16 +02:00
|
|
|
size_t new_rtp_len;
|
2018-02-04 17:47:42 +01:00
|
|
|
char_u *afterdir = NULL;
|
2016-05-31 21:37:36 +02:00
|
|
|
size_t afterlen = 0;
|
2018-09-08 18:21:16 +02:00
|
|
|
char_u *after_insp = NULL;
|
2018-02-04 17:47:42 +01:00
|
|
|
char_u *ffname = NULL;
|
2016-07-02 22:07:22 +02:00
|
|
|
size_t fname_len;
|
2017-02-05 16:07:54 +01:00
|
|
|
char_u *buf = NULL;
|
|
|
|
char_u *rtp_ffname;
|
|
|
|
int match;
|
2018-02-04 17:47:42 +01:00
|
|
|
int retval = FAIL;
|
2016-03-03 17:13:03 +01:00
|
|
|
|
2018-02-04 17:47:42 +01:00
|
|
|
p4 = p3 = p2 = p1 = get_past_head(fname);
|
|
|
|
for (p = p1; *p; MB_PTR_ADV(p))
|
|
|
|
if (vim_ispathsep_nocolon(*p))
|
2016-07-01 15:39:40 +02:00
|
|
|
{
|
2018-02-04 17:47:42 +01:00
|
|
|
p4 = p3; p3 = p2; p2 = p1; p1 = p;
|
2016-07-01 15:39:40 +02:00
|
|
|
}
|
|
|
|
|
2018-02-04 17:47:42 +01:00
|
|
|
/* now we have:
|
|
|
|
* rtp/pack/name/start/name
|
|
|
|
* p4 p3 p2 p1
|
|
|
|
*
|
|
|
|
* find the part up to "pack" in 'runtimepath' */
|
|
|
|
c = *++p4; /* append pathsep in order to expand symlink */
|
|
|
|
*p4 = NUL;
|
|
|
|
ffname = fix_fname(fname);
|
|
|
|
*p4 = c;
|
|
|
|
if (ffname == NULL)
|
|
|
|
return FAIL;
|
|
|
|
|
2018-09-08 18:21:16 +02:00
|
|
|
// Find "ffname" in "p_rtp", ignoring '/' vs '\' differences.
|
|
|
|
// Also stop at the first "after" directory.
|
2018-02-04 17:47:42 +01:00
|
|
|
fname_len = STRLEN(ffname);
|
|
|
|
buf = alloc(MAXPATHL);
|
|
|
|
if (buf == NULL)
|
|
|
|
goto theend;
|
2018-09-08 18:21:16 +02:00
|
|
|
for (entry = p_rtp; *entry != NUL; )
|
|
|
|
{
|
|
|
|
char_u *cur_entry = entry;
|
|
|
|
|
|
|
|
copy_option_part(&entry, buf, MAXPATHL, ",");
|
|
|
|
if (insp == NULL)
|
|
|
|
{
|
|
|
|
add_pathsep(buf);
|
|
|
|
rtp_ffname = fix_fname(buf);
|
|
|
|
if (rtp_ffname == NULL)
|
|
|
|
goto theend;
|
|
|
|
match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
|
|
|
|
vim_free(rtp_ffname);
|
|
|
|
if (match)
|
|
|
|
// Insert "ffname" after this entry (and comma).
|
|
|
|
insp = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p = (char_u *)strstr((char *)buf, "after")) != NULL
|
|
|
|
&& p > buf
|
|
|
|
&& vim_ispathsep(p[-1])
|
|
|
|
&& (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ','))
|
|
|
|
{
|
|
|
|
if (insp == NULL)
|
|
|
|
// Did not find "ffname" before the first "after" directory,
|
|
|
|
// insert it before this entry.
|
|
|
|
insp = cur_entry;
|
|
|
|
after_insp = cur_entry;
|
2018-02-04 17:47:42 +01:00
|
|
|
break;
|
2018-09-08 18:21:16 +02:00
|
|
|
}
|
2016-02-21 23:02:49 +01:00
|
|
|
}
|
|
|
|
|
2018-09-08 18:21:16 +02:00
|
|
|
if (insp == NULL)
|
|
|
|
// Both "fname" and "after" not found, append at the end.
|
2018-02-04 17:47:42 +01:00
|
|
|
insp = p_rtp + STRLEN(p_rtp);
|
|
|
|
|
2018-09-08 18:21:16 +02:00
|
|
|
// check if rtp/pack/name/start/name/after exists
|
2018-02-04 17:47:42 +01:00
|
|
|
afterdir = concat_fnames(fname, (char_u *)"after", TRUE);
|
|
|
|
if (afterdir != NULL && mch_isdir(afterdir))
|
2018-09-08 18:21:16 +02:00
|
|
|
afterlen = STRLEN(afterdir) + 1; // add one for comma
|
2018-02-04 17:47:42 +01:00
|
|
|
|
|
|
|
oldlen = STRLEN(p_rtp);
|
2018-09-08 18:21:16 +02:00
|
|
|
addlen = STRLEN(fname) + 1; // add one for comma
|
2019-05-25 20:21:28 +02:00
|
|
|
new_rtp = alloc(oldlen + addlen + afterlen + 1); // add one for NUL
|
2018-02-04 17:47:42 +01:00
|
|
|
if (new_rtp == NULL)
|
|
|
|
goto theend;
|
2018-09-08 18:21:16 +02:00
|
|
|
|
|
|
|
// We now have 'rtp' parts: {keep}{keep_after}{rest}.
|
|
|
|
// Create new_rtp, first: {keep},{fname}
|
2018-02-04 17:47:42 +01:00
|
|
|
keep = (int)(insp - p_rtp);
|
|
|
|
mch_memmove(new_rtp, p_rtp, keep);
|
2018-09-08 18:21:16 +02:00
|
|
|
new_rtp_len = keep;
|
|
|
|
if (*insp == NUL)
|
|
|
|
new_rtp[new_rtp_len++] = ','; // add comma before
|
|
|
|
mch_memmove(new_rtp + new_rtp_len, fname, addlen - 1);
|
|
|
|
new_rtp_len += addlen - 1;
|
|
|
|
if (*insp != NUL)
|
|
|
|
new_rtp[new_rtp_len++] = ','; // add comma after
|
|
|
|
|
|
|
|
if (afterlen > 0 && after_insp != NULL)
|
|
|
|
{
|
|
|
|
int keep_after = (int)(after_insp - p_rtp);
|
|
|
|
|
|
|
|
// Add to new_rtp: {keep},{fname}{keep_after},{afterdir}
|
|
|
|
mch_memmove(new_rtp + new_rtp_len, p_rtp + keep,
|
|
|
|
keep_after - keep);
|
|
|
|
new_rtp_len += keep_after - keep;
|
|
|
|
mch_memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1);
|
|
|
|
new_rtp_len += afterlen - 1;
|
|
|
|
new_rtp[new_rtp_len++] = ',';
|
|
|
|
keep = keep_after;
|
|
|
|
}
|
|
|
|
|
2018-02-04 17:47:42 +01:00
|
|
|
if (p_rtp[keep] != NUL)
|
2018-09-08 18:21:16 +02:00
|
|
|
// Append rest: {keep},{fname}{keep_after},{afterdir}{rest}
|
|
|
|
mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1);
|
|
|
|
else
|
|
|
|
new_rtp[new_rtp_len] = NUL;
|
|
|
|
|
|
|
|
if (afterlen > 0 && after_insp == NULL)
|
2016-03-04 22:12:23 +01:00
|
|
|
{
|
2018-09-08 18:21:16 +02:00
|
|
|
// Append afterdir when "after" was not found:
|
|
|
|
// {keep},{fname}{rest},{afterdir}
|
2018-02-04 17:47:42 +01:00
|
|
|
STRCAT(new_rtp, ",");
|
|
|
|
STRCAT(new_rtp, afterdir);
|
|
|
|
}
|
2018-09-08 18:21:16 +02:00
|
|
|
|
2018-02-04 17:47:42 +01:00
|
|
|
set_option_value((char_u *)"rtp", 0L, new_rtp, 0);
|
|
|
|
vim_free(new_rtp);
|
|
|
|
retval = OK;
|
2016-03-04 22:12:23 +01:00
|
|
|
|
2018-02-04 17:47:42 +01:00
|
|
|
theend:
|
|
|
|
vim_free(buf);
|
|
|
|
vim_free(ffname);
|
|
|
|
vim_free(afterdir);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load scripts in "plugin" and "ftdetect" directories of the package.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
load_pack_plugin(char_u *fname)
|
|
|
|
{
|
|
|
|
static char *plugpat = "%s/plugin/**/*.vim";
|
|
|
|
static char *ftpat = "%s/ftdetect/*.vim";
|
|
|
|
int len;
|
|
|
|
char_u *ffname = fix_fname(fname);
|
|
|
|
char_u *pat = NULL;
|
|
|
|
int retval = FAIL;
|
|
|
|
|
|
|
|
if (ffname == NULL)
|
|
|
|
return FAIL;
|
|
|
|
len = (int)STRLEN(ffname) + (int)STRLEN(ftpat);
|
|
|
|
pat = alloc(len);
|
|
|
|
if (pat == NULL)
|
|
|
|
goto theend;
|
|
|
|
vim_snprintf((char *)pat, len, plugpat, ffname);
|
|
|
|
source_all_matches(pat);
|
2016-02-21 23:02:49 +01:00
|
|
|
|
2018-02-04 17:47:42 +01:00
|
|
|
{
|
|
|
|
char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes");
|
2016-03-04 22:12:23 +01:00
|
|
|
|
2018-02-04 17:47:42 +01:00
|
|
|
/* If runtime/filetype.vim wasn't loaded yet, the scripts will be
|
|
|
|
* found when it loads. */
|
|
|
|
if (cmd != NULL && eval_to_number(cmd) > 0)
|
|
|
|
{
|
|
|
|
do_cmdline_cmd((char_u *)"augroup filetypedetect");
|
|
|
|
vim_snprintf((char *)pat, len, ftpat, ffname);
|
|
|
|
source_all_matches(pat);
|
|
|
|
do_cmdline_cmd((char_u *)"augroup END");
|
2016-03-04 22:12:23 +01:00
|
|
|
}
|
2018-02-04 17:47:42 +01:00
|
|
|
vim_free(cmd);
|
2016-03-04 22:12:23 +01:00
|
|
|
}
|
2018-02-04 17:47:42 +01:00
|
|
|
vim_free(pat);
|
|
|
|
retval = OK;
|
2016-03-04 22:12:23 +01:00
|
|
|
|
|
|
|
theend:
|
|
|
|
vim_free(ffname);
|
2018-02-04 17:47:42 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* used for "cookie" of add_pack_plugin() */
|
|
|
|
static int APP_ADD_DIR;
|
|
|
|
static int APP_LOAD;
|
|
|
|
static int APP_BOTH;
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_pack_plugin(char_u *fname, void *cookie)
|
|
|
|
{
|
2018-04-18 22:18:23 +02:00
|
|
|
if (cookie != &APP_LOAD)
|
|
|
|
{
|
|
|
|
char_u *buf = alloc(MAXPATHL);
|
|
|
|
char_u *p;
|
|
|
|
int found = FALSE;
|
|
|
|
|
|
|
|
if (buf == NULL)
|
2018-02-04 17:47:42 +01:00
|
|
|
return;
|
2018-04-18 22:18:23 +02:00
|
|
|
p = p_rtp;
|
|
|
|
while (*p != NUL)
|
|
|
|
{
|
|
|
|
copy_option_part(&p, buf, MAXPATHL, ",");
|
|
|
|
if (pathcmp((char *)buf, (char *)fname, -1) == 0)
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vim_free(buf);
|
|
|
|
if (!found)
|
|
|
|
/* directory is not yet in 'runtimepath', add it */
|
|
|
|
if (add_pack_dir_to_rtp(fname) == FAIL)
|
|
|
|
return;
|
|
|
|
}
|
2018-02-04 17:47:42 +01:00
|
|
|
|
|
|
|
if (cookie != &APP_ADD_DIR)
|
|
|
|
load_pack_plugin(fname);
|
2016-02-21 23:02:49 +01:00
|
|
|
}
|
|
|
|
|
2017-06-04 17:47:42 +02:00
|
|
|
/*
|
|
|
|
* Add all packages in the "start" directory to 'runtimepath'.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
add_pack_start_dirs(void)
|
|
|
|
{
|
|
|
|
do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
|
|
|
|
add_pack_plugin, &APP_ADD_DIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load plugins from all packages in the "start" directory.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
load_start_packages(void)
|
|
|
|
{
|
|
|
|
did_source_packages = TRUE;
|
|
|
|
do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
|
|
|
|
add_pack_plugin, &APP_LOAD);
|
|
|
|
}
|
2016-03-12 20:34:27 +01:00
|
|
|
|
2016-02-21 23:02:49 +01:00
|
|
|
/*
|
2016-03-12 20:34:27 +01:00
|
|
|
* ":packloadall"
|
2016-03-04 22:12:23 +01:00
|
|
|
* Find plugins in the package directories and source them.
|
2016-02-21 23:02:49 +01:00
|
|
|
*/
|
|
|
|
void
|
2016-03-12 20:34:27 +01:00
|
|
|
ex_packloadall(exarg_T *eap)
|
2016-02-21 23:02:49 +01:00
|
|
|
{
|
2017-06-04 17:47:42 +02:00
|
|
|
if (!did_source_packages || eap->forceit)
|
2016-03-12 20:34:27 +01:00
|
|
|
{
|
2016-04-05 21:13:00 +02:00
|
|
|
/* First do a round to add all directories to 'runtimepath', then load
|
|
|
|
* the plugins. This allows for plugins to use an autoload directory
|
|
|
|
* of another plugin. */
|
2017-06-04 17:47:42 +02:00
|
|
|
add_pack_start_dirs();
|
|
|
|
load_start_packages();
|
2016-03-12 20:34:27 +01:00
|
|
|
}
|
2016-02-21 23:02:49 +01:00
|
|
|
}
|
|
|
|
|
2016-03-03 17:13:03 +01:00
|
|
|
/*
|
2016-03-04 22:12:23 +01:00
|
|
|
* ":packadd[!] {name}"
|
2016-03-03 17:13:03 +01:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ex_packadd(exarg_T *eap)
|
|
|
|
{
|
2017-12-17 14:26:46 +01:00
|
|
|
static char *plugpat = "pack/*/%s/%s";
|
2016-03-03 17:13:03 +01:00
|
|
|
int len;
|
|
|
|
char *pat;
|
2017-12-17 14:26:46 +01:00
|
|
|
int round;
|
|
|
|
int res = OK;
|
2016-03-03 17:13:03 +01:00
|
|
|
|
2017-12-17 14:26:46 +01:00
|
|
|
/* Round 1: use "start", round 2: use "opt". */
|
|
|
|
for (round = 1; round <= 2; ++round)
|
|
|
|
{
|
|
|
|
/* Only look under "start" when loading packages wasn't done yet. */
|
|
|
|
if (round == 1 && did_source_packages)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5;
|
2019-05-28 23:08:19 +02:00
|
|
|
pat = alloc(len);
|
2017-12-17 14:26:46 +01:00
|
|
|
if (pat == NULL)
|
|
|
|
return;
|
|
|
|
vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
|
|
|
|
/* The first round don't give a "not found" error, in the second round
|
|
|
|
* only when nothing was found in the first round. */
|
|
|
|
res = do_in_path(p_pp, (char_u *)pat,
|
|
|
|
DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0),
|
|
|
|
add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
|
|
|
|
vim_free(pat);
|
|
|
|
}
|
2016-03-03 17:13:03 +01:00
|
|
|
}
|
2018-03-04 18:08:14 +01:00
|
|
|
#endif
|
2016-03-03 17:13:03 +01:00
|
|
|
|
2018-03-04 18:08:14 +01:00
|
|
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* ":options"
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ex_options(
|
|
|
|
exarg_T *eap UNUSED)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2019-05-21 20:54:45 +02:00
|
|
|
vim_setenv((char_u *)"OPTWIN_CMD",
|
|
|
|
(char_u *)(cmdmod.tab ? "tab"
|
|
|
|
: (cmdmod.split & WSP_VERT) ? "vert" : ""));
|
2004-06-13 20:20:40 +00:00
|
|
|
cmd_source((char_u *)SYS_OPTWIN_FILE, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-28 16:06:38 +01:00
|
|
|
#if defined(FEAT_PYTHON3) || defined(FEAT_PYTHON) || defined(PROTO)
|
|
|
|
|
|
|
|
# if (defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* Detect Python 3 or 2, and initialize 'pyxversion'.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
init_pyxversion(void)
|
|
|
|
{
|
|
|
|
if (p_pyx == 0)
|
|
|
|
{
|
|
|
|
if (python3_enabled(FALSE))
|
|
|
|
p_pyx = 3;
|
|
|
|
else if (python_enabled(FALSE))
|
|
|
|
p_pyx = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Does a file contain one of the following strings at the beginning of any
|
|
|
|
* line?
|
|
|
|
* "#!(any string)python2" => returns 2
|
|
|
|
* "#!(any string)python3" => returns 3
|
|
|
|
* "# requires python 2.x" => returns 2
|
|
|
|
* "# requires python 3.x" => returns 3
|
|
|
|
* otherwise return 0.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
requires_py_version(char_u *filename)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
int requires_py_version = 0;
|
|
|
|
int i, lines;
|
|
|
|
|
|
|
|
lines = (int)p_mls;
|
|
|
|
if (lines < 0)
|
|
|
|
lines = 5;
|
|
|
|
|
|
|
|
file = mch_fopen((char *)filename, "r");
|
|
|
|
if (file != NULL)
|
|
|
|
{
|
|
|
|
for (i = 0; i < lines; i++)
|
|
|
|
{
|
|
|
|
if (vim_fgets(IObuff, IOSIZE, file))
|
|
|
|
break;
|
|
|
|
if (i == 0 && IObuff[0] == '#' && IObuff[1] == '!')
|
|
|
|
{
|
|
|
|
/* Check shebang. */
|
|
|
|
if (strstr((char *)IObuff + 2, "python2") != NULL)
|
|
|
|
{
|
|
|
|
requires_py_version = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strstr((char *)IObuff + 2, "python3") != NULL)
|
|
|
|
{
|
|
|
|
requires_py_version = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IObuff[21] = '\0';
|
|
|
|
if (STRCMP("# requires python 2.x", IObuff) == 0)
|
|
|
|
{
|
|
|
|
requires_py_version = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (STRCMP("# requires python 3.x", IObuff) == 0)
|
|
|
|
{
|
|
|
|
requires_py_version = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
return requires_py_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Source a python file using the requested python version.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
source_pyx_file(exarg_T *eap, char_u *fname)
|
|
|
|
{
|
|
|
|
exarg_T ex;
|
|
|
|
int v = requires_py_version(fname);
|
|
|
|
|
|
|
|
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
|
|
|
|
init_pyxversion();
|
|
|
|
# endif
|
|
|
|
if (v == 0)
|
|
|
|
{
|
|
|
|
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
|
|
|
|
/* user didn't choose a preference, 'pyx' is used */
|
|
|
|
v = p_pyx;
|
|
|
|
# elif defined(FEAT_PYTHON)
|
|
|
|
v = 2;
|
|
|
|
# elif defined(FEAT_PYTHON3)
|
|
|
|
v = 3;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now source, if required python version is not supported show
|
|
|
|
* unobtrusive message.
|
|
|
|
*/
|
|
|
|
if (eap == NULL)
|
|
|
|
vim_memset(&ex, 0, sizeof(ex));
|
|
|
|
else
|
|
|
|
ex = *eap;
|
|
|
|
ex.arg = fname;
|
|
|
|
ex.cmd = (char_u *)(v == 2 ? "pyfile" : "pyfile3");
|
|
|
|
|
|
|
|
if (v == 2)
|
|
|
|
{
|
|
|
|
# ifdef FEAT_PYTHON
|
|
|
|
ex_pyfile(&ex);
|
|
|
|
# else
|
|
|
|
vim_snprintf((char *)IObuff, IOSIZE,
|
|
|
|
_("W20: Required python version 2.x not supported, ignoring file: %s"),
|
|
|
|
fname);
|
2019-01-19 17:43:09 +01:00
|
|
|
msg((char *)IObuff);
|
2017-01-28 16:06:38 +01:00
|
|
|
# endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# ifdef FEAT_PYTHON3
|
|
|
|
ex_py3file(&ex);
|
|
|
|
# else
|
|
|
|
vim_snprintf((char *)IObuff, IOSIZE,
|
|
|
|
_("W21: Required python version 3.x not supported, ignoring file: %s"),
|
|
|
|
fname);
|
2019-01-19 17:43:09 +01:00
|
|
|
msg((char *)IObuff);
|
2017-01-28 16:06:38 +01:00
|
|
|
# endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ":pyxfile {fname}"
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ex_pyxfile(exarg_T *eap)
|
|
|
|
{
|
|
|
|
source_pyx_file(eap, eap->arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ":pyx"
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ex_pyx(exarg_T *eap)
|
|
|
|
{
|
|
|
|
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
|
|
|
|
init_pyxversion();
|
|
|
|
if (p_pyx == 2)
|
|
|
|
ex_python(eap);
|
|
|
|
else
|
|
|
|
ex_py3(eap);
|
|
|
|
# elif defined(FEAT_PYTHON)
|
|
|
|
ex_python(eap);
|
|
|
|
# elif defined(FEAT_PYTHON3)
|
|
|
|
ex_py3(eap);
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ":pyxdo"
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ex_pyxdo(exarg_T *eap)
|
|
|
|
{
|
|
|
|
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
|
|
|
|
init_pyxversion();
|
|
|
|
if (p_pyx == 2)
|
|
|
|
ex_pydo(eap);
|
|
|
|
else
|
|
|
|
ex_py3do(eap);
|
|
|
|
# elif defined(FEAT_PYTHON)
|
|
|
|
ex_pydo(eap);
|
|
|
|
# elif defined(FEAT_PYTHON3)
|
|
|
|
ex_py3do(eap);
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* ":source {fname}"
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ex_source(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
#ifdef FEAT_BROWSE
|
|
|
|
if (cmdmod.browse)
|
|
|
|
{
|
|
|
|
char_u *fname = NULL;
|
|
|
|
|
2004-10-11 10:16:09 +00:00
|
|
|
fname = do_browse(0, (char_u *)_("Source Vim script"), eap->arg,
|
2018-04-29 12:22:56 +02:00
|
|
|
NULL, NULL,
|
|
|
|
(char_u *)_(BROWSE_FILTER_MACROS), NULL);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (fname != NULL)
|
|
|
|
{
|
|
|
|
cmd_source(fname, eap);
|
|
|
|
vim_free(fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
cmd_source(eap->arg, eap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
cmd_source(char_u *fname, exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (*fname == NUL)
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_(e_argreq));
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
else if (eap != NULL && eap->forceit)
|
2013-05-06 04:24:17 +02:00
|
|
|
/* ":source!": read Normal mode commands
|
2006-03-07 22:38:47 +00:00
|
|
|
* Need to execute the commands directly. This is required at least
|
|
|
|
* for:
|
2004-06-13 20:20:40 +00:00
|
|
|
* - ":g" command busy
|
|
|
|
* - after ":argdo", ":windo" or ":bufdo"
|
|
|
|
* - another command follows
|
|
|
|
* - inside a loop
|
|
|
|
*/
|
|
|
|
openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
|| eap->cstack->cs_idx >= 0
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
/* ":source" read ex commands */
|
2006-04-05 20:41:53 +00:00
|
|
|
else if (do_source(fname, FALSE, DOSO_NONE) == FAIL)
|
2019-01-13 23:38:42 +01:00
|
|
|
semsg(_(e_notopen), fname);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ":source" and associated commands.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Structure used to store info for each sourced file.
|
|
|
|
* It is shared between do_source() and getsourceline().
|
|
|
|
* This is required, because it needs to be handed to do_cmdline() and
|
|
|
|
* sourcing can be done recursively.
|
|
|
|
*/
|
|
|
|
struct source_cookie
|
|
|
|
{
|
2019-07-04 14:57:12 +02:00
|
|
|
FILE *fp; // opened file for sourcing
|
|
|
|
char_u *nextline; // if not NULL: line that was read ahead
|
|
|
|
linenr_T sourcing_lnum; // line number of the source file
|
|
|
|
int finished; // ":finish" used
|
2019-02-15 21:06:09 +01:00
|
|
|
#ifdef USE_CRNL
|
2019-07-04 14:57:12 +02:00
|
|
|
int fileformat; // EOL_UNKNOWN, EOL_UNIX or EOL_DOS
|
|
|
|
int error; // TRUE if LF found after CR-LF
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FEAT_EVAL
|
2019-07-04 14:57:12 +02:00
|
|
|
linenr_T breakpoint; // next line with breakpoint or zero
|
|
|
|
char_u *fname; // name of sourced file
|
|
|
|
int dbg_tick; // debug_tick when breakpoint was set
|
|
|
|
int level; // top nesting level of sourced file
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
2019-07-04 14:57:12 +02:00
|
|
|
vimconv_T conv; // type of conversion
|
2004-06-13 20:20:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
/*
|
|
|
|
* Return the address holding the next breakpoint line for a source cookie.
|
|
|
|
*/
|
|
|
|
linenr_T *
|
2016-01-30 15:52:46 +01:00
|
|
|
source_breakpoint(void *cookie)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
return &((struct source_cookie *)cookie)->breakpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the address holding the debug tick for a source cookie.
|
|
|
|
*/
|
|
|
|
int *
|
2016-01-30 15:52:46 +01:00
|
|
|
source_dbg_tick(void *cookie)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
return &((struct source_cookie *)cookie)->dbg_tick;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the nesting level for a source cookie.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
source_level(void *cookie)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
return ((struct source_cookie *)cookie)->level;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-29 22:03:47 +01:00
|
|
|
static char_u *get_one_sourceline(struct source_cookie *sp);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2019-02-17 17:44:42 +01:00
|
|
|
#if (defined(MSWIN) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC)
|
2010-01-19 16:22:03 +01:00
|
|
|
# define USE_FOPEN_NOINH
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Special function to open a file without handle inheritance.
|
2010-01-19 16:22:03 +01:00
|
|
|
* When possible the handle is closed on exec().
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
static FILE *
|
2016-01-30 15:52:46 +01:00
|
|
|
fopen_noinh_readbin(char *filename)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2019-02-17 17:44:42 +01:00
|
|
|
# ifdef MSWIN
|
2010-01-20 21:41:47 +01:00
|
|
|
int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0);
|
|
|
|
# else
|
|
|
|
int fd_tmp = mch_open(filename, O_RDONLY, 0);
|
2010-01-19 16:22:03 +01:00
|
|
|
# endif
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (fd_tmp == -1)
|
|
|
|
return NULL;
|
2010-01-19 16:22:03 +01:00
|
|
|
|
|
|
|
# ifdef HAVE_FD_CLOEXEC
|
|
|
|
{
|
|
|
|
int fdflags = fcntl(fd_tmp, F_GETFD);
|
|
|
|
if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0)
|
2015-08-11 19:14:00 +02:00
|
|
|
(void)fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC);
|
2010-01-19 16:22:03 +01:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
return fdopen(fd_tmp, READBIN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do_source: Read the file "fname" and execute its lines as EX commands.
|
|
|
|
*
|
|
|
|
* This function may be called recursively!
|
|
|
|
*
|
|
|
|
* return FAIL if file could not be opened, OK otherwise
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
do_source(
|
|
|
|
char_u *fname,
|
|
|
|
int check_other, /* check for .vimrc and _vimrc */
|
|
|
|
int is_vimrc) /* DOSO_ value */
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
struct source_cookie cookie;
|
|
|
|
char_u *save_sourcing_name;
|
|
|
|
linenr_T save_sourcing_lnum;
|
|
|
|
char_u *p;
|
|
|
|
char_u *fname_exp;
|
2009-02-04 16:50:47 +00:00
|
|
|
char_u *firstline = NULL;
|
2004-06-13 20:20:40 +00:00
|
|
|
int retval = FAIL;
|
|
|
|
#ifdef FEAT_EVAL
|
2018-09-10 21:05:02 +02:00
|
|
|
sctx_T save_current_sctx;
|
2004-06-13 20:20:40 +00:00
|
|
|
static scid_T last_current_SID = 0;
|
2018-11-10 17:33:29 +01:00
|
|
|
static int last_current_SID_seq = 0;
|
2018-10-14 21:41:01 +02:00
|
|
|
funccal_entry_T funccalp_entry;
|
2004-06-13 20:20:40 +00:00
|
|
|
int save_debug_break_level = debug_break_level;
|
2005-02-26 23:04:13 +00:00
|
|
|
scriptitem_T *si = NULL;
|
2004-06-13 20:20:40 +00:00
|
|
|
# ifdef UNIX
|
2016-07-01 17:17:39 +02:00
|
|
|
stat_T st;
|
2004-06-13 20:20:40 +00:00
|
|
|
int stat_ok;
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifdef STARTUPTIME
|
|
|
|
struct timeval tv_rel;
|
|
|
|
struct timeval tv_start;
|
|
|
|
#endif
|
2005-02-26 23:04:13 +00:00
|
|
|
#ifdef FEAT_PROFILE
|
|
|
|
proftime_T wait_start;
|
|
|
|
#endif
|
2019-01-12 13:26:03 +01:00
|
|
|
int trigger_source_post = FALSE;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
p = expand_env_save(fname);
|
|
|
|
if (p == NULL)
|
|
|
|
return retval;
|
|
|
|
fname_exp = fix_fname(p);
|
|
|
|
vim_free(p);
|
|
|
|
if (fname_exp == NULL)
|
|
|
|
return retval;
|
|
|
|
if (mch_isdir(fname_exp))
|
|
|
|
{
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("Cannot source a directory: \"%s\""), fname);
|
2004-06-13 20:20:40 +00:00
|
|
|
goto theend;
|
|
|
|
}
|
|
|
|
|
2007-01-16 20:33:19 +00:00
|
|
|
/* Apply SourceCmd autocommands, they should get the file and source it. */
|
|
|
|
if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL)
|
|
|
|
&& apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp,
|
|
|
|
FALSE, curbuf))
|
2008-01-15 21:17:30 +00:00
|
|
|
{
|
2018-03-04 18:08:14 +01:00
|
|
|
#ifdef FEAT_EVAL
|
2008-01-15 21:17:30 +00:00
|
|
|
retval = aborting() ? FAIL : OK;
|
2018-03-04 18:08:14 +01:00
|
|
|
#else
|
2008-01-15 21:17:30 +00:00
|
|
|
retval = OK;
|
2018-03-04 18:08:14 +01:00
|
|
|
#endif
|
2019-01-12 13:26:03 +01:00
|
|
|
if (retval == OK)
|
|
|
|
// Apply SourcePost autocommands.
|
|
|
|
apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp,
|
|
|
|
FALSE, curbuf);
|
2008-01-15 21:17:30 +00:00
|
|
|
goto theend;
|
|
|
|
}
|
2007-01-16 20:33:19 +00:00
|
|
|
|
|
|
|
/* Apply SourcePre autocommands, they may get the file. */
|
2006-03-07 22:38:47 +00:00
|
|
|
apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf);
|
|
|
|
|
2010-01-19 16:22:03 +01:00
|
|
|
#ifdef USE_FOPEN_NOINH
|
2004-06-13 20:20:40 +00:00
|
|
|
cookie.fp = fopen_noinh_readbin((char *)fname_exp);
|
|
|
|
#else
|
|
|
|
cookie.fp = mch_fopen((char *)fname_exp, READBIN);
|
|
|
|
#endif
|
|
|
|
if (cookie.fp == NULL && check_other)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Try again, replacing file name ".vimrc" by "_vimrc" or vice versa,
|
|
|
|
* and ".exrc" by "_exrc" or vice versa.
|
|
|
|
*/
|
|
|
|
p = gettail(fname_exp);
|
|
|
|
if ((*p == '.' || *p == '_')
|
|
|
|
&& (STRICMP(p + 1, "vimrc") == 0
|
|
|
|
|| STRICMP(p + 1, "gvimrc") == 0
|
|
|
|
|| STRICMP(p + 1, "exrc") == 0))
|
|
|
|
{
|
|
|
|
if (*p == '_')
|
|
|
|
*p = '.';
|
|
|
|
else
|
|
|
|
*p = '_';
|
2010-01-19 16:22:03 +01:00
|
|
|
#ifdef USE_FOPEN_NOINH
|
2004-06-13 20:20:40 +00:00
|
|
|
cookie.fp = fopen_noinh_readbin((char *)fname_exp);
|
|
|
|
#else
|
|
|
|
cookie.fp = mch_fopen((char *)fname_exp, READBIN);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cookie.fp == NULL)
|
|
|
|
{
|
|
|
|
if (p_verbose > 0)
|
|
|
|
{
|
2005-05-31 22:22:17 +00:00
|
|
|
verbose_enter();
|
2004-06-13 20:20:40 +00:00
|
|
|
if (sourcing_name == NULL)
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("could not source \"%s\""), fname);
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("line %ld: could not source \"%s\""),
|
2005-05-19 21:08:39 +00:00
|
|
|
sourcing_lnum, fname);
|
2005-05-31 22:22:17 +00:00
|
|
|
verbose_leave();
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
goto theend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The file exists.
|
|
|
|
* - In verbose mode, give a message.
|
|
|
|
* - For a vimrc file, may want to set 'compatible', call vimrc_found().
|
|
|
|
*/
|
|
|
|
if (p_verbose > 1)
|
|
|
|
{
|
2005-05-31 22:22:17 +00:00
|
|
|
verbose_enter();
|
2004-06-13 20:20:40 +00:00
|
|
|
if (sourcing_name == NULL)
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("sourcing \"%s\""), fname);
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("line %ld: sourcing \"%s\""),
|
2005-05-19 21:08:39 +00:00
|
|
|
sourcing_lnum, fname);
|
2005-05-31 22:22:17 +00:00
|
|
|
verbose_leave();
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2006-04-05 20:41:53 +00:00
|
|
|
if (is_vimrc == DOSO_VIMRC)
|
|
|
|
vimrc_found(fname_exp, (char_u *)"MYVIMRC");
|
|
|
|
else if (is_vimrc == DOSO_GVIMRC)
|
|
|
|
vimrc_found(fname_exp, (char_u *)"MYGVIMRC");
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
#ifdef USE_CRNL
|
|
|
|
/* If no automatic file format: Set default to CR-NL. */
|
|
|
|
if (*p_ffs == NUL)
|
|
|
|
cookie.fileformat = EOL_DOS;
|
|
|
|
else
|
|
|
|
cookie.fileformat = EOL_UNKNOWN;
|
|
|
|
cookie.error = FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cookie.nextline = NULL;
|
2019-07-04 14:57:12 +02:00
|
|
|
cookie.sourcing_lnum = 0;
|
2004-06-13 20:20:40 +00:00
|
|
|
cookie.finished = FALSE;
|
|
|
|
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
/*
|
|
|
|
* Check if this script has a breakpoint.
|
|
|
|
*/
|
|
|
|
cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0);
|
|
|
|
cookie.fname = fname_exp;
|
|
|
|
cookie.dbg_tick = debug_tick;
|
|
|
|
|
|
|
|
cookie.level = ex_nesting_level;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep the sourcing name/lnum, for recursive calls.
|
|
|
|
*/
|
|
|
|
save_sourcing_name = sourcing_name;
|
|
|
|
sourcing_name = fname_exp;
|
|
|
|
save_sourcing_lnum = sourcing_lnum;
|
|
|
|
sourcing_lnum = 0;
|
|
|
|
|
|
|
|
#ifdef STARTUPTIME
|
2010-01-19 16:31:47 +01:00
|
|
|
if (time_fd != NULL)
|
|
|
|
time_push(&tv_rel, &tv_start);
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FEAT_EVAL
|
2005-02-26 23:04:13 +00:00
|
|
|
# ifdef FEAT_PROFILE
|
2006-03-20 21:55:45 +00:00
|
|
|
if (do_profiling == PROF_YES)
|
2005-02-26 23:04:13 +00:00
|
|
|
prof_child_enter(&wait_start); /* entering a child now */
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Don't use local function variables, if called from a function.
|
|
|
|
* Also starts profiling timer for nested script. */
|
2018-10-14 21:41:01 +02:00
|
|
|
save_funccal(&funccalp_entry);
|
2005-02-26 23:04:13 +00:00
|
|
|
|
2019-04-04 18:15:38 +02:00
|
|
|
save_current_sctx = current_sctx;
|
|
|
|
current_sctx.sc_lnum = 0;
|
|
|
|
current_sctx.sc_version = 1;
|
|
|
|
|
2018-11-10 17:33:29 +01:00
|
|
|
// Check if this script was sourced before to finds its SID.
|
|
|
|
// If it's new, generate a new SID.
|
|
|
|
// Always use a new sequence number.
|
|
|
|
current_sctx.sc_seq = ++last_current_SID_seq;
|
2004-06-13 20:20:40 +00:00
|
|
|
# ifdef UNIX
|
|
|
|
stat_ok = (mch_stat((char *)fname_exp, &st) >= 0);
|
|
|
|
# endif
|
2018-09-10 21:05:02 +02:00
|
|
|
for (current_sctx.sc_sid = script_items.ga_len; current_sctx.sc_sid > 0;
|
|
|
|
--current_sctx.sc_sid)
|
2005-02-26 23:04:13 +00:00
|
|
|
{
|
2018-09-10 21:05:02 +02:00
|
|
|
si = &SCRIPT_ITEM(current_sctx.sc_sid);
|
2005-02-26 23:04:13 +00:00
|
|
|
if (si->sn_name != NULL
|
2004-06-13 20:20:40 +00:00
|
|
|
&& (
|
|
|
|
# ifdef UNIX
|
2005-02-07 22:01:03 +00:00
|
|
|
/* Compare dev/ino when possible, it catches symbolic
|
|
|
|
* links. Also compare file names, the inode may change
|
|
|
|
* when the file was edited. */
|
2009-05-16 19:16:33 +00:00
|
|
|
((stat_ok && si->sn_dev_valid)
|
2005-02-26 23:04:13 +00:00
|
|
|
&& (si->sn_dev == st.st_dev
|
|
|
|
&& si->sn_ino == st.st_ino)) ||
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
2005-02-26 23:04:13 +00:00
|
|
|
fnamecmp(si->sn_name, fname_exp) == 0))
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
2005-02-26 23:04:13 +00:00
|
|
|
}
|
2018-09-10 21:05:02 +02:00
|
|
|
if (current_sctx.sc_sid == 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2018-09-10 21:05:02 +02:00
|
|
|
current_sctx.sc_sid = ++last_current_SID;
|
|
|
|
if (ga_grow(&script_items,
|
|
|
|
(int)(current_sctx.sc_sid - script_items.ga_len)) == FAIL)
|
2005-02-26 23:04:13 +00:00
|
|
|
goto almosttheend;
|
2018-09-10 21:05:02 +02:00
|
|
|
while (script_items.ga_len < current_sctx.sc_sid)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-02-26 23:04:13 +00:00
|
|
|
++script_items.ga_len;
|
|
|
|
SCRIPT_ITEM(script_items.ga_len).sn_name = NULL;
|
|
|
|
# ifdef FEAT_PROFILE
|
|
|
|
SCRIPT_ITEM(script_items.ga_len).sn_prof_on = FALSE;
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
}
|
2018-09-10 21:05:02 +02:00
|
|
|
si = &SCRIPT_ITEM(current_sctx.sc_sid);
|
2005-02-26 23:04:13 +00:00
|
|
|
si->sn_name = fname_exp;
|
2019-01-12 15:15:38 +01:00
|
|
|
fname_exp = vim_strsave(si->sn_name); // used for autocmd
|
2005-02-26 23:04:13 +00:00
|
|
|
# ifdef UNIX
|
|
|
|
if (stat_ok)
|
|
|
|
{
|
2009-05-16 19:16:33 +00:00
|
|
|
si->sn_dev_valid = TRUE;
|
2005-02-26 23:04:13 +00:00
|
|
|
si->sn_dev = st.st_dev;
|
|
|
|
si->sn_ino = st.st_ino;
|
|
|
|
}
|
|
|
|
else
|
2009-05-16 19:16:33 +00:00
|
|
|
si->sn_dev_valid = FALSE;
|
2005-02-26 23:04:13 +00:00
|
|
|
# endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Allocate the local script variables to use for this script. */
|
2018-09-10 21:05:02 +02:00
|
|
|
new_script_vars(current_sctx.sc_sid);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
2005-02-26 23:04:13 +00:00
|
|
|
# ifdef FEAT_PROFILE
|
2006-03-20 21:55:45 +00:00
|
|
|
if (do_profiling == PROF_YES)
|
2005-02-26 23:04:13 +00:00
|
|
|
{
|
|
|
|
int forceit;
|
|
|
|
|
|
|
|
/* Check if we do profiling for this script. */
|
|
|
|
if (!si->sn_prof_on && has_profiling(TRUE, si->sn_name, &forceit))
|
|
|
|
{
|
|
|
|
script_do_profile(si);
|
|
|
|
si->sn_pr_force = forceit;
|
|
|
|
}
|
|
|
|
if (si->sn_prof_on)
|
|
|
|
{
|
|
|
|
++si->sn_pr_count;
|
|
|
|
profile_start(&si->sn_pr_start);
|
|
|
|
profile_zero(&si->sn_pr_children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
2017-10-19 21:04:37 +02:00
|
|
|
cookie.conv.vc_type = CONV_NONE; /* no conversion */
|
|
|
|
|
|
|
|
/* Read the first line so we can check for a UTF-8 BOM. */
|
2019-06-25 04:12:16 +02:00
|
|
|
firstline = getsourceline(0, (void *)&cookie, 0, TRUE);
|
2017-10-19 21:04:37 +02:00
|
|
|
if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
|
|
|
|
&& firstline[1] == 0xbb && firstline[2] == 0xbf)
|
|
|
|
{
|
|
|
|
/* Found BOM; setup conversion, skip over BOM and recode the line. */
|
|
|
|
convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
|
|
|
|
p = string_convert(&cookie.conv, firstline + 3, NULL);
|
|
|
|
if (p == NULL)
|
|
|
|
p = vim_strsave(firstline + 3);
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
vim_free(firstline);
|
|
|
|
firstline = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Call do_cmdline, which will call getsourceline() to get the lines.
|
|
|
|
*/
|
2009-02-04 16:50:47 +00:00
|
|
|
do_cmdline(firstline, getsourceline, (void *)&cookie,
|
2004-06-13 20:20:40 +00:00
|
|
|
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
|
|
|
|
retval = OK;
|
2005-02-26 23:04:13 +00:00
|
|
|
|
|
|
|
#ifdef FEAT_PROFILE
|
2006-03-20 21:55:45 +00:00
|
|
|
if (do_profiling == PROF_YES)
|
2005-02-26 23:04:13 +00:00
|
|
|
{
|
|
|
|
/* Get "si" again, "script_items" may have been reallocated. */
|
2018-09-10 21:05:02 +02:00
|
|
|
si = &SCRIPT_ITEM(current_sctx.sc_sid);
|
2005-02-26 23:04:13 +00:00
|
|
|
if (si->sn_prof_on)
|
|
|
|
{
|
|
|
|
profile_end(&si->sn_pr_start);
|
|
|
|
profile_sub_wait(&wait_start, &si->sn_pr_start);
|
|
|
|
profile_add(&si->sn_pr_total, &si->sn_pr_start);
|
2006-03-09 22:37:52 +00:00
|
|
|
profile_self(&si->sn_pr_self, &si->sn_pr_start,
|
|
|
|
&si->sn_pr_children);
|
2005-02-26 23:04:13 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (got_int)
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_(e_interr));
|
2004-06-13 20:20:40 +00:00
|
|
|
sourcing_name = save_sourcing_name;
|
|
|
|
sourcing_lnum = save_sourcing_lnum;
|
|
|
|
if (p_verbose > 1)
|
|
|
|
{
|
2005-05-31 22:22:17 +00:00
|
|
|
verbose_enter();
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("finished sourcing %s"), fname);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (sourcing_name != NULL)
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("continuing in %s"), sourcing_name);
|
2005-05-31 22:22:17 +00:00
|
|
|
verbose_leave();
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
#ifdef STARTUPTIME
|
2010-01-19 16:31:47 +01:00
|
|
|
if (time_fd != NULL)
|
|
|
|
{
|
|
|
|
vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname);
|
|
|
|
time_msg((char *)IObuff, &tv_start);
|
|
|
|
time_pop(&tv_rel);
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-12 13:26:03 +01:00
|
|
|
if (!got_int)
|
|
|
|
trigger_source_post = TRUE;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
/*
|
|
|
|
* After a "finish" in debug mode, need to break at first command of next
|
|
|
|
* sourced file.
|
|
|
|
*/
|
|
|
|
if (save_debug_break_level > ex_nesting_level
|
|
|
|
&& debug_break_level == ex_nesting_level)
|
|
|
|
++debug_break_level;
|
|
|
|
#endif
|
|
|
|
|
2005-02-26 23:04:13 +00:00
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
almosttheend:
|
2018-09-10 21:05:02 +02:00
|
|
|
current_sctx = save_current_sctx;
|
2018-10-14 21:41:01 +02:00
|
|
|
restore_funccal();
|
2005-02-26 23:04:13 +00:00
|
|
|
# ifdef FEAT_PROFILE
|
2006-03-20 21:55:45 +00:00
|
|
|
if (do_profiling == PROF_YES)
|
2005-02-26 23:04:13 +00:00
|
|
|
prof_child_exit(&wait_start); /* leaving a child now */
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
fclose(cookie.fp);
|
|
|
|
vim_free(cookie.nextline);
|
2009-02-04 16:50:47 +00:00
|
|
|
vim_free(firstline);
|
2005-02-26 23:04:13 +00:00
|
|
|
convert_setup(&cookie.conv, NULL, NULL);
|
|
|
|
|
2019-01-12 13:26:03 +01:00
|
|
|
if (trigger_source_post)
|
2019-01-12 15:15:38 +01:00
|
|
|
apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, FALSE, curbuf);
|
2019-01-12 13:26:03 +01:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
theend:
|
|
|
|
vim_free(fname_exp);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
2005-06-24 23:07:47 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* ":scriptnames"
|
|
|
|
*/
|
|
|
|
void
|
2018-11-30 22:48:32 +01:00
|
|
|
ex_scriptnames(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-11-30 22:48:32 +01:00
|
|
|
if (eap->addr_count > 0)
|
|
|
|
{
|
|
|
|
// :script {scriptId}: edit the script
|
|
|
|
if (eap->line2 < 1 || eap->line2 > script_items.ga_len)
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_(e_invarg));
|
2018-11-30 22:48:32 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
eap->arg = SCRIPT_ITEM(eap->line2).sn_name;
|
|
|
|
do_exedit(eap, NULL);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-26 23:04:13 +00:00
|
|
|
for (i = 1; i <= script_items.ga_len && !got_int; ++i)
|
|
|
|
if (SCRIPT_ITEM(i).sn_name != NULL)
|
2011-06-26 04:25:30 +02:00
|
|
|
{
|
|
|
|
home_replace(NULL, SCRIPT_ITEM(i).sn_name,
|
|
|
|
NameBuff, MAXPATHL, TRUE);
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg("%3d: %s", i, NameBuff);
|
2012-03-23 18:39:18 +01:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* Fix slashes in the list of script names for 'shellslash'.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
scriptnames_slash_adjust(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2005-02-26 23:04:13 +00:00
|
|
|
for (i = 1; i <= script_items.ga_len; ++i)
|
|
|
|
if (SCRIPT_ITEM(i).sn_name != NULL)
|
|
|
|
slash_adjust(SCRIPT_ITEM(i).sn_name);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a pointer to a script name. Used for ":verbose set".
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
get_scriptname(scid_T id)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (id == SID_MODELINE)
|
2006-02-22 21:25:37 +00:00
|
|
|
return (char_u *)_("modeline");
|
2004-06-13 20:20:40 +00:00
|
|
|
if (id == SID_CMDARG)
|
2006-02-22 21:25:37 +00:00
|
|
|
return (char_u *)_("--cmd argument");
|
2004-06-13 20:20:40 +00:00
|
|
|
if (id == SID_CARG)
|
2006-02-22 21:25:37 +00:00
|
|
|
return (char_u *)_("-c argument");
|
2004-06-13 20:20:40 +00:00
|
|
|
if (id == SID_ENV)
|
2006-02-22 21:25:37 +00:00
|
|
|
return (char_u *)_("environment variable");
|
|
|
|
if (id == SID_ERROR)
|
|
|
|
return (char_u *)_("error handler");
|
2005-02-26 23:04:13 +00:00
|
|
|
return SCRIPT_ITEM(id).sn_name;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2005-02-26 23:04:13 +00:00
|
|
|
|
2005-06-24 23:07:47 +00:00
|
|
|
# if defined(EXITFREE) || defined(PROTO)
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
free_scriptnames(void)
|
2005-06-24 23:07:47 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = script_items.ga_len; i > 0; --i)
|
|
|
|
vim_free(SCRIPT_ITEM(i).sn_name);
|
|
|
|
ga_clear(&script_items);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
2019-07-04 14:57:12 +02:00
|
|
|
linenr_T
|
|
|
|
get_sourced_lnum(char_u *(*fgetline)(int, void *, int, int), void *cookie)
|
|
|
|
{
|
|
|
|
return fgetline == getsourceline
|
|
|
|
? ((struct source_cookie *)cookie)->sourcing_lnum
|
|
|
|
: sourcing_lnum;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Get one full line from a sourced file.
|
|
|
|
* Called by do_cmdline() when it's called from do_source().
|
|
|
|
*
|
|
|
|
* Return a pointer to the line in allocated memory.
|
|
|
|
* Return NULL for end-of-file or some error.
|
|
|
|
*/
|
|
|
|
char_u *
|
2019-06-25 04:12:16 +02:00
|
|
|
getsourceline(int c UNUSED, void *cookie, int indent UNUSED, int do_concat)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
struct source_cookie *sp = (struct source_cookie *)cookie;
|
|
|
|
char_u *line;
|
2012-02-11 20:40:55 +01:00
|
|
|
char_u *p;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
/* If breakpoints have been added/deleted need to check for it. */
|
|
|
|
if (sp->dbg_tick < debug_tick)
|
|
|
|
{
|
|
|
|
sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum);
|
|
|
|
sp->dbg_tick = debug_tick;
|
|
|
|
}
|
2005-02-26 23:04:13 +00:00
|
|
|
# ifdef FEAT_PROFILE
|
2006-03-20 21:55:45 +00:00
|
|
|
if (do_profiling == PROF_YES)
|
2005-02-26 23:04:13 +00:00
|
|
|
script_line_end();
|
|
|
|
# endif
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
2019-07-04 14:57:12 +02:00
|
|
|
|
|
|
|
// Set the current sourcing line number.
|
|
|
|
sourcing_lnum = sp->sourcing_lnum + 1;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Get current line. If there is a read-ahead line, use it, otherwise get
|
|
|
|
* one now.
|
|
|
|
*/
|
|
|
|
if (sp->finished)
|
|
|
|
line = NULL;
|
|
|
|
else if (sp->nextline == NULL)
|
|
|
|
line = get_one_sourceline(sp);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line = sp->nextline;
|
|
|
|
sp->nextline = NULL;
|
2019-07-04 14:57:12 +02:00
|
|
|
++sp->sourcing_lnum;
|
2005-03-15 22:43:58 +00:00
|
|
|
}
|
2005-02-26 23:04:13 +00:00
|
|
|
#ifdef FEAT_PROFILE
|
2006-03-20 21:55:45 +00:00
|
|
|
if (line != NULL && do_profiling == PROF_YES)
|
2005-03-15 22:43:58 +00:00
|
|
|
script_line_start();
|
2005-02-26 23:04:13 +00:00
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Only concatenate lines starting with a \ when 'cpoptions' doesn't
|
|
|
|
* contain the 'C' flag. */
|
2019-06-25 04:12:16 +02:00
|
|
|
if (line != NULL && do_concat && vim_strchr(p_cpo, CPO_CONCAT) == NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* compensate for the one line read-ahead */
|
2019-07-04 14:57:12 +02:00
|
|
|
--sp->sourcing_lnum;
|
2012-02-05 23:10:30 +01:00
|
|
|
|
2018-09-11 22:37:29 +02:00
|
|
|
// Get the next line and concatenate it when it starts with a
|
|
|
|
// backslash. We always need to read the next line, keep it in
|
|
|
|
// sp->nextline.
|
|
|
|
/* Also check for a comment in between continuation lines: "\ */
|
2012-02-05 23:10:30 +01:00
|
|
|
sp->nextline = get_one_sourceline(sp);
|
2018-09-11 22:37:29 +02:00
|
|
|
if (sp->nextline != NULL
|
|
|
|
&& (*(p = skipwhite(sp->nextline)) == '\\'
|
|
|
|
|| (p[0] == '"' && p[1] == '\\' && p[2] == ' ')))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2012-02-05 23:10:30 +01:00
|
|
|
garray_T ga;
|
|
|
|
|
2012-02-22 18:29:33 +01:00
|
|
|
ga_init2(&ga, (int)sizeof(char_u), 400);
|
2012-02-05 23:10:30 +01:00
|
|
|
ga_concat(&ga, line);
|
2018-09-11 22:37:29 +02:00
|
|
|
if (*p == '\\')
|
|
|
|
ga_concat(&ga, p + 1);
|
2012-02-05 23:10:30 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
vim_free(sp->nextline);
|
|
|
|
sp->nextline = get_one_sourceline(sp);
|
|
|
|
if (sp->nextline == NULL)
|
|
|
|
break;
|
|
|
|
p = skipwhite(sp->nextline);
|
2018-09-11 22:37:29 +02:00
|
|
|
if (*p == '\\')
|
2012-02-22 18:29:33 +01:00
|
|
|
{
|
2018-09-11 22:37:29 +02:00
|
|
|
// Adjust the growsize to the current length to speed up
|
|
|
|
// concatenating many lines.
|
|
|
|
if (ga.ga_len > 400)
|
|
|
|
{
|
|
|
|
if (ga.ga_len > 8000)
|
|
|
|
ga.ga_growsize = 8000;
|
|
|
|
else
|
|
|
|
ga.ga_growsize = ga.ga_len;
|
|
|
|
}
|
|
|
|
ga_concat(&ga, p + 1);
|
2012-02-22 18:29:33 +01:00
|
|
|
}
|
2018-09-11 22:37:29 +02:00
|
|
|
else if (p[0] != '"' || p[1] != '\\' || p[2] != ' ')
|
|
|
|
break;
|
2012-02-05 23:10:30 +01:00
|
|
|
}
|
|
|
|
ga_append(&ga, NUL);
|
2004-06-13 20:20:40 +00:00
|
|
|
vim_free(line);
|
2012-02-05 23:10:30 +01:00
|
|
|
line = ga.ga_data;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line != NULL && sp->conv.vc_type != CONV_NONE)
|
|
|
|
{
|
2012-02-11 20:40:55 +01:00
|
|
|
char_u *s;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Convert the encoding of the script line. */
|
|
|
|
s = string_convert(&sp->conv, line, NULL);
|
|
|
|
if (s != NULL)
|
|
|
|
{
|
|
|
|
vim_free(line);
|
|
|
|
line = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
/* Did we encounter a breakpoint? */
|
|
|
|
if (sp->breakpoint != 0 && sp->breakpoint <= sourcing_lnum)
|
|
|
|
{
|
|
|
|
dbg_breakpoint(sp->fname, sourcing_lnum);
|
|
|
|
/* Find next breakpoint. */
|
|
|
|
sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum);
|
|
|
|
sp->dbg_tick = debug_tick;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
get_one_sourceline(struct source_cookie *sp)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
garray_T ga;
|
|
|
|
int len;
|
|
|
|
int c;
|
|
|
|
char_u *buf;
|
|
|
|
#ifdef USE_CRNL
|
|
|
|
int has_cr; /* CR-LF found */
|
|
|
|
#endif
|
|
|
|
int have_read = FALSE;
|
|
|
|
|
|
|
|
/* use a growarray to store the sourced line */
|
2005-02-02 23:07:25 +00:00
|
|
|
ga_init2(&ga, 1, 250);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop until there is a finished line (or end-of-file).
|
|
|
|
*/
|
2019-07-04 14:57:12 +02:00
|
|
|
++sp->sourcing_lnum;
|
2004-06-13 20:20:40 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2005-02-02 23:07:25 +00:00
|
|
|
/* make room to read at least 120 (more) characters */
|
|
|
|
if (ga_grow(&ga, 120) == FAIL)
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
buf = (char_u *)ga.ga_data;
|
|
|
|
|
2019-02-15 21:06:09 +01:00
|
|
|
if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
|
2004-12-27 21:59:20 +00:00
|
|
|
sp->fp) == NULL)
|
2019-02-15 21:06:09 +01:00
|
|
|
break;
|
2005-02-02 23:07:25 +00:00
|
|
|
len = ga.ga_len + (int)STRLEN(buf + ga.ga_len);
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef USE_CRNL
|
|
|
|
/* Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the
|
|
|
|
* CTRL-Z by its own, or after a NL. */
|
|
|
|
if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n'))
|
|
|
|
&& sp->fileformat == EOL_DOS
|
|
|
|
&& buf[len - 1] == Ctrl_Z)
|
|
|
|
{
|
|
|
|
buf[len - 1] = NUL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
have_read = TRUE;
|
|
|
|
ga.ga_len = len;
|
|
|
|
|
|
|
|
/* If the line was longer than the buffer, read more. */
|
2004-12-27 21:59:20 +00:00
|
|
|
if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n')
|
2004-06-13 20:20:40 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (len >= 1 && buf[len - 1] == '\n') /* remove trailing NL */
|
|
|
|
{
|
|
|
|
#ifdef USE_CRNL
|
|
|
|
has_cr = (len >= 2 && buf[len - 2] == '\r');
|
|
|
|
if (sp->fileformat == EOL_UNKNOWN)
|
|
|
|
{
|
|
|
|
if (has_cr)
|
|
|
|
sp->fileformat = EOL_DOS;
|
|
|
|
else
|
|
|
|
sp->fileformat = EOL_UNIX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sp->fileformat == EOL_DOS)
|
|
|
|
{
|
|
|
|
if (has_cr) /* replace trailing CR */
|
|
|
|
{
|
|
|
|
buf[len - 2] = '\n';
|
|
|
|
--len;
|
|
|
|
--ga.ga_len;
|
|
|
|
}
|
|
|
|
else /* lines like ":map xx yy^M" will have failed */
|
|
|
|
{
|
|
|
|
if (!sp->error)
|
2004-07-12 15:53:54 +00:00
|
|
|
{
|
2017-03-16 17:23:31 +01:00
|
|
|
msg_source(HL_ATTR(HLF_W));
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_("W15: Warning: Wrong line separator, ^M may be missing"));
|
2004-07-12 15:53:54 +00:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
sp->error = TRUE;
|
|
|
|
sp->fileformat = EOL_UNIX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* The '\n' is escaped if there is an odd number of ^V's just
|
|
|
|
* before it, first set "c" just before the 'V's and then check
|
|
|
|
* len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo */
|
|
|
|
for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--)
|
|
|
|
;
|
|
|
|
if ((len & 1) != (c & 1)) /* escaped NL, read more */
|
|
|
|
{
|
2019-07-04 14:57:12 +02:00
|
|
|
++sp->sourcing_lnum;
|
2004-06-13 20:20:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[len - 1] = NUL; /* remove the NL */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for ^C here now and then, so recursive :so can be broken.
|
|
|
|
*/
|
|
|
|
line_breakcheck();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_read)
|
|
|
|
return (char_u *)ga.ga_data;
|
|
|
|
|
|
|
|
vim_free(ga.ga_data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ":scriptencoding": Set encoding conversion for a sourced script.
|
|
|
|
*/
|
|
|
|
void
|
2019-04-04 18:15:38 +02:00
|
|
|
ex_scriptencoding(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
struct source_cookie *sp;
|
|
|
|
char_u *name;
|
|
|
|
|
|
|
|
if (!getline_equal(eap->getline, eap->cookie, getsourceline))
|
|
|
|
{
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_("E167: :scriptencoding used outside of a sourced file"));
|
2004-06-13 20:20:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*eap->arg != NUL)
|
|
|
|
{
|
|
|
|
name = enc_canonize(eap->arg);
|
|
|
|
if (name == NULL) /* out of memory */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
name = eap->arg;
|
|
|
|
|
|
|
|
/* Setup for conversion from the specified encoding to 'encoding'. */
|
|
|
|
sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie);
|
|
|
|
convert_setup(&sp->conv, name, p_enc);
|
|
|
|
|
|
|
|
if (name != eap->arg)
|
|
|
|
vim_free(name);
|
|
|
|
}
|
|
|
|
|
2019-04-04 18:15:38 +02:00
|
|
|
/*
|
|
|
|
* ":scriptversion": Set Vim script version for a sourced script.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ex_scriptversion(exarg_T *eap UNUSED)
|
|
|
|
{
|
2019-04-04 19:06:14 +02:00
|
|
|
#ifdef FEAT_EVAL
|
2019-04-04 18:15:38 +02:00
|
|
|
int nr;
|
|
|
|
|
|
|
|
if (!getline_equal(eap->getline, eap->cookie, getsourceline))
|
|
|
|
{
|
|
|
|
emsg(_("E984: :scriptversion used outside of a sourced file"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nr = getdigits(&eap->arg);
|
|
|
|
if (nr == 0 || *eap->arg != NUL)
|
|
|
|
emsg(_(e_invarg));
|
2019-04-20 14:39:52 +02:00
|
|
|
else if (nr > 3)
|
2019-04-04 18:15:38 +02:00
|
|
|
semsg(_("E999: scriptversion not supported: %d"), nr);
|
|
|
|
else
|
|
|
|
current_sctx.sc_version = nr;
|
2019-04-04 19:06:14 +02:00
|
|
|
#endif
|
2019-04-04 18:15:38 +02:00
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* ":finish": Mark a sourced file as finished.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ex_finish(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (getline_equal(eap->getline, eap->cookie, getsourceline))
|
|
|
|
do_finish(eap, FALSE);
|
|
|
|
else
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_("E168: :finish used outside of a sourced file"));
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark a sourced file as finished. Possibly makes the ":finish" pending.
|
|
|
|
* Also called for a pending finish at the ":endtry" or after returning from
|
|
|
|
* an extra do_cmdline(). "reanimate" is used in the latter case.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
do_finish(exarg_T *eap, int reanimate)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
if (reanimate)
|
|
|
|
((struct source_cookie *)getline_cookie(eap->getline,
|
|
|
|
eap->cookie))->finished = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup (and inactivate) conditionals, but stop when a try conditional
|
|
|
|
* not in its finally clause (which then is to be executed next) is found.
|
|
|
|
* In this case, make the ":finish" pending for execution at the ":endtry".
|
|
|
|
* Otherwise, finish normally.
|
|
|
|
*/
|
|
|
|
idx = cleanup_conditionals(eap->cstack, 0, TRUE);
|
|
|
|
if (idx >= 0)
|
|
|
|
{
|
|
|
|
eap->cstack->cs_pending[idx] = CSTP_FINISH;
|
|
|
|
report_make_pending(CSTP_FINISH, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
((struct source_cookie *)getline_cookie(eap->getline,
|
|
|
|
eap->cookie))->finished = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return TRUE when a sourced file had the ":finish" command: Don't give error
|
|
|
|
* message for missing ":endif".
|
|
|
|
* Return FALSE when not sourcing a file.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
source_finished(
|
2019-06-25 04:12:16 +02:00
|
|
|
char_u *(*fgetline)(int, void *, int, int),
|
2016-01-30 15:52:46 +01:00
|
|
|
void *cookie)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2006-08-29 15:30:07 +00:00
|
|
|
return (getline_equal(fgetline, cookie, getsourceline)
|
2004-06-13 20:20:40 +00:00
|
|
|
&& ((struct source_cookie *)getline_cookie(
|
2006-08-29 15:30:07 +00:00
|
|
|
fgetline, cookie))->finished);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ":checktime [buffer]"
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ex_checktime(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
buf_T *buf;
|
|
|
|
int save_no_check_timestamps = no_check_timestamps;
|
|
|
|
|
|
|
|
no_check_timestamps = 0;
|
|
|
|
if (eap->addr_count == 0) /* default is all buffers */
|
|
|
|
check_timestamps(FALSE);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf = buflist_findnr((int)eap->line2);
|
|
|
|
if (buf != NULL) /* cannot happen? */
|
|
|
|
(void)buf_check_timestamp(buf, FALSE);
|
|
|
|
}
|
|
|
|
no_check_timestamps = save_no_check_timestamps;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
|
|
|
|
&& (defined(FEAT_EVAL) || defined(FEAT_MULTI_LANG))
|
2010-07-27 22:41:43 +02:00
|
|
|
# define HAVE_GET_LOCALE_VAL
|
2016-02-16 15:06:59 +01:00
|
|
|
static char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
get_locale_val(int what)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2016-02-16 15:06:59 +01:00
|
|
|
char_u *loc;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2016-02-23 14:53:34 +01:00
|
|
|
/* Obtain the locale value from the libraries. */
|
2016-02-16 15:06:59 +01:00
|
|
|
loc = (char_u *)setlocale(what, NULL);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2019-02-17 17:44:42 +01:00
|
|
|
# ifdef MSWIN
|
2004-06-13 20:20:40 +00:00
|
|
|
if (loc != NULL)
|
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
|
2006-04-07 21:40:07 +00:00
|
|
|
/* setocale() returns something like "LC_COLLATE=<name>;LC_..." when
|
|
|
|
* one of the values (e.g., LC_CTYPE) differs. */
|
2004-06-13 20:20:40 +00:00
|
|
|
p = vim_strchr(loc, '=');
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
loc = ++p;
|
|
|
|
while (*p != NUL) /* remove trailing newline */
|
|
|
|
{
|
2006-04-07 21:40:07 +00:00
|
|
|
if (*p < ' ' || *p == ';')
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
*p = NUL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2019-02-17 17:44:42 +01:00
|
|
|
#ifdef MSWIN
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* On MS-Windows locale names are strings like "German_Germany.1252", but
|
|
|
|
* gettext expects "de". Try to translate one into another here for a few
|
|
|
|
* supported languages.
|
|
|
|
*/
|
|
|
|
static char_u *
|
|
|
|
gettext_lang(char_u *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
static char *(mtable[]) = {
|
|
|
|
"afrikaans", "af",
|
|
|
|
"czech", "cs",
|
|
|
|
"dutch", "nl",
|
|
|
|
"german", "de",
|
|
|
|
"english_united kingdom", "en_GB",
|
|
|
|
"spanish", "es",
|
|
|
|
"french", "fr",
|
|
|
|
"italian", "it",
|
|
|
|
"japanese", "ja",
|
|
|
|
"korean", "ko",
|
|
|
|
"norwegian", "no",
|
|
|
|
"polish", "pl",
|
|
|
|
"russian", "ru",
|
|
|
|
"slovak", "sk",
|
|
|
|
"swedish", "sv",
|
|
|
|
"ukrainian", "uk",
|
|
|
|
"chinese_china", "zh_CN",
|
|
|
|
"chinese_taiwan", "zh_TW",
|
|
|
|
NULL};
|
|
|
|
|
|
|
|
for (i = 0; mtable[i] != NULL; i += 2)
|
|
|
|
if (STRNICMP(mtable[i], name, STRLEN(mtable[i])) == 0)
|
2016-02-16 15:06:59 +01:00
|
|
|
return (char_u *)mtable[i + 1];
|
2004-06-13 20:20:40 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(FEAT_MULTI_LANG) || defined(PROTO)
|
2018-11-05 20:25:52 +01:00
|
|
|
/*
|
|
|
|
* Return TRUE when "lang" starts with a valid language name.
|
|
|
|
* Rejects NULL, empty string, "C", "C.UTF-8" and others.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
is_valid_mess_lang(char_u *lang)
|
|
|
|
{
|
|
|
|
return lang != NULL && ASCII_ISALPHA(lang[0]) && ASCII_ISALPHA(lang[1]);
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Obtain the current messages language. Used to set the default for
|
|
|
|
* 'helplang'. May return NULL or an empty string.
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
get_mess_lang(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
|
2010-07-27 22:41:43 +02:00
|
|
|
# ifdef HAVE_GET_LOCALE_VAL
|
2004-06-13 20:20:40 +00:00
|
|
|
# if defined(LC_MESSAGES)
|
2016-02-16 15:06:59 +01:00
|
|
|
p = get_locale_val(LC_MESSAGES);
|
2004-06-13 20:20:40 +00:00
|
|
|
# else
|
|
|
|
/* This is necessary for Win32, where LC_MESSAGES is not defined and $LANG
|
2006-04-07 21:40:07 +00:00
|
|
|
* may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME
|
|
|
|
* and LC_MONETARY may be set differently for a Japanese working in the
|
|
|
|
* US. */
|
2016-02-16 15:06:59 +01:00
|
|
|
p = get_locale_val(LC_COLLATE);
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
p = mch_getenv((char_u *)"LC_ALL");
|
2018-11-05 20:25:52 +01:00
|
|
|
if (!is_valid_mess_lang(p))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
p = mch_getenv((char_u *)"LC_MESSAGES");
|
2018-11-05 20:25:52 +01:00
|
|
|
if (!is_valid_mess_lang(p))
|
2004-06-13 20:20:40 +00:00
|
|
|
p = mch_getenv((char_u *)"LANG");
|
|
|
|
}
|
|
|
|
# endif
|
2019-02-17 17:44:42 +01:00
|
|
|
# ifdef MSWIN
|
2004-06-13 20:20:40 +00:00
|
|
|
p = gettext_lang(p);
|
|
|
|
# endif
|
2018-11-05 20:25:52 +01:00
|
|
|
return is_valid_mess_lang(p) ? p : NULL;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-12-31 20:58:58 +00:00
|
|
|
/* Complicated #if; matches with where get_mess_env() is used below. */
|
|
|
|
#if (defined(FEAT_EVAL) && !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
|
|
|
|
&& defined(LC_MESSAGES))) \
|
|
|
|
|| ((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
|
|
|
|
&& !defined(LC_MESSAGES))
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Get the language used for messages from the environment.
|
|
|
|
*/
|
|
|
|
static char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
get_mess_env(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
|
|
|
|
p = mch_getenv((char_u *)"LC_ALL");
|
|
|
|
if (p == NULL || *p == NUL)
|
|
|
|
{
|
|
|
|
p = mch_getenv((char_u *)"LC_MESSAGES");
|
|
|
|
if (p == NULL || *p == NUL)
|
|
|
|
{
|
|
|
|
p = mch_getenv((char_u *)"LANG");
|
|
|
|
if (p != NULL && VIM_ISDIGIT(*p))
|
|
|
|
p = NULL; /* ignore something like "1043" */
|
2010-07-27 22:41:43 +02:00
|
|
|
# ifdef HAVE_GET_LOCALE_VAL
|
2004-06-13 20:20:40 +00:00
|
|
|
if (p == NULL || *p == NUL)
|
2016-02-16 15:06:59 +01:00
|
|
|
p = get_locale_val(LC_CTYPE);
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the "v:lang" variable according to the current locale setting.
|
|
|
|
* Also do "v:lc_time"and "v:ctype".
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
set_lang_var(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *loc;
|
|
|
|
|
2010-07-27 22:41:43 +02:00
|
|
|
# ifdef HAVE_GET_LOCALE_VAL
|
2016-02-16 15:06:59 +01:00
|
|
|
loc = get_locale_val(LC_CTYPE);
|
2004-06-13 20:20:40 +00:00
|
|
|
# else
|
|
|
|
/* setlocale() not supported: use the default value */
|
|
|
|
loc = (char_u *)"C";
|
|
|
|
# endif
|
|
|
|
set_vim_var_string(VV_CTYPE, loc, -1);
|
|
|
|
|
|
|
|
/* When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall
|
|
|
|
* back to LC_CTYPE if it's empty. */
|
2010-07-27 22:41:43 +02:00
|
|
|
# if defined(HAVE_GET_LOCALE_VAL) && defined(LC_MESSAGES)
|
2016-02-16 15:06:59 +01:00
|
|
|
loc = get_locale_val(LC_MESSAGES);
|
2004-06-13 20:20:40 +00:00
|
|
|
# else
|
|
|
|
loc = get_mess_env();
|
|
|
|
# endif
|
|
|
|
set_vim_var_string(VV_LANG, loc, -1);
|
|
|
|
|
2010-07-27 22:41:43 +02:00
|
|
|
# ifdef HAVE_GET_LOCALE_VAL
|
2016-02-16 15:06:59 +01:00
|
|
|
loc = get_locale_val(LC_TIME);
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
set_vim_var_string(VV_LC_TIME, loc, -1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-01-24 15:54:21 +01:00
|
|
|
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE) \
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* ":language": Set the language (locale).
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ex_language(exarg_T *eap)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char *loc;
|
|
|
|
char_u *p;
|
|
|
|
char_u *name;
|
|
|
|
int what = LC_ALL;
|
|
|
|
char *whatstr = "";
|
|
|
|
#ifdef LC_MESSAGES
|
|
|
|
# define VIM_LC_MESSAGES LC_MESSAGES
|
|
|
|
#else
|
|
|
|
# define VIM_LC_MESSAGES 6789
|
|
|
|
#endif
|
|
|
|
|
|
|
|
name = eap->arg;
|
|
|
|
|
|
|
|
/* Check for "messages {name}", "ctype {name}" or "time {name}" argument.
|
|
|
|
* Allow abbreviation, but require at least 3 characters to avoid
|
|
|
|
* confusion with a two letter language name "me" or "ct". */
|
|
|
|
p = skiptowhite(eap->arg);
|
2017-03-12 20:10:05 +01:00
|
|
|
if ((*p == NUL || VIM_ISWHITE(*p)) && p - eap->arg >= 3)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0)
|
|
|
|
{
|
|
|
|
what = VIM_LC_MESSAGES;
|
|
|
|
name = skipwhite(p);
|
|
|
|
whatstr = "messages ";
|
|
|
|
}
|
|
|
|
else if (STRNICMP(eap->arg, "ctype", p - eap->arg) == 0)
|
|
|
|
{
|
|
|
|
what = LC_CTYPE;
|
|
|
|
name = skipwhite(p);
|
|
|
|
whatstr = "ctype ";
|
|
|
|
}
|
|
|
|
else if (STRNICMP(eap->arg, "time", p - eap->arg) == 0)
|
|
|
|
{
|
|
|
|
what = LC_TIME;
|
|
|
|
name = skipwhite(p);
|
|
|
|
whatstr = "time ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*name == NUL)
|
|
|
|
{
|
|
|
|
#ifndef LC_MESSAGES
|
|
|
|
if (what == VIM_LC_MESSAGES)
|
|
|
|
p = get_mess_env();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
p = (char_u *)setlocale(what, NULL);
|
|
|
|
if (p == NULL || *p == NUL)
|
|
|
|
p = (char_u *)"Unknown";
|
2019-01-13 23:38:42 +01:00
|
|
|
smsg(_("Current %slanguage: \"%s\""), whatstr, p);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifndef LC_MESSAGES
|
|
|
|
if (what == VIM_LC_MESSAGES)
|
|
|
|
loc = "";
|
|
|
|
else
|
|
|
|
#endif
|
2008-06-24 22:58:06 +00:00
|
|
|
{
|
2004-06-13 20:20:40 +00:00
|
|
|
loc = setlocale(what, (char *)name);
|
2008-06-24 22:58:06 +00:00
|
|
|
#if defined(FEAT_FLOAT) && defined(LC_NUMERIC)
|
|
|
|
/* Make sure strtod() uses a decimal point, not a comma. */
|
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
#endif
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
if (loc == NULL)
|
2019-01-13 23:38:42 +01:00
|
|
|
semsg(_("E197: Cannot set language to \"%s\""), name);
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef HAVE_NL_MSG_CAT_CNTR
|
|
|
|
/* Need to do this for GNU gettext, otherwise cached translations
|
|
|
|
* will be used again. */
|
|
|
|
extern int _nl_msg_cat_cntr;
|
|
|
|
|
|
|
|
++_nl_msg_cat_cntr;
|
|
|
|
#endif
|
2007-05-10 18:59:07 +00:00
|
|
|
/* Reset $LC_ALL, otherwise it would overrule everything. */
|
2004-06-13 20:20:40 +00:00
|
|
|
vim_setenv((char_u *)"LC_ALL", (char_u *)"");
|
|
|
|
|
|
|
|
if (what != LC_TIME)
|
|
|
|
{
|
|
|
|
/* Tell gettext() what to translate to. It apparently doesn't
|
|
|
|
* use the currently effective locale. Also do this when
|
|
|
|
* FEAT_GETTEXT isn't defined, so that shell commands use this
|
|
|
|
* value. */
|
|
|
|
if (what == LC_ALL)
|
2005-09-29 18:26:07 +00:00
|
|
|
{
|
2004-06-13 20:20:40 +00:00
|
|
|
vim_setenv((char_u *)"LANG", name);
|
2013-06-28 20:36:30 +02:00
|
|
|
|
|
|
|
/* Clear $LANGUAGE because GNU gettext uses it. */
|
|
|
|
vim_setenv((char_u *)"LANGUAGE", (char_u *)"");
|
2019-02-17 17:44:42 +01:00
|
|
|
# ifdef MSWIN
|
2005-09-29 18:26:07 +00:00
|
|
|
/* Apparently MS-Windows printf() may cause a crash when
|
|
|
|
* we give it 8-bit text while it's expecting text in the
|
|
|
|
* current locale. This call avoids that. */
|
|
|
|
setlocale(LC_CTYPE, "C");
|
|
|
|
# endif
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
if (what != LC_CTYPE)
|
|
|
|
{
|
|
|
|
char_u *mname;
|
2019-02-17 17:44:42 +01:00
|
|
|
#ifdef MSWIN
|
2004-06-13 20:20:40 +00:00
|
|
|
mname = gettext_lang(name);
|
|
|
|
#else
|
|
|
|
mname = name;
|
|
|
|
#endif
|
|
|
|
vim_setenv((char_u *)"LC_MESSAGES", mname);
|
|
|
|
#ifdef FEAT_MULTI_LANG
|
|
|
|
set_helplang_default(mname);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# ifdef FEAT_EVAL
|
|
|
|
/* Set v:lang, v:lc_time and v:ctype to the final result. */
|
|
|
|
set_lang_var();
|
2011-10-20 21:41:09 +02:00
|
|
|
# endif
|
|
|
|
# ifdef FEAT_TITLE
|
|
|
|
maketitle();
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
2011-05-19 18:26:40 +02:00
|
|
|
|
|
|
|
static char_u **locales = NULL; /* Array of all available locales */
|
|
|
|
|
2019-02-17 17:44:42 +01:00
|
|
|
# ifndef MSWIN
|
2017-01-12 20:28:25 +01:00
|
|
|
static int did_init_locales = FALSE;
|
2011-05-19 18:26:40 +02:00
|
|
|
|
|
|
|
/* Return an array of strings for all available locales + NULL for the
|
|
|
|
* last element. Return NULL in case of error. */
|
|
|
|
static char_u **
|
2016-01-30 15:52:46 +01:00
|
|
|
find_locales(void)
|
2011-05-19 18:26:40 +02:00
|
|
|
{
|
|
|
|
garray_T locales_ga;
|
|
|
|
char_u *loc;
|
|
|
|
|
|
|
|
/* Find all available locales by running command "locale -a". If this
|
|
|
|
* doesn't work we won't have completion. */
|
|
|
|
char_u *locale_a = get_cmd_output((char_u *)"locale -a",
|
2014-04-05 19:44:40 +02:00
|
|
|
NULL, SHELL_SILENT, NULL);
|
2011-05-19 18:26:40 +02:00
|
|
|
if (locale_a == NULL)
|
|
|
|
return NULL;
|
|
|
|
ga_init2(&locales_ga, sizeof(char_u *), 20);
|
|
|
|
|
|
|
|
/* Transform locale_a string where each locale is separated by "\n"
|
|
|
|
* into an array of locale strings. */
|
|
|
|
loc = (char_u *)strtok((char *)locale_a, "\n");
|
|
|
|
|
|
|
|
while (loc != NULL)
|
|
|
|
{
|
|
|
|
if (ga_grow(&locales_ga, 1) == FAIL)
|
|
|
|
break;
|
|
|
|
loc = vim_strsave(loc);
|
|
|
|
if (loc == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc;
|
|
|
|
loc = (char_u *)strtok(NULL, "\n");
|
|
|
|
}
|
|
|
|
vim_free(locale_a);
|
|
|
|
if (ga_grow(&locales_ga, 1) == FAIL)
|
|
|
|
{
|
|
|
|
ga_clear(&locales_ga);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL;
|
|
|
|
return (char_u **)locales_ga.ga_data;
|
|
|
|
}
|
2017-01-12 20:28:25 +01:00
|
|
|
# endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lazy initialization of all available locales.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
init_locales(void)
|
|
|
|
{
|
2019-02-17 17:44:42 +01:00
|
|
|
# ifndef MSWIN
|
2017-01-12 20:28:25 +01:00
|
|
|
if (!did_init_locales)
|
|
|
|
{
|
|
|
|
did_init_locales = TRUE;
|
|
|
|
locales = find_locales();
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
}
|
2011-05-19 18:26:40 +02:00
|
|
|
|
|
|
|
# if defined(EXITFREE) || defined(PROTO)
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
free_locales(void)
|
2011-05-19 18:26:40 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (locales != NULL)
|
|
|
|
{
|
|
|
|
for (i = 0; locales[i] != NULL; i++)
|
|
|
|
vim_free(locales[i]);
|
2018-02-10 18:45:26 +01:00
|
|
|
VIM_CLEAR(locales);
|
2011-05-19 18:26:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Function given to ExpandGeneric() to obtain the possible arguments of the
|
|
|
|
* ":language" command.
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
get_lang_arg(expand_T *xp UNUSED, int idx)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (idx == 0)
|
|
|
|
return (char_u *)"messages";
|
|
|
|
if (idx == 1)
|
|
|
|
return (char_u *)"ctype";
|
|
|
|
if (idx == 2)
|
|
|
|
return (char_u *)"time";
|
2011-05-19 18:26:40 +02:00
|
|
|
|
|
|
|
init_locales();
|
|
|
|
if (locales == NULL)
|
|
|
|
return NULL;
|
|
|
|
return locales[idx - 3];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function given to ExpandGeneric() to obtain the available locales.
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
get_locales(expand_T *xp UNUSED, int idx)
|
2011-05-19 18:26:40 +02:00
|
|
|
{
|
|
|
|
init_locales();
|
|
|
|
if (locales == NULL)
|
|
|
|
return NULL;
|
|
|
|
return locales[idx];
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
#endif
|