comparison src/buffer.c @ 13782:3be5e8306a3e v8.0.1763

patch 8.0.1763: :argedit does not reuse an empty unnamed buffer commit https://github.com/vim/vim/commit/46a53dfc29689c6a0d80e3820e8b0a48dba6b6ec Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 24 21:58:51 2018 +0200 patch 8.0.1763: :argedit does not reuse an empty unnamed buffer Problem: :argedit does not reuse an empty unnamed buffer. Solution: Add the BLN_CURBUF flag and fix all the side effects. (Christian Brabandt, closes #2713)
author Christian Brabandt <cb@256bit.org>
date Tue, 24 Apr 2018 22:00:07 +0200
parents 7d2039b2ecc8
children fc03fabbedc5
comparison
equal deleted inserted replaced
13781:37bcbeae1a03 13782:3be5e8306a3e
1840 */ 1840 */
1841 1841
1842 static int top_file_num = 1; /* highest file number */ 1842 static int top_file_num = 1; /* highest file number */
1843 1843
1844 /* 1844 /*
1845 * Return TRUE if the current buffer is empty, unnamed, unmodified and used in
1846 * only one window. That means it can be re-used.
1847 */
1848 int
1849 curbuf_reusable(void)
1850 {
1851 return (curbuf != NULL
1852 && curbuf->b_ffname == NULL
1853 && curbuf->b_nwindows <= 1
1854 && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY())
1855 && !curbufIsChanged());
1856 }
1857
1858 /*
1845 * Add a file name to the buffer list. Return a pointer to the buffer. 1859 * Add a file name to the buffer list. Return a pointer to the buffer.
1846 * If the same file name already exists return a pointer to that buffer. 1860 * If the same file name already exists return a pointer to that buffer.
1847 * If it does not exist, or if fname == NULL, a new entry is created. 1861 * If it does not exist, or if fname == NULL, a new entry is created.
1848 * If (flags & BLN_CURBUF) is TRUE, may use current buffer. 1862 * If (flags & BLN_CURBUF) is TRUE, may use current buffer.
1849 * If (flags & BLN_LISTED) is TRUE, add new buffer to buffer list. 1863 * If (flags & BLN_LISTED) is TRUE, add new buffer to buffer list.
1919 * This is the ONLY place where a new buffer structure is allocated! 1933 * This is the ONLY place where a new buffer structure is allocated!
1920 * (A spell file buffer is allocated in spell.c, but that's not a normal 1934 * (A spell file buffer is allocated in spell.c, but that's not a normal
1921 * buffer.) 1935 * buffer.)
1922 */ 1936 */
1923 buf = NULL; 1937 buf = NULL;
1924 if ((flags & BLN_CURBUF) 1938 if ((flags & BLN_CURBUF) && curbuf_reusable())
1925 && curbuf != NULL
1926 && curbuf->b_ffname == NULL
1927 && curbuf->b_nwindows <= 1
1928 && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY()))
1929 { 1939 {
1930 buf = curbuf; 1940 buf = curbuf;
1931 /* It's like this buffer is deleted. Watch out for autocommands that 1941 /* It's like this buffer is deleted. Watch out for autocommands that
1932 * change curbuf! If that happens, allocate a new buffer anyway. */ 1942 * change curbuf! If that happens, allocate a new buffer anyway. */
1933 if (curbuf->b_p_bl) 1943 if (curbuf->b_p_bl)