aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt14
-rw-r--r--CONTRIBUTING.md5
-rw-r--r--Makefile4
-rw-r--r--cmake/Format.cmake67
-rwxr-xr-xscripts/uncrustify.sh11
-rwxr-xr-xsrc/nvim/CMakeLists.txt9
-rw-r--r--src/nvim/buffer.c2
-rw-r--r--src/nvim/buffer_defs.h19
-rw-r--r--src/nvim/lua/stdlib.c4
-rw-r--r--src/nvim/mbyte.c17
-rw-r--r--src/nvim/ops.c2
-rw-r--r--src/nvim/window.c11
-rw-r--r--test/functional/editor/tabpage_spec.lua41
13 files changed, 163 insertions, 43 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6c54e5749b..caf9658699 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -675,6 +675,19 @@ add_dependencies(lintcommit nvim)
add_custom_target(lint)
add_dependencies(lint check-single-includes lintc lintlua lintpy lintsh lintcommit lintuncrustify)
+#
+# Format
+#
+add_custom_target(formatlua
+ COMMAND ${CMAKE_COMMAND}
+ -D FORMAT_PRG=${STYLUA_PRG}
+ -D LANG=lua
+ -P ${PROJECT_SOURCE_DIR}/cmake/Format.cmake
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
+
+add_custom_target(format)
+add_dependencies(format formatc formatlua)
+
install_helper(
FILES ${CMAKE_SOURCE_DIR}/src/man/nvim.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
@@ -797,4 +810,3 @@ add_custom_target(uninstall
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(cmake.packaging)
endif()
-
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e26d0d63c5..17622fa33a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -218,6 +218,11 @@ You can lint a single file (but this will _not_ exclude legacy errors):
### Style
+- You can format files by using:
+```
+ make format
+```
+This will format changed Lua and C files with all appropriate flags set.
- Style rules are (mostly) defined by `src/uncrustify.cfg` which tries to match
the [style-guide]. To use the Nvim `gq` command with `uncrustify`:
```
diff --git a/Makefile b/Makefile
index e9a59f0941..c071338435 100644
--- a/Makefile
+++ b/Makefile
@@ -137,7 +137,7 @@ helphtml: | nvim build/runtime/doc/tags
functionaltest functionaltest-lua unittest benchmark: | nvim
$(BUILD_TOOL) -C build $@
-lintlua lintsh lintpy lintuncrustify lintc lintcfull check-single-includes generated-sources lintcommit lint: | build/.ran-cmake
+lintlua lintsh lintpy lintuncrustify lintc lintcfull check-single-includes generated-sources lintcommit lint formatc formatlua format: | build/.ran-cmake
$(CMAKE_PRG) --build build --target $@
test: functionaltest unittest
@@ -174,4 +174,4 @@ $(DEPS_BUILD_DIR)/%: phony_force
$(BUILD_TOOL) -C $(DEPS_BUILD_DIR) $(patsubst $(DEPS_BUILD_DIR)/%,%,$@)
endif
-.PHONY: test lintlua lintpy lintsh functionaltest unittest lint lintc clean distclean nvim libnvim cmake deps install appimage checkprefix lintcommit
+.PHONY: test lintlua lintpy lintsh functionaltest unittest lint lintc clean distclean nvim libnvim cmake deps install appimage checkprefix lintcommit formatc formatlua format
diff --git a/cmake/Format.cmake b/cmake/Format.cmake
new file mode 100644
index 0000000000..4115e66705
--- /dev/null
+++ b/cmake/Format.cmake
@@ -0,0 +1,67 @@
+# Returns a list of all files that has been changed in current branch compared
+# to master branch. This includes unstaged, staged and committed files.
+function(get_changed_files outvar)
+ set(default_branch master)
+
+ execute_process(
+ COMMAND git branch --show-current
+ OUTPUT_VARIABLE current_branch
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ execute_process(
+ COMMAND git merge-base ${default_branch} ${current_branch}
+ OUTPUT_VARIABLE ancestor_commit
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ # Changed files that have been committed
+ execute_process(
+ COMMAND git diff --name-only ${ancestor_commit}...${current_branch}
+ OUTPUT_VARIABLE committed_files
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ separate_arguments(committed_files NATIVE_COMMAND ${committed_files})
+
+ # Unstaged files
+ execute_process(
+ COMMAND git diff --name-only
+ OUTPUT_VARIABLE unstaged_files
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ separate_arguments(unstaged_files NATIVE_COMMAND ${unstaged_files})
+
+ # Staged files
+ execute_process(
+ COMMAND git diff --cached --name-only
+ OUTPUT_VARIABLE staged_files
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ separate_arguments(staged_files NATIVE_COMMAND ${staged_files})
+
+ set(files ${committed_files} ${unstaged_files} ${staged_files})
+ list(REMOVE_DUPLICATES files)
+
+ set(${outvar} "${files}" PARENT_SCOPE)
+endfunction()
+
+get_changed_files(changed_files)
+
+if(LANG STREQUAL c)
+ list(FILTER changed_files INCLUDE REGEX "\\.[ch]$")
+ list(FILTER changed_files INCLUDE REGEX "^src/nvim/")
+
+ if(changed_files)
+ if(FORMAT_PRG)
+ execute_process(COMMAND ${FORMAT_PRG} -c "src/uncrustify.cfg" --replace --no-backup ${changed_files})
+ else()
+ message(STATUS "Uncrustify not found. Skip formatting C files.")
+ endif()
+ endif()
+elseif(LANG STREQUAL lua)
+ list(FILTER changed_files INCLUDE REGEX "\\.lua$")
+ list(FILTER changed_files INCLUDE REGEX "^runtime/")
+
+ if(changed_files)
+ if(FORMAT_PRG)
+ execute_process(COMMAND ${FORMAT_PRG} ${changed_files})
+ else()
+ message(STATUS "Stylua not found. Skip formatting lua files.")
+ endif()
+ endif()
+endif()
diff --git a/scripts/uncrustify.sh b/scripts/uncrustify.sh
deleted file mode 100755
index ac5d542c29..0000000000
--- a/scripts/uncrustify.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-# Check that you have uncrustify
-hash uncrustify
-
-COMMITISH="${1:-master}"
-for file in $(git diff --diff-filter=d --name-only $COMMITISH | grep '\.[ch]$'); do
- uncrustify -c src/uncrustify.cfg -l C --replace --no-backup "$file"
-done
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index f302f25ad6..017883a913 100755
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -778,9 +778,16 @@ add_glob_targets(
FLAGS -c "${PROJECT_SOURCE_DIR}/src/uncrustify.cfg" -q --check
FILES ${LINT_NVIM_SOURCES}
)
-
add_dependencies(lintuncrustify uncrustify-version)
+add_custom_target(formatc
+ COMMAND ${CMAKE_COMMAND}
+ -D FORMAT_PRG=${UNCRUSTIFY_PRG}
+ -D LANG=c
+ -P ${PROJECT_SOURCE_DIR}/cmake/Format.cmake
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
+add_dependencies(formatc uncrustify-version)
+
add_custom_target(
lintcfull
COMMAND
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 328a72476a..6dd71e92a6 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -3288,7 +3288,7 @@ void maketitle(void)
len = (int)STRLEN(buf_p);
if (len > 100) {
len -= 100;
- len += mb_tail_off(buf_p, buf_p + len) + 1;
+ len += utf_cp_tail_off(buf_p, buf_p + len) + 1;
buf_p += len;
}
STRCPY(icon_str, buf_p);
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index aeba3acbc3..3ef5ea7e02 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -947,16 +947,15 @@ struct diffblock_S {
typedef struct tabpage_S tabpage_T;
struct tabpage_S {
handle_T handle;
- tabpage_T *tp_next; ///< next tabpage or NULL
- frame_T *tp_topframe; ///< topframe for the windows
- win_T *tp_curwin; ///< current window in this Tab page
- win_T *tp_prevwin; ///< previous window in this Tab page
- win_T *tp_firstwin; ///< first window in this Tab page
- win_T *tp_lastwin; ///< last window in this Tab page
- long tp_old_Rows; ///< Rows when Tab page was left
- long tp_old_Columns; ///< Columns when Tab page was left
- long tp_ch_used; ///< value of 'cmdheight' when frame size
- ///< was set
+ tabpage_T *tp_next; ///< next tabpage or NULL
+ frame_T *tp_topframe; ///< topframe for the windows
+ win_T *tp_curwin; ///< current window in this Tab page
+ win_T *tp_prevwin; ///< previous window in this Tab page
+ win_T *tp_firstwin; ///< first window in this Tab page
+ win_T *tp_lastwin; ///< last window in this Tab page
+ long tp_old_Rows_avail; ///< ROWS_AVAIL when Tab page was left
+ long tp_old_Columns; ///< Columns when Tab page was left
+ long tp_ch_used; ///< value of 'cmdheight' when frame size was set
diff_T *tp_first_diff;
buf_T *(tp_diffbuf[DB_COUNT]);
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index 8fde85b163..6ba0056f48 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -232,7 +232,7 @@ static int nlua_str_utf_start(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
if (offset < 0 || offset > (intptr_t)s1_len) {
return luaL_error(lstate, "index out of range");
}
- int head_offset = mb_head_off((char_u *)s1, (char_u *)s1 + offset - 1);
+ int head_offset = utf_cp_head_off((char_u *)s1, (char_u *)s1 + offset - 1);
lua_pushinteger(lstate, head_offset);
return 1;
}
@@ -252,7 +252,7 @@ static int nlua_str_utf_end(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
if (offset < 0 || offset > (intptr_t)s1_len) {
return luaL_error(lstate, "index out of range");
}
- int tail_offset = mb_tail_off(s1, s1 + offset - 1);
+ int tail_offset = utf_cp_tail_off(s1, s1 + offset - 1);
lua_pushinteger(lstate, tail_offset);
return 1;
}
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index cf4ac27d1a..223b4d6845 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1837,10 +1837,10 @@ int mb_off_next(const char_u *base, const char_u *p)
return i;
}
-/// Return the offset from "p" to the last byte of the character it points
-/// into. Can start anywhere in a stream of bytes.
-/// Composing characters are not included.
-int mb_tail_off(const char *base, const char *p_in)
+/// Return the offset from `p_in` to the last byte of the codepoint it points
+/// to. Can start anywhere in a stream of bytes.
+/// Note: Counts individual codepoints of composed characters separately.
+int utf_cp_tail_off(const char *base, const char *p_in)
{
const uint8_t *p = (uint8_t *)p_in;
int i;
@@ -1866,15 +1866,16 @@ int mb_tail_off(const char *base, const char *p_in)
return i;
}
-/// Return the offset from "p" to the first byte of the character it points
-/// into. Can start anywhere in a stream of bytes.
-/// Unlike utf_head_off() this doesn't include composing characters and returns a negative value.
+/// Return the offset from "p" to the first byte of the codepoint it points
+/// to. Can start anywhere in a stream of bytes.
+/// Note: Unlike `utf_head_off`, this counts individual codepoints of composed characters
+/// separately and returns a negative offset.
///
/// @param[in] base Pointer to start of string
/// @param[in] p Pointer to byte for which to return the offset to the previous codepoint
//
/// @return 0 if invalid sequence, else offset to previous codepoint
-int mb_head_off(const char_u *base, const char_u *p)
+int utf_cp_head_off(const char_u *base, const char_u *p)
{
int i;
int j;
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 0bcc5ecd0e..660902b10b 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -1828,7 +1828,7 @@ static void mb_adjust_opend(oparg_T *oap)
{
if (oap->inclusive) {
char *p = (char *)ml_get(oap->end.lnum);
- oap->end.col += mb_tail_off(p, p + oap->end.col);
+ oap->end.col += utf_cp_tail_off(p, p + oap->end.col);
}
}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index e820be626c..c7f038850e 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -4293,7 +4293,7 @@ static int leave_tabpage(buf_T *new_curbuf, bool trigger_leave_autocmds)
tp->tp_prevwin = prevwin;
tp->tp_firstwin = firstwin;
tp->tp_lastwin = lastwin;
- tp->tp_old_Rows = Rows;
+ tp->tp_old_Rows_avail = ROWS_AVAIL;
tp->tp_old_Columns = Columns;
firstwin = NULL;
lastwin = NULL;
@@ -4333,10 +4333,7 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_a
const int row = win_comp_pos(); // recompute w_winrow for all windows
diff_need_scrollbind = true;
- // The tabpage line may have appeared or disappeared, may need to resize
- // the frames for that. When the Vim window was resized need to update
- // frame sizes too. Use the stored value of p_ch, so that it can be
- // different for each tab page.
+ // Use the stored value of p_ch, so that it can be different for each tab page.
if (p_ch != curtab->tp_ch_used) {
clear_cmdline = true;
}
@@ -4349,7 +4346,9 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_a
clear_cmdline = true;
}
- if (curtab->tp_old_Rows != Rows || (old_off != firstwin->w_winrow)) {
+ // The tabpage line may have appeared or disappeared, may need to resize the frames for that.
+ // When the Vim window was resized or ROWS_AVAIL changed need to update frame sizes too.
+ if (curtab->tp_old_Rows_avail != ROWS_AVAIL || (old_off != firstwin->w_winrow)) {
win_new_screen_rows();
}
if (curtab->tp_old_Columns != Columns && starting == 0) {
diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua
index 3b2c1db350..7dd0b9f154 100644
--- a/test/functional/editor/tabpage_spec.lua
+++ b/test/functional/editor/tabpage_spec.lua
@@ -1,4 +1,5 @@
local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local command = helpers.command
@@ -53,6 +54,46 @@ describe('tabpage', function()
neq(999, eval('g:win_closed'))
end)
+ it('switching tabpage after setting laststatus=3 #19591', function()
+ local screen = Screen.new(40, 8)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue},
+ [1] = {bold = true, reverse = true}, -- StatusLine
+ [2] = {reverse = true}, -- StatusLineNC, TabLineFill
+ [3] = {bold = true}, -- TabLineSel
+ [4] = {background = Screen.colors.LightGrey, underline = true}, -- TabLine
+ [5] = {bold = true, foreground = Screen.colors.Magenta},
+ })
+ screen:attach()
+
+ command('tabnew')
+ command('tabprev')
+ command('set laststatus=3')
+ command('tabnext')
+ feed('<C-G>')
+ screen:expect([[
+ {4: [No Name] }{3: [No Name] }{2: }{4:X}|
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {1:[No Name] }|
+ "[No Name]" --No lines in buffer-- |
+ ]])
+ command('vnew')
+ screen:expect([[
+ {4: [No Name] }{3: }{5:2}{3: [No Name] }{2: }{4:X}|
+ ^ │ |
+ {0:~ }│{0:~ }|
+ {0:~ }│{0:~ }|
+ {0:~ }│{0:~ }|
+ {0:~ }│{0:~ }|
+ {1:[No Name] }|
+ "[No Name]" --No lines in buffer-- |
+ ]])
+ end)
+
it(":tabmove handles modifiers and addr", function()
command('tabnew | tabnew | tabnew')
eq(4, funcs.nvim_tabpage_get_number(0))