comparison src/ex_docmd.c @ 12289:294f510f6d35 v8.0.1024

patch 8.0.1024: folds lost when session file has a buffer in two windows commit https://github.com/vim/vim/commit/4bebc9a0565670b853d227f81a9a31eafdb47eed Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 30 21:07:38 2017 +0200 patch 8.0.1024: folds lost when session file has a buffer in two windows Problem: Manual folds are lost when a session file has the same buffer in two windows. (Jeansen) Solution: Use ":edit" only once. (Christian Brabandt, closes #1958)
author Christian Brabandt <cb@256bit.org>
date Wed, 30 Aug 2017 21:15:04 +0200
parents 59c1e09cf1a9
children d216d9e8ac57
comparison
equal deleted inserted replaced
12288:26922aa4be57 12289:294f510f6d35
11097 static frame_T *ses_skipframe(frame_T *fr); 11097 static frame_T *ses_skipframe(frame_T *fr);
11098 static int ses_do_frame(frame_T *fr); 11098 static int ses_do_frame(frame_T *fr);
11099 static int ses_do_win(win_T *wp); 11099 static int ses_do_win(win_T *wp);
11100 static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp); 11100 static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp);
11101 static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp); 11101 static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp);
11102 static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp); 11102 static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, int add_eol);
11103 11103
11104 /* 11104 /*
11105 * Write openfile commands for the current buffers to an .exrc file. 11105 * Write openfile commands for the current buffers to an .exrc file.
11106 * Return FAIL on error, OK otherwise. 11106 * Return FAIL on error, OK otherwise.
11107 */ 11107 */
11193 && buf->b_fname != NULL 11193 && buf->b_fname != NULL
11194 && buf->b_p_bl) 11194 && buf->b_p_bl)
11195 { 11195 {
11196 if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L 11196 if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L
11197 : buf->b_wininfo->wi_fpos.lnum) < 0 11197 : buf->b_wininfo->wi_fpos.lnum) < 0
11198 || ses_fname(fd, buf, &ssop_flags) == FAIL) 11198 || ses_fname(fd, buf, &ssop_flags, TRUE) == FAIL)
11199 return FAIL; 11199 return FAIL;
11200 } 11200 }
11201 } 11201 }
11202 11202
11203 /* the global argument list */ 11203 /* the global argument list */
11287 && !bt_nofile(wp->w_buffer) 11287 && !bt_nofile(wp->w_buffer)
11288 #endif 11288 #endif
11289 ) 11289 )
11290 { 11290 {
11291 if (fputs(need_tabnew ? "tabedit " : "edit ", fd) < 0 11291 if (fputs(need_tabnew ? "tabedit " : "edit ", fd) < 0
11292 || ses_fname(fd, wp->w_buffer, &ssop_flags) == FAIL) 11292 || ses_fname(fd, wp->w_buffer, &ssop_flags, TRUE)
11293 == FAIL)
11293 return FAIL; 11294 return FAIL;
11294 need_tabnew = FALSE; 11295 need_tabnew = FALSE;
11295 if (!wp->w_arg_idx_invalid) 11296 if (!wp->w_arg_idx_invalid)
11296 edited_win = wp; 11297 edited_win = wp;
11297 break; 11298 break;
11634 ) 11635 )
11635 { 11636 {
11636 /* 11637 /*
11637 * Editing a file in this buffer: use ":edit file". 11638 * Editing a file in this buffer: use ":edit file".
11638 * This may have side effects! (e.g., compressed or network file). 11639 * This may have side effects! (e.g., compressed or network file).
11640 *
11641 * Note, if a buffer for that file already exists, use :badd to
11642 * edit that buffer, to not lose folding information (:edit resets
11643 * folds in other buffers)
11639 */ 11644 */
11640 if (fputs("edit ", fd) < 0 11645 if (fputs("if bufexists('", fd) < 0
11641 || ses_fname(fd, wp->w_buffer, flagp) == FAIL) 11646 || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
11647 || fputs("') | buffer ", fd) < 0
11648 || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
11649 || fputs(" | else | edit ", fd) < 0
11650 || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
11651 || fputs(" | endif", fd) < 0
11652 ||
11653 put_eol(fd) == FAIL)
11642 return FAIL; 11654 return FAIL;
11643 } 11655 }
11644 else 11656 else
11645 { 11657 {
11646 /* No file in this buffer, just make it empty. */ 11658 /* No file in this buffer, just make it empty. */
11649 #ifdef FEAT_QUICKFIX 11661 #ifdef FEAT_QUICKFIX
11650 if (wp->w_buffer->b_ffname != NULL) 11662 if (wp->w_buffer->b_ffname != NULL)
11651 { 11663 {
11652 /* The buffer does have a name, but it's not a file name. */ 11664 /* The buffer does have a name, but it's not a file name. */
11653 if (fputs("file ", fd) < 0 11665 if (fputs("file ", fd) < 0
11654 || ses_fname(fd, wp->w_buffer, flagp) == FAIL) 11666 || ses_fname(fd, wp->w_buffer, flagp, TRUE) == FAIL)
11655 return FAIL; 11667 return FAIL;
11656 } 11668 }
11657 #endif 11669 #endif
11658 do_cursor = FALSE; 11670 do_cursor = FALSE;
11659 } 11671 }
11821 return OK; 11833 return OK;
11822 } 11834 }
11823 11835
11824 /* 11836 /*
11825 * Write a buffer name to the session file. 11837 * Write a buffer name to the session file.
11826 * Also ends the line. 11838 * Also ends the line, if "add_eol" is TRUE.
11827 * Returns FAIL if writing fails. 11839 * Returns FAIL if writing fails.
11828 */ 11840 */
11829 static int 11841 static int
11830 ses_fname(FILE *fd, buf_T *buf, unsigned *flagp) 11842 ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, int add_eol)
11831 { 11843 {
11832 char_u *name; 11844 char_u *name;
11833 11845
11834 /* Use the short file name if the current directory is known at the time 11846 /* Use the short file name if the current directory is known at the time
11835 * the session file will be sourced. 11847 * the session file will be sourced.
11844 #endif 11856 #endif
11845 && !did_lcd) 11857 && !did_lcd)
11846 name = buf->b_sfname; 11858 name = buf->b_sfname;
11847 else 11859 else
11848 name = buf->b_ffname; 11860 name = buf->b_ffname;
11849 if (ses_put_fname(fd, name, flagp) == FAIL || put_eol(fd) == FAIL) 11861 if (ses_put_fname(fd, name, flagp) == FAIL
11862 || (add_eol && put_eol(fd) == FAIL))
11850 return FAIL; 11863 return FAIL;
11851 return OK; 11864 return OK;
11852 } 11865 }
11853 11866
11854 /* 11867 /*