Mercurial > vim
comparison src/ex_docmd.c @ 27617:269f89efb06a v8.2.4335
patch 8.2.4335: no autocommand event triggered before changing directory
Commit: https://github.com/vim/vim/commit/28e8f73ae2d90009fd62cd60f97c2643ba44de68
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 9 12:58:20 2022 +0000
patch 8.2.4335: no autocommand event triggered before changing directory
Problem: No autocommand event triggered before changing directory. (Ronnie
Magatti)
Solution: Add DirChangedPre. (closes #9721)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 09 Feb 2022 14:00:05 +0100 |
parents | 9986f96fb1bd |
children | 1712b102d642 |
comparison
equal
deleted
inserted
replaced
27616:431c6a7a1f8b | 27617:269f89efb06a |
---|---|
7341 last_chdir_reason = NULL; | 7341 last_chdir_reason = NULL; |
7342 shorten_fnames(TRUE); | 7342 shorten_fnames(TRUE); |
7343 } | 7343 } |
7344 | 7344 |
7345 /* | 7345 /* |
7346 * Trigger DirChangedPre for "acmd_fname" with directory "new_dir". | |
7347 */ | |
7348 void | |
7349 trigger_DirChangedPre(char_u *acmd_fname, char_u *new_dir) | |
7350 { | |
7351 #ifdef FEAT_EVAL | |
7352 dict_T *v_event; | |
7353 save_v_event_T save_v_event; | |
7354 | |
7355 v_event = get_v_event(&save_v_event); | |
7356 (void)dict_add_string(v_event, "directory", new_dir); | |
7357 dict_set_items_ro(v_event); | |
7358 #endif | |
7359 apply_autocmds(EVENT_DIRCHANGEDPRE, acmd_fname, new_dir, FALSE, curbuf); | |
7360 #ifdef FEAT_EVAL | |
7361 restore_v_event(v_event, &save_v_event); | |
7362 #endif | |
7363 } | |
7364 | |
7365 /* | |
7346 * Change directory function used by :cd/:tcd/:lcd Ex commands and the | 7366 * Change directory function used by :cd/:tcd/:lcd Ex commands and the |
7347 * chdir() function. | 7367 * chdir() function. |
7348 * scope == CDSCOPE_WINDOW: changes the window-local directory | 7368 * scope == CDSCOPE_WINDOW: changes the window-local directory |
7349 * scope == CDSCOPE_TABPAGE: changes the tab-local directory | 7369 * scope == CDSCOPE_TABPAGE: changes the tab-local directory |
7350 * Otherwise: changes the global directory | 7370 * Otherwise: changes the global directory |
7356 int forceit, | 7376 int forceit, |
7357 cdscope_T scope) | 7377 cdscope_T scope) |
7358 { | 7378 { |
7359 char_u *pdir = NULL; | 7379 char_u *pdir = NULL; |
7360 int dir_differs; | 7380 int dir_differs; |
7361 char_u *acmd_fname; | 7381 char_u *acmd_fname = NULL; |
7362 char_u **pp; | 7382 char_u **pp; |
7363 | 7383 |
7364 if (new_dir == NULL || allbuf_locked()) | 7384 if (new_dir == NULL || allbuf_locked()) |
7365 return FALSE; | 7385 return FALSE; |
7366 | 7386 |
7409 expand_env((char_u *)"$HOME", NameBuff, MAXPATHL); | 7429 expand_env((char_u *)"$HOME", NameBuff, MAXPATHL); |
7410 # endif | 7430 # endif |
7411 new_dir = NameBuff; | 7431 new_dir = NameBuff; |
7412 } | 7432 } |
7413 dir_differs = pdir == NULL | 7433 dir_differs = pdir == NULL |
7414 || pathcmp((char *)pdir, (char *)new_dir, -1) != 0; | 7434 || pathcmp((char *)pdir, (char *)new_dir, -1) != 0; |
7415 if (dir_differs && vim_chdir(new_dir)) | 7435 if (dir_differs) |
7416 { | 7436 { |
7417 emsg(_(e_command_failed)); | 7437 if (scope == CDSCOPE_WINDOW) |
7418 vim_free(pdir); | 7438 acmd_fname = (char_u *)"window"; |
7419 return FALSE; | 7439 else if (scope == CDSCOPE_TABPAGE) |
7440 acmd_fname = (char_u *)"tabpage"; | |
7441 else | |
7442 acmd_fname = (char_u *)"global"; | |
7443 trigger_DirChangedPre(acmd_fname, new_dir); | |
7444 | |
7445 if (vim_chdir(new_dir)) | |
7446 { | |
7447 emsg(_(e_command_failed)); | |
7448 vim_free(pdir); | |
7449 return FALSE; | |
7450 } | |
7420 } | 7451 } |
7421 | 7452 |
7422 if (scope == CDSCOPE_WINDOW) | 7453 if (scope == CDSCOPE_WINDOW) |
7423 pp = &curwin->w_prevdir; | 7454 pp = &curwin->w_prevdir; |
7424 else if (scope == CDSCOPE_TABPAGE) | 7455 else if (scope == CDSCOPE_TABPAGE) |
7429 *pp = pdir; | 7460 *pp = pdir; |
7430 | 7461 |
7431 post_chdir(scope); | 7462 post_chdir(scope); |
7432 | 7463 |
7433 if (dir_differs) | 7464 if (dir_differs) |
7434 { | 7465 apply_autocmds(EVENT_DIRCHANGED, acmd_fname, new_dir, FALSE, curbuf); |
7435 if (scope == CDSCOPE_WINDOW) | |
7436 acmd_fname = (char_u *)"window"; | |
7437 else if (scope == CDSCOPE_TABPAGE) | |
7438 acmd_fname = (char_u *)"tabpage"; | |
7439 else | |
7440 acmd_fname = (char_u *)"global"; | |
7441 apply_autocmds(EVENT_DIRCHANGED, acmd_fname, new_dir, FALSE, | |
7442 curbuf); | |
7443 } | |
7444 return TRUE; | 7466 return TRUE; |
7445 } | 7467 } |
7446 | 7468 |
7447 /* | 7469 /* |
7448 * ":cd", ":tcd", ":lcd", ":chdir" ":tchdir" and ":lchdir". | 7470 * ":cd", ":tcd", ":lcd", ":chdir" ":tchdir" and ":lchdir". |