diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-10-16 08:06:07 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-10-16 08:34:55 +0800 |
commit | 19eb7054ff7b1fbc78e56e7f9ed6537b085147bc (patch) | |
tree | f10b35a7a415ebd3cbfc3b944aec96e65892becc /src/nvim/indent.c | |
parent | bc798dfd8cea9a5f93461e05dcb8409b6d96afc0 (diff) | |
download | rneovim-19eb7054ff7b1fbc78e56e7f9ed6537b085147bc.tar.gz rneovim-19eb7054ff7b1fbc78e56e7f9ed6537b085147bc.tar.bz2 rneovim-19eb7054ff7b1fbc78e56e7f9ed6537b085147bc.zip |
vim-patch:9.0.0761: cannot use 'indentexpr' for Lisp indenting
Problem: Cannot use 'indentexpr' for Lisp indenting.
Solution: Add the 'lispoptions' option.
https://github.com/vim/vim/commit/49846fb1a31de99f49d6a7e70efe685197423c84
vim-patch:9.0.0762: build failure
Problem: Build failure.
Solution: Add missing change.
https://github.com/vim/vim/commit/4b082c4bd05f504fda1acaa9d28fca55a2d04857
Diffstat (limited to 'src/nvim/indent.c')
-rw-r--r-- | src/nvim/indent.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 3f5a8afbc1..3f08aa7043 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -15,6 +15,7 @@ #include "nvim/eval.h" #include "nvim/extmark.h" #include "nvim/indent.h" +#include "nvim/indent_c.h" #include "nvim/mark.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -1144,3 +1145,45 @@ static int lisp_match(char_u *p) } return false; } + +/// Re-indent the current line, based on the current contents of it and the +/// surrounding lines. Fixing the cursor position seems really easy -- I'm very +/// confused what all the part that handles Control-T is doing that I'm not. +/// "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent. +void fixthisline(IndentGetter get_the_indent) +{ + int amount = get_the_indent(); + + if (amount >= 0) { + change_indent(INDENT_SET, amount, false, 0, true); + if (linewhite(curwin->w_cursor.lnum)) { + did_ai = true; // delete the indent if the line stays empty + } + } +} + +/// Return true if 'indentexpr' should be used for Lisp indenting. +/// Caller may want to check 'autoindent'. +bool use_indentexpr_for_lisp(void) +{ + return curbuf->b_p_lisp + && *curbuf->b_p_inde != NUL + && strcmp(curbuf->b_p_lop, "expr:1") == 0; +} + +/// Fix indent for 'lisp' and 'cindent'. +void fix_indent(void) +{ + if (p_paste) { + return; // no auto-indenting when 'paste' is set + } + if (curbuf->b_p_lisp && curbuf->b_p_ai) { + if (use_indentexpr_for_lisp()) { + do_c_expr_indent(); + } else { + fixthisline(get_lisp_indent); + } + } else if (cindent_on()) { + do_c_expr_indent(); + } +} |