comparison src/ex_cmds.c @ 4589:fa39483a1363 v7.3.1042

updated for version 7.3.1042 Problem: Python: can't assign to vim.Buffer.name. Solution: Python patch 3. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Wed, 29 May 2013 22:02:22 +0200
parents 6c2e8074ea25
children 219b2fcad60d
comparison
equal deleted inserted replaced
4588:15cf120f2a68 4589:fa39483a1363
782 * And Finally we adjust the marks we put at the end of the file back to 782 * And Finally we adjust the marks we put at the end of the file back to
783 * their final destination at the new text position -- webb 783 * their final destination at the new text position -- webb
784 */ 784 */
785 last_line = curbuf->b_ml.ml_line_count; 785 last_line = curbuf->b_ml.ml_line_count;
786 mark_adjust(line1, line2, last_line - line2, 0L); 786 mark_adjust(line1, line2, last_line - line2, 0L);
787 changed_lines(last_line - num_lines + 1, 0, last_line + 1, num_lines);
787 if (dest >= line2) 788 if (dest >= line2)
788 { 789 {
789 mark_adjust(line2 + 1, dest, -num_lines, 0L); 790 mark_adjust(line2 + 1, dest, -num_lines, 0L);
790 curbuf->b_op_start.lnum = dest - num_lines + 1; 791 curbuf->b_op_start.lnum = dest - num_lines + 1;
791 curbuf->b_op_end.lnum = dest; 792 curbuf->b_op_end.lnum = dest;
797 curbuf->b_op_end.lnum = dest + num_lines; 798 curbuf->b_op_end.lnum = dest + num_lines;
798 } 799 }
799 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; 800 curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
800 mark_adjust(last_line - num_lines + 1, last_line, 801 mark_adjust(last_line - num_lines + 1, last_line,
801 -(last_line - dest - extra), 0L); 802 -(last_line - dest - extra), 0L);
803 changed_lines(last_line - num_lines + 1, 0, last_line + 1, -extra);
802 804
803 /* 805 /*
804 * Now we delete the original text -- webb 806 * Now we delete the original text -- webb
805 */ 807 */
806 if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL) 808 if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL)
2412 silent_mode = save_silent; 2414 silent_mode = save_silent;
2413 } 2415 }
2414 info_message = FALSE; 2416 info_message = FALSE;
2415 } 2417 }
2416 2418
2419 int
2420 rename_buffer(new_fname)
2421 char_u *new_fname;
2422 {
2423 char_u *fname, *sfname, *xfname;
2424 #ifdef FEAT_AUTOCMD
2425 buf_T *buf = curbuf;
2426
2427 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, buf);
2428 /* buffer changed, don't change name now */
2429 if (buf != curbuf)
2430 return FAIL;
2431 # ifdef FEAT_EVAL
2432 if (aborting()) /* autocmds may abort script processing */
2433 return FAIL;
2434 # endif
2435 #endif
2436 /*
2437 * The name of the current buffer will be changed.
2438 * A new (unlisted) buffer entry needs to be made to hold the old file
2439 * name, which will become the alternate file name.
2440 * But don't set the alternate file name if the buffer didn't have a
2441 * name.
2442 */
2443 fname = buf->b_ffname;
2444 sfname = buf->b_sfname;
2445 xfname = buf->b_fname;
2446 buf->b_ffname = NULL;
2447 buf->b_sfname = NULL;
2448 if (setfname(buf, new_fname, NULL, TRUE) == FAIL)
2449 {
2450 buf->b_ffname = fname;
2451 buf->b_sfname = sfname;
2452 return FAIL;
2453 }
2454 buf->b_flags |= BF_NOTEDITED;
2455 if (xfname != NULL && *xfname != NUL)
2456 {
2457 buf = buflist_new(fname, xfname, curwin->w_cursor.lnum, 0);
2458 if (buf != NULL && !cmdmod.keepalt)
2459 curwin->w_alt_fnum = buf->b_fnum;
2460 }
2461 vim_free(fname);
2462 vim_free(sfname);
2463 #ifdef FEAT_AUTOCMD
2464 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, buf);
2465 #endif
2466 /* Change directories when the 'acd' option is set. */
2467 DO_AUTOCHDIR
2468 return OK;
2469 }
2470
2417 /* 2471 /*
2418 * ":file[!] [fname]". 2472 * ":file[!] [fname]".
2419 */ 2473 */
2420 void 2474 void
2421 ex_file(eap) 2475 ex_file(eap)
2422 exarg_T *eap; 2476 exarg_T *eap;
2423 { 2477 {
2424 char_u *fname, *sfname, *xfname;
2425 buf_T *buf;
2426
2427 /* ":0file" removes the file name. Check for illegal uses ":3file", 2478 /* ":0file" removes the file name. Check for illegal uses ":3file",
2428 * "0file name", etc. */ 2479 * "0file name", etc. */
2429 if (eap->addr_count > 0 2480 if (eap->addr_count > 0
2430 && (*eap->arg != NUL 2481 && (*eap->arg != NUL
2431 || eap->line2 > 0 2482 || eap->line2 > 0
2435 return; 2486 return;
2436 } 2487 }
2437 2488
2438 if (*eap->arg != NUL || eap->addr_count == 1) 2489 if (*eap->arg != NUL || eap->addr_count == 1)
2439 { 2490 {
2440 #ifdef FEAT_AUTOCMD 2491 if (rename_buffer(eap->arg) == FAIL)
2441 buf = curbuf;
2442 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf);
2443 /* buffer changed, don't change name now */
2444 if (buf != curbuf)
2445 return; 2492 return;
2446 # ifdef FEAT_EVAL
2447 if (aborting()) /* autocmds may abort script processing */
2448 return;
2449 # endif
2450 #endif
2451 /*
2452 * The name of the current buffer will be changed.
2453 * A new (unlisted) buffer entry needs to be made to hold the old file
2454 * name, which will become the alternate file name.
2455 * But don't set the alternate file name if the buffer didn't have a
2456 * name.
2457 */
2458 fname = curbuf->b_ffname;
2459 sfname = curbuf->b_sfname;
2460 xfname = curbuf->b_fname;
2461 curbuf->b_ffname = NULL;
2462 curbuf->b_sfname = NULL;
2463 if (setfname(curbuf, eap->arg, NULL, TRUE) == FAIL)
2464 {
2465 curbuf->b_ffname = fname;
2466 curbuf->b_sfname = sfname;
2467 return;
2468 }
2469 curbuf->b_flags |= BF_NOTEDITED;
2470 if (xfname != NULL && *xfname != NUL)
2471 {
2472 buf = buflist_new(fname, xfname, curwin->w_cursor.lnum, 0);
2473 if (buf != NULL && !cmdmod.keepalt)
2474 curwin->w_alt_fnum = buf->b_fnum;
2475 }
2476 vim_free(fname);
2477 vim_free(sfname);
2478 #ifdef FEAT_AUTOCMD
2479 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf);
2480 #endif
2481 /* Change directories when the 'acd' option is set. */
2482 DO_AUTOCHDIR
2483 } 2493 }
2484 /* print full file name if :cd used */ 2494 /* print full file name if :cd used */
2485 fileinfo(FALSE, FALSE, eap->forceit); 2495 fileinfo(FALSE, FALSE, eap->forceit);
2486 } 2496 }
2487 2497