Mercurial > vim
comparison src/buffer.c @ 17458:cfdef48743ed v8.1.1727
patch 8.1.1727: code for viminfo support is spread out
commit https://github.com/vim/vim/commit/defa067c54874dd987121dd7252c62755e0aebfa
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 21 19:25:37 2019 +0200
patch 8.1.1727: code for viminfo support is spread out
Problem: Code for viminfo support is spread out.
Solution: Move to code to viminfo.c. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4686)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 21 Jul 2019 19:30:06 +0200 |
parents | 09fa437d33d8 |
children | 711db62c8aca |
comparison
equal
deleted
inserted
replaced
17457:3a368ff28a0b | 17458:cfdef48743ed |
---|---|
27 | 27 |
28 #include "vim.h" | 28 #include "vim.h" |
29 | 29 |
30 static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, int ignore_case); | 30 static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, int ignore_case); |
31 static char_u *fname_match(regmatch_T *rmp, char_u *name, int ignore_case); | 31 static char_u *fname_match(regmatch_T *rmp, char_u *name, int ignore_case); |
32 static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options); | |
33 #ifdef UNIX | 32 #ifdef UNIX |
34 static buf_T *buflist_findname_stat(char_u *ffname, stat_T *st); | 33 static buf_T *buflist_findname_stat(char_u *ffname, stat_T *st); |
35 static int otherfile_buf(buf_T *buf, char_u *ffname, stat_T *stp); | 34 static int otherfile_buf(buf_T *buf, char_u *ffname, stat_T *stp); |
36 static int buf_same_ino(buf_T *buf, stat_T *stp); | 35 static int buf_same_ino(buf_T *buf, stat_T *stp); |
37 #else | 36 #else |
447 can_unload = FALSE; | 446 can_unload = FALSE; |
448 break; | 447 break; |
449 } | 448 } |
450 } | 449 } |
451 if (!can_unload) | 450 if (!can_unload) |
452 emsg(_("E937: Attempt to delete a buffer that is in use")); | 451 semsg(_("E937: Attempt to delete a buffer that is in use: %s"), |
452 buf->b_fname); | |
453 return can_unload; | 453 return can_unload; |
454 } | 454 } |
455 | 455 |
456 /* | 456 /* |
457 * Close the link to a buffer. | 457 * Close the link to a buffer. |
2772 /* | 2772 /* |
2773 * Set the "lnum" and "col" for the buffer "buf" and the current window. | 2773 * Set the "lnum" and "col" for the buffer "buf" and the current window. |
2774 * When "copy_options" is TRUE save the local window option values. | 2774 * When "copy_options" is TRUE save the local window option values. |
2775 * When "lnum" is 0 only do the options. | 2775 * When "lnum" is 0 only do the options. |
2776 */ | 2776 */ |
2777 static void | 2777 void |
2778 buflist_setfpos( | 2778 buflist_setfpos( |
2779 buf_T *buf, | 2779 buf_T *buf, |
2780 win_T *win, | 2780 win_T *win, |
2781 linenr_T lnum, | 2781 linenr_T lnum, |
2782 colnr_T col, | 2782 colnr_T col, |
5543 vim_free(linecopy); | 5543 vim_free(linecopy); |
5544 } | 5544 } |
5545 return retval; | 5545 return retval; |
5546 } | 5546 } |
5547 | 5547 |
5548 #if defined(FEAT_VIMINFO) || defined(PROTO) | |
5549 int | |
5550 read_viminfo_bufferlist( | |
5551 vir_T *virp, | |
5552 int writing) | |
5553 { | |
5554 char_u *tab; | |
5555 linenr_T lnum; | |
5556 colnr_T col; | |
5557 buf_T *buf; | |
5558 char_u *sfname; | |
5559 char_u *xline; | |
5560 | |
5561 /* Handle long line and escaped characters. */ | |
5562 xline = viminfo_readstring(virp, 1, FALSE); | |
5563 | |
5564 /* don't read in if there are files on the command-line or if writing: */ | |
5565 if (xline != NULL && !writing && ARGCOUNT == 0 | |
5566 && find_viminfo_parameter('%') != NULL) | |
5567 { | |
5568 /* Format is: <fname> Tab <lnum> Tab <col>. | |
5569 * Watch out for a Tab in the file name, work from the end. */ | |
5570 lnum = 0; | |
5571 col = 0; | |
5572 tab = vim_strrchr(xline, '\t'); | |
5573 if (tab != NULL) | |
5574 { | |
5575 *tab++ = '\0'; | |
5576 col = (colnr_T)atoi((char *)tab); | |
5577 tab = vim_strrchr(xline, '\t'); | |
5578 if (tab != NULL) | |
5579 { | |
5580 *tab++ = '\0'; | |
5581 lnum = atol((char *)tab); | |
5582 } | |
5583 } | |
5584 | |
5585 /* Expand "~/" in the file name at "line + 1" to a full path. | |
5586 * Then try shortening it by comparing with the current directory */ | |
5587 expand_env(xline, NameBuff, MAXPATHL); | |
5588 sfname = shorten_fname1(NameBuff); | |
5589 | |
5590 buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED); | |
5591 if (buf != NULL) /* just in case... */ | |
5592 { | |
5593 buf->b_last_cursor.lnum = lnum; | |
5594 buf->b_last_cursor.col = col; | |
5595 buflist_setfpos(buf, curwin, lnum, col, FALSE); | |
5596 } | |
5597 } | |
5598 vim_free(xline); | |
5599 | |
5600 return viminfo_readline(virp); | |
5601 } | |
5602 | |
5603 void | |
5604 write_viminfo_bufferlist(FILE *fp) | |
5605 { | |
5606 buf_T *buf; | |
5607 win_T *win; | |
5608 tabpage_T *tp; | |
5609 char_u *line; | |
5610 int max_buffers; | |
5611 | |
5612 if (find_viminfo_parameter('%') == NULL) | |
5613 return; | |
5614 | |
5615 /* Without a number -1 is returned: do all buffers. */ | |
5616 max_buffers = get_viminfo_parameter('%'); | |
5617 | |
5618 /* Allocate room for the file name, lnum and col. */ | |
5619 #define LINE_BUF_LEN (MAXPATHL + 40) | |
5620 line = alloc(LINE_BUF_LEN); | |
5621 if (line == NULL) | |
5622 return; | |
5623 | |
5624 FOR_ALL_TAB_WINDOWS(tp, win) | |
5625 set_last_cursor(win); | |
5626 | |
5627 fputs(_("\n# Buffer list:\n"), fp); | |
5628 FOR_ALL_BUFFERS(buf) | |
5629 { | |
5630 if (buf->b_fname == NULL | |
5631 || !buf->b_p_bl | |
5632 #ifdef FEAT_QUICKFIX | |
5633 || bt_quickfix(buf) | |
5634 #endif | |
5635 #ifdef FEAT_TERMINAL | |
5636 || bt_terminal(buf) | |
5637 #endif | |
5638 || removable(buf->b_ffname)) | |
5639 continue; | |
5640 | |
5641 if (max_buffers-- == 0) | |
5642 break; | |
5643 putc('%', fp); | |
5644 home_replace(NULL, buf->b_ffname, line, MAXPATHL, TRUE); | |
5645 vim_snprintf_add((char *)line, LINE_BUF_LEN, "\t%ld\t%d", | |
5646 (long)buf->b_last_cursor.lnum, | |
5647 buf->b_last_cursor.col); | |
5648 viminfo_writestring(fp, line); | |
5649 } | |
5650 vim_free(line); | |
5651 } | |
5652 #endif | |
5653 | |
5654 /* | 5548 /* |
5655 * Return TRUE if "buf" is a normal buffer, 'buftype' is empty. | 5549 * Return TRUE if "buf" is a normal buffer, 'buftype' is empty. |
5656 */ | 5550 */ |
5657 int | 5551 int |
5658 bt_normal(buf_T *buf) | 5552 bt_normal(buf_T *buf) |