~ubuntu-branches/ubuntu/utopic/vim/utopic

« back to all changes in this revision

Viewing changes to src/buffer.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2009-01-13 18:39:18 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090113183918-kgq1jzdwsbbex4pq
Tags: 2:7.2.079-1ubuntu1
* Resynchronise with Debian (diversions fix closes LP: #296324). Remaining
  changes:
  - runtime/syntax/debcontrol.vim:
    + Add "metapackages" to the list of valid sections.
  - runtime/syntax/debchangelog.vim:
    + Add "jaunty" to the list of valid suites.
  - Drop vim-lesstif package and lesstif2-dev build-dependency.
  - Enable Python interpreter on basic builds.
  - Create a .pot file for translations.
  - Disable autoindent, line-wrapping, and backup files by default.
  - runtime/syntax/debsources.vim:
    + Add "jaunty" to debsourcesDistrKeyword
  - runtime/syntax/grub.vim:
    + Add Ubuntu-specific 'quiet' keyword.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
static char_u   *fname_match __ARGS((regprog_T *prog, char_u *name));
34
34
#endif
35
35
static void     buflist_setfpos __ARGS((buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options));
36
 
static wininfo_T *find_wininfo __ARGS((buf_T *buf));
 
36
static wininfo_T *find_wininfo __ARGS((buf_T *buf, int skip_diff_buffer));
37
37
#ifdef UNIX
38
38
static buf_T    *buflist_findname_stat __ARGS((char_u *ffname, struct stat *st));
39
39
static int      otherfile_buf __ARGS((buf_T *buf, char_u *ffname, struct stat *stp));
437
437
        return;
438
438
#endif
439
439
 
440
 
#ifdef FEAT_NETBEANS_INTG
441
 
    if (usingNetbeans)
442
 
        netbeans_file_closed(buf);
443
 
#endif
444
440
    /* Change directories when the 'acd' option is set. */
445
441
    DO_AUTOCHDIR
446
442
 
639
635
#ifdef FEAT_SIGNS
640
636
    buf_delete_signs(buf);              /* delete any signs */
641
637
#endif
 
638
#ifdef FEAT_NETBEANS_INTG
 
639
    if (usingNetbeans)
 
640
        netbeans_file_killed(buf);
 
641
#endif
642
642
#ifdef FEAT_LOCALMAP
643
643
    map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE);  /* clear local mappings */
644
644
    map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE);   /* clear local abbrevs */
647
647
    vim_free(buf->b_start_fenc);
648
648
    buf->b_start_fenc = NULL;
649
649
#endif
 
650
#ifdef FEAT_SPELL
 
651
    ga_clear(&buf->b_langp);
 
652
#endif
650
653
}
651
654
 
652
655
/*
812
815
    int         bnr;            /* buffer number */
813
816
    char_u      *p;
814
817
 
815
 
#ifdef FEAT_NETBEANS_INTG
816
 
    netbeansCloseFile = 1;
817
 
#endif
818
818
    if (addr_count == 0)
819
819
    {
820
820
        (void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit);
909
909
        }
910
910
    }
911
911
 
912
 
#ifdef FEAT_NETBEANS_INTG
913
 
    netbeansCloseFile = 0;
914
 
#endif
915
912
 
916
913
    return errormsg;
917
914
}
1090
1087
#endif
1091
1088
            setpcmark();
1092
1089
            retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE,
1093
 
                                                  forceit ? ECMD_FORCEIT : 0);
 
1090
                                          forceit ? ECMD_FORCEIT : 0, curwin);
1094
1091
 
1095
1092
            /*
1096
1093
             * do_ecmd() may create a new buffer, then we have to delete
1237
1234
         * "buf" if one exists */
1238
1235
        if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf))
1239
1236
            return OK;
1240
 
        /* If 'switchbuf' contians "usetab": jump to first window in any tab
 
1237
        /* If 'switchbuf' contains "usetab": jump to first window in any tab
1241
1238
         * page containing "buf" if one exists */
1242
1239
        if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf))
1243
1240
            return OK;
1313
1310
    setpcmark();
1314
1311
    if (!cmdmod.keepalt)
1315
1312
        curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */
1316
 
    buflist_altfpos();                   /* remember curpos */
 
1313
    buflist_altfpos(curwin);                     /* remember curpos */
1317
1314
 
1318
1315
#ifdef FEAT_VISUAL
1319
1316
    /* Don't restart Select mode after switching to another buffer. */
1398
1395
    curwin->w_cursor.coladd = 0;
1399
1396
#endif
1400
1397
    curwin->w_set_curswant = TRUE;
 
1398
#ifdef FEAT_AUTOCMD
 
1399
    curwin->w_topline_was_set = FALSE;
 
1400
#endif
1401
1401
 
1402
1402
    /* Make sure the buffer is loaded. */
1403
1403
    if (curbuf->b_ml.ml_mfp == NULL)    /* need to load the file */
1437
1437
    maketitle();
1438
1438
#endif
1439
1439
#ifdef FEAT_AUTOCMD
1440
 
    if (curwin->w_topline == 1)         /* when autocmds didn't change it */
 
1440
        /* when autocmds didn't change it */
 
1441
    if (curwin->w_topline == 1 && !curwin->w_topline_was_set)
1441
1442
#endif
1442
1443
        scroll_cursor_halfway(FALSE);   /* redisplay at correct position */
1443
1444
 
2401
2402
    return;
2402
2403
}
2403
2404
 
 
2405
#ifdef FEAT_DIFF
 
2406
static int wininfo_other_tab_diff __ARGS((wininfo_T *wip));
 
2407
 
 
2408
/*
 
2409
 * Return TRUE when "wip" has 'diff' set and the diff is only for another tab
 
2410
 * page.  That's because a diff is local to a tab page.
 
2411
 */
 
2412
    static int
 
2413
wininfo_other_tab_diff(wip)
 
2414
    wininfo_T   *wip;
 
2415
{
 
2416
    win_T       *wp;
 
2417
 
 
2418
    if (wip->wi_opt.wo_diff)
 
2419
    {
 
2420
        for (wp = firstwin; wp != NULL; wp = wp->w_next)
 
2421
            /* return FALSE when it's a window in the current tab page, thus
 
2422
             * the buffer was in diff mode here */
 
2423
            if (wip->wi_win == wp)
 
2424
                return FALSE;
 
2425
        return TRUE;
 
2426
    }
 
2427
    return FALSE;
 
2428
}
 
2429
#endif
 
2430
 
2404
2431
/*
2405
2432
 * Find info for the current window in buffer "buf".
2406
2433
 * If not found, return the info for the most recently used window.
 
2434
 * When "skip_diff_buffer" is TRUE avoid windows with 'diff' set that is in
 
2435
 * another tab page.
2407
2436
 * Returns NULL when there isn't any info.
2408
2437
 */
 
2438
/*ARGSUSED*/
2409
2439
    static wininfo_T *
2410
 
find_wininfo(buf)
 
2440
find_wininfo(buf, skip_diff_buffer)
2411
2441
    buf_T       *buf;
 
2442
    int         skip_diff_buffer;
2412
2443
{
2413
2444
    wininfo_T   *wip;
2414
2445
 
2415
2446
    for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
2416
 
        if (wip->wi_win == curwin)
 
2447
        if (wip->wi_win == curwin
 
2448
#ifdef FEAT_DIFF
 
2449
                && (!skip_diff_buffer || !wininfo_other_tab_diff(wip))
 
2450
#endif
 
2451
           )
2417
2452
            break;
2418
 
    if (wip == NULL)    /* if no fpos for curwin, use the first in the list */
2419
 
        wip = buf->b_wininfo;
 
2453
 
 
2454
    /* If no wininfo for curwin, use the first in the list (that doesn't have
 
2455
     * 'diff' set and is in another tab page). */
 
2456
    if (wip == NULL)
 
2457
    {
 
2458
#ifdef FEAT_DIFF
 
2459
        if (skip_diff_buffer)
 
2460
        {
 
2461
            for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
 
2462
                if (!wininfo_other_tab_diff(wip))
 
2463
                    break;
 
2464
        }
 
2465
        else
 
2466
#endif
 
2467
            wip = buf->b_wininfo;
 
2468
    }
2420
2469
    return wip;
2421
2470
}
2422
2471
 
2437
2486
    clearFolding(curwin);
2438
2487
#endif
2439
2488
 
2440
 
    wip = find_wininfo(buf);
 
2489
    wip = find_wininfo(buf, TRUE);
2441
2490
    if (wip != NULL && wip->wi_optset)
2442
2491
    {
2443
2492
        copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt);
2469
2518
    wininfo_T   *wip;
2470
2519
    static pos_T no_position = {1, 0};
2471
2520
 
2472
 
    wip = find_wininfo(buf);
 
2521
    wip = find_wininfo(buf, FALSE);
2473
2522
    if (wip != NULL)
2474
2523
        return &(wip->wi_fpos);
2475
2524
    else
2790
2839
#endif
2791
2840
 
2792
2841
/*
2793
 
 * Set alternate cursor position for current window.
 
2842
 * Set alternate cursor position for the current buffer and window "win".
2794
2843
 * Also save the local window option values.
2795
2844
 */
2796
2845
    void
2797
 
buflist_altfpos()
 
2846
buflist_altfpos(win)
 
2847
    win_T *win;
2798
2848
{
2799
 
    buflist_setfpos(curbuf, curwin, curwin->w_cursor.lnum,
2800
 
                                                  curwin->w_cursor.col, TRUE);
 
2849
    buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, TRUE);
2801
2850
}
2802
2851
 
2803
2852
/*
3964
4013
    width = vim_strsize(out);
3965
4014
    if (maxwidth > 0 && width > maxwidth)
3966
4015
    {
3967
 
        /* Result is too long, must trunctate somewhere. */
 
4016
        /* Result is too long, must truncate somewhere. */
3968
4017
        l = 0;
3969
4018
        if (itemcnt == 0)
3970
4019
            s = out;
4489
4538
                      ECMD_ONE,
4490
4539
                      ((P_HID(curwin->w_buffer)
4491
4540
                           || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0)
4492
 
                                                               + ECMD_OLDBUF);
 
4541
                                                       + ECMD_OLDBUF, curwin);
4493
4542
#ifdef FEAT_AUTOCMD
4494
4543
            if (use_firstwin)
4495
4544
                ++autocmd_no_leave;
5063
5112
    {
5064
5113
        if (buf->b_sfname != NULL)
5065
5114
            return (char *)buf->b_sfname;
5066
 
        return "[Scratch]";
 
5115
        return _("[Scratch]");
5067
5116
    }
5068
5117
#endif
5069
5118
    if (buf->b_fname == NULL)