Mercurial > vim
annotate src/change.c @ 30910:6686e742a859 v9.0.0789
patch 9.0.0789: dummy buffer ends up in a window
Commit: https://github.com/vim/vim/commit/8f3c3c6cd044e3b5bf08dbfa3b3f04bb3f711bad
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Oct 18 17:05:54 2022 +0100
patch 9.0.0789: dummy buffer ends up in a window
Problem: Dummy buffer ends up in a window.
Solution: Disallow navigating to a dummy buffer.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 18 Oct 2022 18:15:03 +0200 |
parents | 74e64f3a54ef |
children | 35265d9d24df |
rev | line source |
---|---|
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * change.c: functions related to changing text |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 * If the file is readonly, give a warning message with the first change. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 * Don't do this for autocommands. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 * Doesn't use emsg(), because it flushes the macro buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 * If we have undone all changes b_changed will be FALSE, but "b_did_warn" |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 * will be TRUE. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 * "col" is the column for the message; non-zero when in insert mode and |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 * 'showmode' is on. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 * Careful: may trigger autocommands that reload the buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 change_warning(int col) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 static char *w_readonly = N_("W10: Warning: Changing a readonly file"); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
31 if (curbuf->b_did_warn |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
32 || curbufIsChanged() |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
33 || autocmd_busy |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
34 || !curbuf->b_p_ro) |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
35 return; |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
37 ++curbuf_lock; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
38 apply_autocmds(EVENT_FILECHANGEDRO, NULL, NULL, FALSE, curbuf); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
39 --curbuf_lock; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
40 if (!curbuf->b_p_ro) |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
41 return; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
42 |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
43 // Do what msg() does, but with a column offset if the warning should |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
44 // be after the mode message. |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
45 msg_start(); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
46 if (msg_row == Rows - 1) |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
47 msg_col = col; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
48 msg_source(HL_ATTR(HLF_W)); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
49 msg_puts_attr(_(w_readonly), HL_ATTR(HLF_W) | MSG_HIST); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 #ifdef FEAT_EVAL |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
51 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_readonly), -1); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 #endif |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
53 msg_clr_eos(); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
54 (void)msg_end(); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
55 if (msg_silent == 0 && !silent_mode |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 #ifdef FEAT_EVAL |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
57 && time_for_testing != 1 |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 #endif |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
59 ) |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
60 { |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
61 out_flush(); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
62 ui_delay(1002L, TRUE); // give the user time to think about it |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 } |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
64 curbuf->b_did_warn = TRUE; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
65 redraw_cmdline = FALSE; // don't redraw and erase the message |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
66 if (msg_row < Rows - 1) |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
67 showmode(); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 * Call this function when something in the current buffer is changed. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 * Most often called through changed_bytes() and changed_lines(), which also |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 * mark the area of the display to be redrawn. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 * Careful: may trigger autocommands that reload the buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 changed(void) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 if (p_imst == IM_ON_THE_SPOT) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 // The text of the preediting area is inserted, but this doesn't |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 // mean a change of the buffer yet. That is delayed until the |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 // text is committed. (this means preedit becomes empty) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 if (im_is_preediting() && !xim_changed_while_preediting) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 return; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 xim_changed_while_preediting = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 if (!curbuf->b_changed) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 int save_msg_scroll = msg_scroll; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 // Give a warning about changing a read-only file. This may also |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 // check-out the file, thus change "curbuf"! |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 change_warning(0); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 // Create a swap file if that is wanted. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 // Don't do this for "nofile" and "nowrite" buffer types. |
29849
6c7eddcce52c
patch 9.0.0263: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
103 if (curbuf->b_may_swap && !bt_dontwrite(curbuf)) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 int save_need_wait_return = need_wait_return; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 need_wait_return = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 ml_open_file(curbuf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 // The ml_open_file() can cause an ATTENTION message. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 // Wait two seconds, to make sure the user reads this unexpected |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 // message. Since we could be anywhere, call wait_return() now, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 // and don't let the emsg() set msg_scroll. |
22742
f7f2d73ff85e
patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
114 if (need_wait_return && emsg_silent == 0 && !in_assert_fails) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 out_flush(); |
18642
bbea1f108187
patch 8.1.2313: debugging where a delay comes from is not easy
Bram Moolenaar <Bram@vim.org>
parents:
18440
diff
changeset
|
117 ui_delay(2002L, TRUE); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 wait_return(TRUE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 msg_scroll = save_msg_scroll; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 need_wait_return = save_need_wait_return; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 changed_internal(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 ++CHANGEDTICK(curbuf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 #ifdef FEAT_SEARCH_EXTRA |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 // If a pattern is highlighted, the position may now be invalid. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 highlight_match = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 * Internal part of changed(), no user interaction. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 * Also used for recovery. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 changed_internal(void) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 curbuf->b_changed = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 ml_setflags(curbuf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 check_status(curbuf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 redraw_tabline = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 need_maketitle = TRUE; // set window title later |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
148 #ifdef FEAT_EVAL |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
149 static long next_listener_id = 0; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
150 |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
151 /* |
17423
ae11ab022b02
patch 8.1.1710: Coverity found dead code
Bram Moolenaar <Bram@vim.org>
parents:
17352
diff
changeset
|
152 * Check if the change at "lnum" is above or overlaps with an existing |
ae11ab022b02
patch 8.1.1710: Coverity found dead code
Bram Moolenaar <Bram@vim.org>
parents:
17352
diff
changeset
|
153 * change. If above then flush changes and invoke listeners. |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
154 */ |
27706
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
27521
diff
changeset
|
155 static void |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
156 check_recorded_changes( |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
157 buf_T *buf, |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
158 linenr_T lnum, |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
159 linenr_T lnume, |
17423
ae11ab022b02
patch 8.1.1710: Coverity found dead code
Bram Moolenaar <Bram@vim.org>
parents:
17352
diff
changeset
|
160 long xtra) |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
161 { |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
162 if (buf->b_recorded_changes == NULL || xtra == 0) |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
163 return; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
164 |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
165 listitem_T *li; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
166 linenr_T prev_lnum; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
167 linenr_T prev_lnume; |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
168 |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
169 FOR_ALL_LIST_ITEMS(buf->b_recorded_changes, li) |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
170 { |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
171 prev_lnum = (linenr_T)dict_get_number( |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
172 li->li_tv.vval.v_dict, "lnum"); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
173 prev_lnume = (linenr_T)dict_get_number( |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
174 li->li_tv.vval.v_dict, "end"); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
175 if (prev_lnum >= lnum || prev_lnum > lnume || prev_lnume >= lnum) |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
176 { |
30886
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
177 // the current change is going to make the line number in |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
178 // the older change invalid, flush now |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
179 invoke_listeners(curbuf); |
74e64f3a54ef
patch 9.0.0777: code is indented too much
Bram Moolenaar <Bram@vim.org>
parents:
30853
diff
changeset
|
180 break; |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
181 } |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
182 } |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
183 } |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
184 |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
185 /* |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
186 * Record a change for listeners added with listener_add(). |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
187 * Always for the current buffer. |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
188 */ |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
189 static void |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
190 may_record_change( |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
191 linenr_T lnum, |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
192 colnr_T col, |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
193 linenr_T lnume, |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
194 long xtra) |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
195 { |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
196 dict_T *dict; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
197 |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
198 if (curbuf->b_listener == NULL) |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
199 return; |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
200 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
201 // If the new change is going to change the line numbers in already listed |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
202 // changes, then flush. |
27706
17cd22b7151b
patch 8.2.4379: an empty change is reported to a listener
Bram Moolenaar <Bram@vim.org>
parents:
27521
diff
changeset
|
203 check_recorded_changes(curbuf, lnum, lnume, xtra); |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
204 |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
205 if (curbuf->b_recorded_changes == NULL) |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
206 { |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
207 curbuf->b_recorded_changes = list_alloc(); |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
208 if (curbuf->b_recorded_changes == NULL) // out of memory |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
209 return; |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
210 ++curbuf->b_recorded_changes->lv_refcount; |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
211 curbuf->b_recorded_changes->lv_lock = VAR_FIXED; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
212 } |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
213 |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
214 dict = dict_alloc(); |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
215 if (dict == NULL) |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
216 return; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
217 dict_add_number(dict, "lnum", (varnumber_T)lnum); |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
218 dict_add_number(dict, "end", (varnumber_T)lnume); |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
219 dict_add_number(dict, "added", (varnumber_T)xtra); |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
220 dict_add_number(dict, "col", (varnumber_T)col + 1); |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
221 |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
222 list_append_dict(curbuf->b_recorded_changes, dict); |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
223 } |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
224 |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
225 /* |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
226 * listener_add() function |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
227 */ |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
228 void |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
229 f_listener_add(typval_T *argvars, typval_T *rettv) |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
230 { |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16835
diff
changeset
|
231 callback_T callback; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
232 listener_T *lnr; |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
233 buf_T *buf = curbuf; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
234 |
25356
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25246
diff
changeset
|
235 if (in_vim9script() && check_for_opt_buffer_arg(argvars, 1) == FAIL) |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25246
diff
changeset
|
236 return; |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25246
diff
changeset
|
237 |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16835
diff
changeset
|
238 callback = get_callback(&argvars[0]); |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16835
diff
changeset
|
239 if (callback.cb_name == NULL) |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
240 return; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
241 |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
242 if (argvars[1].v_type != VAR_UNKNOWN) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
243 { |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
244 buf = get_buf_arg(&argvars[1]); |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
245 if (buf == NULL) |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16835
diff
changeset
|
246 { |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16835
diff
changeset
|
247 free_callback(&callback); |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
248 return; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16835
diff
changeset
|
249 } |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
250 } |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
251 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16774
diff
changeset
|
252 lnr = ALLOC_CLEAR_ONE(listener_T); |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
253 if (lnr == NULL) |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
254 { |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16835
diff
changeset
|
255 free_callback(&callback); |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
256 return; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
257 } |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
258 lnr->lr_next = buf->b_listener; |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
259 buf->b_listener = lnr; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
260 |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16835
diff
changeset
|
261 set_callback(&lnr->lr_callback, &callback); |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
262 |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
263 lnr->lr_id = ++next_listener_id; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
264 rettv->vval.v_number = lnr->lr_id; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
265 } |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
266 |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
267 /* |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
268 * listener_flush() function |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
269 */ |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
270 void |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
271 f_listener_flush(typval_T *argvars, typval_T *rettv UNUSED) |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
272 { |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
273 buf_T *buf = curbuf; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
274 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25380
diff
changeset
|
275 if (in_vim9script() && check_for_opt_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25380
diff
changeset
|
276 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25380
diff
changeset
|
277 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
278 if (argvars[0].v_type != VAR_UNKNOWN) |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
279 { |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
280 buf = get_buf_arg(&argvars[0]); |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
281 if (buf == NULL) |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
282 return; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
283 } |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
284 invoke_listeners(buf); |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
285 } |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
286 |
25782
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
287 |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
288 static void |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
289 remove_listener(buf_T *buf, listener_T *lnr, listener_T *prev) |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
290 { |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
291 if (prev != NULL) |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
292 prev->lr_next = lnr->lr_next; |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
293 else |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
294 buf->b_listener = lnr->lr_next; |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
295 free_callback(&lnr->lr_callback); |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
296 vim_free(lnr); |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
297 } |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
298 |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
299 /* |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
300 * listener_remove() function |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
301 */ |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
302 void |
17352
b2616a8be8a6
patch 8.1.1675: listener list not correctly updated on listener_remove()
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
303 f_listener_remove(typval_T *argvars, typval_T *rettv) |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
304 { |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
305 listener_T *lnr; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
306 listener_T *next; |
17352
b2616a8be8a6
patch 8.1.1675: listener list not correctly updated on listener_remove()
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
307 listener_T *prev; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25380
diff
changeset
|
308 int id; |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
309 buf_T *buf; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
310 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25380
diff
changeset
|
311 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25380
diff
changeset
|
312 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25380
diff
changeset
|
313 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25380
diff
changeset
|
314 id = tv_get_number(argvars); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
315 FOR_ALL_BUFFERS(buf) |
17352
b2616a8be8a6
patch 8.1.1675: listener list not correctly updated on listener_remove()
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
316 { |
b2616a8be8a6
patch 8.1.1675: listener list not correctly updated on listener_remove()
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
317 prev = NULL; |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
318 for (lnr = buf->b_listener; lnr != NULL; lnr = next) |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
319 { |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
320 next = lnr->lr_next; |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
321 if (lnr->lr_id == id) |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
322 { |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
28972
diff
changeset
|
323 if (textlock > 0) |
25782
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
324 { |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
325 // in invoke_listeners(), clear ID and delete later |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
326 lnr->lr_id = 0; |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
327 return; |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
328 } |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
329 remove_listener(buf, lnr, prev); |
17352
b2616a8be8a6
patch 8.1.1675: listener list not correctly updated on listener_remove()
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
330 rettv->vval.v_number = 1; |
b2616a8be8a6
patch 8.1.1675: listener list not correctly updated on listener_remove()
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
331 return; |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
332 } |
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16636
diff
changeset
|
333 prev = lnr; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
334 } |
17352
b2616a8be8a6
patch 8.1.1675: listener list not correctly updated on listener_remove()
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
335 } |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
336 } |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
337 |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
338 /* |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
339 * Called before inserting a line above "lnum"/"lnum3" or deleting line "lnum" |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
340 * to "lnume". |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
341 */ |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
342 void |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
343 may_invoke_listeners(buf_T *buf, linenr_T lnum, linenr_T lnume, int added) |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
344 { |
17423
ae11ab022b02
patch 8.1.1710: Coverity found dead code
Bram Moolenaar <Bram@vim.org>
parents:
17352
diff
changeset
|
345 check_recorded_changes(buf, lnum, lnume, added); |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
346 } |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
347 |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
348 /* |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
349 * Called when a sequence of changes is done: invoke listeners added with |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
350 * listener_add(). |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
351 */ |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
352 void |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
353 invoke_listeners(buf_T *buf) |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
354 { |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
355 listener_T *lnr; |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
356 typval_T rettv; |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
357 typval_T argv[6]; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
358 listitem_T *li; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
359 linenr_T start = MAXLNUM; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
360 linenr_T end = 0; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
361 linenr_T added = 0; |
16835
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
362 int save_updating_screen = updating_screen; |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
363 static int recursive = FALSE; |
25782
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
364 listener_T *next; |
30047
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
29849
diff
changeset
|
365 listener_T *prev; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
366 |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
367 if (buf->b_recorded_changes == NULL // nothing changed |
16835
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
368 || buf->b_listener == NULL // no listeners |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
369 || recursive) // already busy |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
370 return; |
16835
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
371 recursive = TRUE; |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
372 |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
373 // Block messages on channels from being handled, so that they don't make |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
374 // text changes here. |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
375 ++updating_screen; |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
376 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
377 argv[0].v_type = VAR_NUMBER; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
378 argv[0].vval.v_number = buf->b_fnum; // a:bufnr |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
379 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19534
diff
changeset
|
380 FOR_ALL_LIST_ITEMS(buf->b_recorded_changes, li) |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
381 { |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
382 varnumber_T lnum; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
383 |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
384 lnum = dict_get_number(li->li_tv.vval.v_dict, "lnum"); |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
385 if (start > lnum) |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
386 start = lnum; |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
387 lnum = dict_get_number(li->li_tv.vval.v_dict, "end"); |
18434
5da355d15b88
patch 8.1.2211: listener callback "added" argument is not the total
Bram Moolenaar <Bram@vim.org>
parents:
18265
diff
changeset
|
388 if (end < lnum) |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
389 end = lnum; |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29340
diff
changeset
|
390 added += dict_get_number(li->li_tv.vval.v_dict, "added"); |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
391 } |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
392 argv[1].v_type = VAR_NUMBER; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
393 argv[1].vval.v_number = start; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
394 argv[2].v_type = VAR_NUMBER; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
395 argv[2].vval.v_number = end; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
396 argv[3].v_type = VAR_NUMBER; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
397 argv[3].vval.v_number = added; |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
398 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
399 argv[4].v_type = VAR_LIST; |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
400 argv[4].vval.v_list = buf->b_recorded_changes; |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
28972
diff
changeset
|
401 ++textlock; |
16660
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
402 |
04c2614af21c
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Bram Moolenaar <Bram@vim.org>
parents:
16638
diff
changeset
|
403 for (lnr = buf->b_listener; lnr != NULL; lnr = lnr->lr_next) |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
404 { |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17423
diff
changeset
|
405 call_callback(&lnr->lr_callback, -1, &rettv, 5, argv); |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
406 clear_tv(&rettv); |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
407 } |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
408 |
25782
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
409 // If f_listener_remove() was called may have to remove a listener now. |
30047
711ae604980a
patch 9.0.0361: removing a listener may result in a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
29849
diff
changeset
|
410 prev = NULL; |
25782
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
411 for (lnr = buf->b_listener; lnr != NULL; lnr = next) |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
412 { |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
413 next = lnr->lr_next; |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
414 if (lnr->lr_id == 0) |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
415 remove_listener(buf, lnr, prev); |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
416 else |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
417 prev = lnr; |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
418 } |
5ef74c37a9a1
patch 8.2.3426: crash when deleting a listener in a listener callback
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
419 |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
28972
diff
changeset
|
420 --textlock; |
16666
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
421 list_unref(buf->b_recorded_changes); |
978bcd70883d
patch 8.1.1335: listener callback is called after inserting text
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
422 buf->b_recorded_changes = NULL; |
16835
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
423 |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
424 if (save_updating_screen) |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
425 updating_screen = TRUE; |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
426 else |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
427 after_updating_screen(TRUE); |
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
428 recursive = FALSE; |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
429 } |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
430 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
431 /* |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
432 * Remove all listeners associated with "buf". |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
433 */ |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
434 void |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
435 remove_listeners(buf_T *buf) |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
436 { |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
437 listener_T *lnr; |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
438 listener_T *next; |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
439 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
440 for (lnr = buf->b_listener; lnr != NULL; lnr = next) |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
441 { |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
442 next = lnr->lr_next; |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
443 free_callback(&lnr->lr_callback); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
444 vim_free(lnr); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
445 } |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
446 buf->b_listener = NULL; |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
447 } |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
448 #endif |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
449 |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 * Common code for when a change was made. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 * See changed_lines() for the arguments. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 * Careful: may trigger autocommands that reload the buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 static void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 changed_common( |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 linenr_T lnum, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 colnr_T col, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 linenr_T lnume, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 long xtra) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 win_T *wp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 tabpage_T *tp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 int i; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 int cols; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 pos_T *p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 int add; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 // mark the buffer as modified |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 changed(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 |
16636
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
472 #ifdef FEAT_EVAL |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
473 may_record_change(lnum, col, lnume, xtra); |
0daf9eca3541
patch 8.1.1320: it is not possible to track changes to a buffer
Bram Moolenaar <Bram@vim.org>
parents:
16631
diff
changeset
|
474 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 #ifdef FEAT_DIFF |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 if (curwin->w_p_diff && diff_internal()) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 curtab->tp_diff_update = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 // set the '. mark |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22282
diff
changeset
|
481 if ((cmdmod.cmod_flags & CMOD_KEEPJUMPS) == 0) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 curbuf->b_last_change.lnum = lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 curbuf->b_last_change.col = col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 // Create a new entry if a new undo-able change was started or we |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 // don't have an entry yet. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 if (curbuf->b_new_change || curbuf->b_changelistlen == 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 if (curbuf->b_changelistlen == 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 add = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 // Don't create a new entry when the line number is the same |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 // as the last one and the column is not too far away. Avoids |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 // creating many entries for typing "xxxxx". |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 p = &curbuf->b_changelist[curbuf->b_changelistlen - 1]; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 if (p->lnum != lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 add = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 cols = comp_textwidth(FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 if (cols == 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 cols = 79; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 add = (p->col + cols < col || col + cols < p->col); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 if (add) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 // This is the first of a new sequence of undo-able changes |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 // and it's at some distance of the last change. Use a new |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 // position in the changelist. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 curbuf->b_new_change = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 if (curbuf->b_changelistlen == JUMPLISTSIZE) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 // changelist is full: remove oldest entry |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 curbuf->b_changelistlen = JUMPLISTSIZE - 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 mch_memmove(curbuf->b_changelist, curbuf->b_changelist + 1, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 sizeof(pos_T) * (JUMPLISTSIZE - 1)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 FOR_ALL_TAB_WINDOWS(tp, wp) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 // Correct position in changelist for other windows on |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 // this buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 if (wp->w_buffer == curbuf && wp->w_changelistidx > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 --wp->w_changelistidx; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 FOR_ALL_TAB_WINDOWS(tp, wp) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 // For other windows, if the position in the changelist is |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 // at the end it stays at the end. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 if (wp->w_buffer == curbuf |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 && wp->w_changelistidx == curbuf->b_changelistlen) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 ++wp->w_changelistidx; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 ++curbuf->b_changelistlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 curbuf->b_changelist[curbuf->b_changelistlen - 1] = |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 curbuf->b_last_change; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 // The current window is always after the last change, so that "g," |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 // takes you back to it. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 curwin->w_changelistidx = curbuf->b_changelistlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 |
28893
aa44d5842d6c
patch 8.2.4969: changing text in Visual mode may cause invalid memory access
Bram Moolenaar <Bram@vim.org>
parents:
28865
diff
changeset
|
547 if (VIsual_active) |
aa44d5842d6c
patch 8.2.4969: changing text in Visual mode may cause invalid memory access
Bram Moolenaar <Bram@vim.org>
parents:
28865
diff
changeset
|
548 check_visual_pos(); |
aa44d5842d6c
patch 8.2.4969: changing text in Visual mode may cause invalid memory access
Bram Moolenaar <Bram@vim.org>
parents:
28865
diff
changeset
|
549 |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 FOR_ALL_TAB_WINDOWS(tp, wp) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 if (wp->w_buffer == curbuf) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 { |
27758
5a8258fde1d9
patch 8.2.4405: compiler warning for unused variable without +folding
Bram Moolenaar <Bram@vim.org>
parents:
27754
diff
changeset
|
554 #ifdef FEAT_FOLDING |
27754
1f37e5082343
patch 8.2.4403: ml_get error with nested folds and deleting lines
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
555 linenr_T last = lnume + xtra - 1; // last line after the change |
27758
5a8258fde1d9
patch 8.2.4405: compiler warning for unused variable without +folding
Bram Moolenaar <Bram@vim.org>
parents:
27754
diff
changeset
|
556 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 // Mark this window to be redrawn later. |
29812
68ef14b21d01
patch 9.0.0245: mechanism to prevent recursive screen updating is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
558 if (!redraw_not_allowed && wp->w_redr_type < UPD_VALID) |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
559 wp->w_redr_type = UPD_VALID; |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 // Check if a change in the buffer has invalidated the cached |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 // values for the cursor. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 #ifdef FEAT_FOLDING |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 // Update the folds for this window. Can't postpone this, because |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 // a following operator might work on the whole fold: ">>dd". |
27754
1f37e5082343
patch 8.2.4403: ml_get error with nested folds and deleting lines
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
566 foldUpdate(wp, lnum, last); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 // The change may cause lines above or below the change to become |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 // included in a fold. Set lnum/lnume to the first/last line that |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 // might be displayed differently. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 // Set w_cline_folded here as an efficient way to update it when |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 // inserting lines just above a closed fold. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 i = hasFoldingWin(wp, lnum, &lnum, NULL, FALSE, NULL); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 if (wp->w_cursor.lnum == lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 wp->w_cline_folded = i; |
27754
1f37e5082343
patch 8.2.4403: ml_get error with nested folds and deleting lines
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
576 i = hasFoldingWin(wp, last, NULL, &last, FALSE, NULL); |
1f37e5082343
patch 8.2.4403: ml_get error with nested folds and deleting lines
Bram Moolenaar <Bram@vim.org>
parents:
27706
diff
changeset
|
577 if (wp->w_cursor.lnum == last) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 wp->w_cline_folded = i; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 // If the changed line is in a range of previously folded lines, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 // compare with the first line in that range. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 if (wp->w_cursor.lnum <= lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 i = find_wl_entry(wp, lnum); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 changed_line_abv_curs_win(wp); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 if (wp->w_cursor.lnum > lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 changed_line_abv_curs_win(wp); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 else if (wp->w_cursor.lnum == lnum && wp->w_cursor.col >= col) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 changed_cline_bef_curs_win(wp); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 if (wp->w_botline >= lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 { |
25246
5932642234e1
patch 8.2.3159: cursor displayed in wrong position after deleting line
Bram Moolenaar <Bram@vim.org>
parents:
24643
diff
changeset
|
595 if (xtra < 0) |
5932642234e1
patch 8.2.3159: cursor displayed in wrong position after deleting line
Bram Moolenaar <Bram@vim.org>
parents:
24643
diff
changeset
|
596 invalidate_botline_win(wp); |
5932642234e1
patch 8.2.3159: cursor displayed in wrong position after deleting line
Bram Moolenaar <Bram@vim.org>
parents:
24643
diff
changeset
|
597 else |
5932642234e1
patch 8.2.3159: cursor displayed in wrong position after deleting line
Bram Moolenaar <Bram@vim.org>
parents:
24643
diff
changeset
|
598 // Assume that botline doesn't change (inserted lines make |
5932642234e1
patch 8.2.3159: cursor displayed in wrong position after deleting line
Bram Moolenaar <Bram@vim.org>
parents:
24643
diff
changeset
|
599 // other lines scroll down below botline). |
5932642234e1
patch 8.2.3159: cursor displayed in wrong position after deleting line
Bram Moolenaar <Bram@vim.org>
parents:
24643
diff
changeset
|
600 approximate_botline_win(wp); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 // Check if any w_lines[] entries have become invalid. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 // For entries below the change: Correct the lnums for |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 // inserted/deleted lines. Makes it possible to stop displaying |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 // after the change. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 for (i = 0; i < wp->w_lines_valid; ++i) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 if (wp->w_lines[i].wl_valid) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 if (wp->w_lines[i].wl_lnum >= lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 if (wp->w_lines[i].wl_lnum < lnume) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 // line included in change |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 wp->w_lines[i].wl_valid = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 else if (xtra != 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 // line below change |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 wp->w_lines[i].wl_lnum += xtra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 #ifdef FEAT_FOLDING |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 wp->w_lines[i].wl_lastlnum += xtra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 #ifdef FEAT_FOLDING |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 else if (wp->w_lines[i].wl_lastlnum >= lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 // change somewhere inside this range of folded lines, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 // may need to be redrawn |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 wp->w_lines[i].wl_valid = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 #ifdef FEAT_FOLDING |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 // Take care of side effects for setting w_topline when folds have |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 // changed. Esp. when the buffer was changed in another window. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 if (hasAnyFolding(wp)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 set_topline(wp, wp->w_topline); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 #endif |
28363
a9a56b567709
patch 8.2.4707: redrawing could be a bit more efficient
Bram Moolenaar <Bram@vim.org>
parents:
28236
diff
changeset
|
642 // If lines have been added or removed, relative numbering always |
a9a56b567709
patch 8.2.4707: redrawing could be a bit more efficient
Bram Moolenaar <Bram@vim.org>
parents:
28236
diff
changeset
|
643 // requires a redraw. |
28236
3f6c0a5c99bb
patch 8.2.4644: redrawing too often when 'relativenumber' is set
Bram Moolenaar <Bram@vim.org>
parents:
27758
diff
changeset
|
644 if (wp->w_p_rnu && xtra != 0) |
28363
a9a56b567709
patch 8.2.4707: redrawing could be a bit more efficient
Bram Moolenaar <Bram@vim.org>
parents:
28236
diff
changeset
|
645 { |
a9a56b567709
patch 8.2.4707: redrawing could be a bit more efficient
Bram Moolenaar <Bram@vim.org>
parents:
28236
diff
changeset
|
646 wp->w_last_cursor_lnum_rnu = 0; |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
647 redraw_win_later(wp, UPD_VALID); |
28363
a9a56b567709
patch 8.2.4707: redrawing could be a bit more efficient
Bram Moolenaar <Bram@vim.org>
parents:
28236
diff
changeset
|
648 } |
17859
06e655ce1938
patch 8.1.1926: cursorline not redrawn when putting a line above the cursor
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
649 #ifdef FEAT_SYN_HL |
18440
d6cb1e706fb7
patch 8.1.2214: too much is redrawn when 'cursorline' is set
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
650 // Cursor line highlighting probably need to be updated with |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
651 // "UPD_VALID" if it's below the change. |
18440
d6cb1e706fb7
patch 8.1.2214: too much is redrawn when 'cursorline' is set
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
652 // If the cursor line is inside the change we need to redraw more. |
d6cb1e706fb7
patch 8.1.2214: too much is redrawn when 'cursorline' is set
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
653 if (wp->w_p_cul) |
d6cb1e706fb7
patch 8.1.2214: too much is redrawn when 'cursorline' is set
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
654 { |
d6cb1e706fb7
patch 8.1.2214: too much is redrawn when 'cursorline' is set
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
655 if (xtra == 0) |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
656 redraw_win_later(wp, UPD_VALID); |
18440
d6cb1e706fb7
patch 8.1.2214: too much is redrawn when 'cursorline' is set
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
657 else if (lnum <= wp->w_last_cursorline) |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
658 redraw_win_later(wp, UPD_SOME_VALID); |
18440
d6cb1e706fb7
patch 8.1.2214: too much is redrawn when 'cursorline' is set
Bram Moolenaar <Bram@vim.org>
parents:
18434
diff
changeset
|
659 } |
17859
06e655ce1938
patch 8.1.1926: cursorline not redrawn when putting a line above the cursor
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
660 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 } |
29050
a2710736125a
patch 8.2.5047: CurSearch highlight is often wrong
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
662 #ifdef FEAT_SEARCH_EXTRA |
a2710736125a
patch 8.2.5047: CurSearch highlight is often wrong
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
663 if (wp == curwin && xtra != 0 && search_hl_has_cursor_lnum >= lnum) |
a2710736125a
patch 8.2.5047: CurSearch highlight is often wrong
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
664 search_hl_has_cursor_lnum += xtra; |
a2710736125a
patch 8.2.5047: CurSearch highlight is often wrong
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
665 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 // Call update_screen() later, which checks out what needs to be redrawn, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 // since it notices b_mod_set and then uses b_mod_*. |
29812
68ef14b21d01
patch 9.0.0245: mechanism to prevent recursive screen updating is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
670 set_must_redraw(UPD_VALID); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 // when the cursor line is changed always trigger CursorMoved |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 if (lnum <= curwin->w_cursor.lnum |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 && lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 last_cursormoved.lnum = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 static void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 changedOneline(buf_T *buf, linenr_T lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 if (buf->b_mod_set) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 // find the maximum area that must be redisplayed |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 if (lnum < buf->b_mod_top) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 buf->b_mod_top = lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 else if (lnum >= buf->b_mod_bot) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 buf->b_mod_bot = lnum + 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 // set the area that must be redisplayed to one line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 buf->b_mod_set = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 buf->b_mod_top = lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 buf->b_mod_bot = lnum + 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 buf->b_mod_xlines = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 * Changed bytes within a single line for the current buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 * - marks the windows on this buffer to be redisplayed |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 * - marks the buffer changed by calling changed() |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 * - invalidates cached values |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 * Careful: may trigger autocommands that reload the buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 changed_bytes(linenr_T lnum, colnr_T col) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 changedOneline(curbuf, lnum); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 changed_common(lnum, col, lnum + 1, 0L); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 |
30545
9a6f7e750697
patch 9.0.0608: with spelling, deleting a full stop does not update next line
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
712 #ifdef FEAT_SPELL |
9a6f7e750697
patch 9.0.0608: with spelling, deleting a full stop does not update next line
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
713 // When text has been changed at the end of the line, possibly the start of |
9a6f7e750697
patch 9.0.0608: with spelling, deleting a full stop does not update next line
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
714 // the next line may have SpellCap that should be removed or it needs to be |
9a6f7e750697
patch 9.0.0608: with spelling, deleting a full stop does not update next line
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
715 // displayed. Schedule the next line for redrawing just in case. |
30659
ea16b081493d
patch 9.0.0664: bad redrawing with spell checking, using "C" and "$" in 'cpo'
Bram Moolenaar <Bram@vim.org>
parents:
30545
diff
changeset
|
716 // Don't do this when displaying '$' at the end of changed text. |
ea16b081493d
patch 9.0.0664: bad redrawing with spell checking, using "C" and "$" in 'cpo'
Bram Moolenaar <Bram@vim.org>
parents:
30545
diff
changeset
|
717 if (spell_check_window(curwin) |
ea16b081493d
patch 9.0.0664: bad redrawing with spell checking, using "C" and "$" in 'cpo'
Bram Moolenaar <Bram@vim.org>
parents:
30545
diff
changeset
|
718 && lnum < curbuf->b_ml.ml_line_count |
ea16b081493d
patch 9.0.0664: bad redrawing with spell checking, using "C" and "$" in 'cpo'
Bram Moolenaar <Bram@vim.org>
parents:
30545
diff
changeset
|
719 && vim_strchr(p_cpo, CPO_DOLLAR) == NULL) |
30545
9a6f7e750697
patch 9.0.0608: with spelling, deleting a full stop does not update next line
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
720 redrawWinline(curwin, lnum + 1); |
9a6f7e750697
patch 9.0.0608: with spelling, deleting a full stop does not update next line
Bram Moolenaar <Bram@vim.org>
parents:
30261
diff
changeset
|
721 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 #ifdef FEAT_DIFF |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 // Diff highlighting in other diff windows may need to be updated too. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 if (curwin->w_p_diff) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 win_T *wp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 linenr_T wlnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 FOR_ALL_WINDOWS(wp) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 if (wp->w_p_diff && wp != curwin) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 { |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
732 redraw_win_later(wp, UPD_VALID); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 wlnum = diff_lnum_win(lnum, wp); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 if (wlnum > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 changedOneline(wp->w_buffer, wlnum); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 * Like changed_bytes() but also adjust text properties for "added" bytes. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 * When "added" is negative text was deleted. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 */ |
22282
5adb97bf0b32
patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
745 void |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 inserted_bytes(linenr_T lnum, colnr_T col, int added UNUSED) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 { |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
748 #ifdef FEAT_PROP_POPUP |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 if (curbuf->b_has_textprop && added != 0) |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
750 adjust_prop_columns(lnum, col, added, 0); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 #endif |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
752 |
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
753 changed_bytes(lnum, col); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 * Appended "count" lines below line "lnum" in the current buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 * Must be called AFTER the change and after mark_adjust(). |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 * Takes care of marking the buffer to be redrawn and sets the changed flag. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 appended_lines(linenr_T lnum, long count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 changed_lines(lnum + 1, 0, lnum + 1, count); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 * Like appended_lines(), but adjust marks first. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 appended_lines_mark(linenr_T lnum, long count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 // Skip mark_adjust when adding a line after the last one, there can't |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 // be marks there. But it's still needed in diff mode. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 if (lnum + count < curbuf->b_ml.ml_line_count |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 #ifdef FEAT_DIFF |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 || curwin->w_p_diff |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 ) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 changed_lines(lnum + 1, 0, lnum + 1, count); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 * Deleted "count" lines at line "lnum" in the current buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 * Must be called AFTER the change and after mark_adjust(). |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 * Takes care of marking the buffer to be redrawn and sets the changed flag. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 deleted_lines(linenr_T lnum, long count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 changed_lines(lnum, 0, lnum + count, -count); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 * Like deleted_lines(), but adjust marks first. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 * Make sure the cursor is on a valid line before calling, a GUI callback may |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 * be triggered to display the cursor. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 deleted_lines_mark(linenr_T lnum, long count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
802 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 changed_lines(lnum, 0, lnum + count, -count); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 * Marks the area to be redrawn after a change. |
29708
d97b2ce26258
patch 9.0.0194: cursor displayed in wrong position after removing text prop
Bram Moolenaar <Bram@vim.org>
parents:
29660
diff
changeset
|
809 * Consider also calling changed_line_display_buf(). |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 */ |
24643
09e64e81c473
patch 8.2.2860: adding a text property causes the whole window to be redawn
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
811 void |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 changed_lines_buf( |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 buf_T *buf, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 linenr_T lnum, // first line with change |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 linenr_T lnume, // line below last changed line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 long xtra) // number of extra lines (negative when deleting) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 if (buf->b_mod_set) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 // find the maximum area that must be redisplayed |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 if (lnum < buf->b_mod_top) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 buf->b_mod_top = lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 if (lnum < buf->b_mod_bot) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 // adjust old bot position for xtra lines |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 buf->b_mod_bot += xtra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 if (buf->b_mod_bot < lnum) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 buf->b_mod_bot = lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 if (lnume + xtra > buf->b_mod_bot) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 buf->b_mod_bot = lnume + xtra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 buf->b_mod_xlines += xtra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 // set the area that must be redisplayed |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 buf->b_mod_set = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 buf->b_mod_top = lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 buf->b_mod_bot = lnume + xtra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 buf->b_mod_xlines = xtra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 * Changed lines for the current buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 * Must be called AFTER the change and after mark_adjust(). |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 * - mark the buffer changed by calling changed() |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 * - mark the windows on this buffer to be redisplayed |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 * - invalidate cached values |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 * "lnum" is the first line that needs displaying, "lnume" the first line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 * below the changed lines (BEFORE the change). |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 * When only inserting lines, "lnum" and "lnume" are equal. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 * Takes care of calling changed() and updating b_mod_*. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 * Careful: may trigger autocommands that reload the buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 changed_lines( |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 linenr_T lnum, // first line with change |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 colnr_T col, // column in first line with change |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 linenr_T lnume, // line below last changed line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 long xtra) // number of extra lines (negative when deleting) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 changed_lines_buf(curbuf, lnum, lnume, xtra); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 #ifdef FEAT_DIFF |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 if (xtra == 0 && curwin->w_p_diff && !diff_internal()) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 // When the number of lines doesn't change then mark_adjust() isn't |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 // called and other diff buffers still need to be marked for |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 // displaying. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 win_T *wp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 linenr_T wlnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 FOR_ALL_WINDOWS(wp) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 if (wp->w_p_diff && wp != curwin) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 { |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29708
diff
changeset
|
877 redraw_win_later(wp, UPD_VALID); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 wlnum = diff_lnum_win(lnum, wp); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 if (wlnum > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 changed_lines_buf(wp->w_buffer, wlnum, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 lnume - lnum + wlnum, 0L); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 changed_common(lnum, col, lnume, xtra); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 * Called when the changed flag must be reset for buffer "buf". |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 * When "ff" is TRUE also reset 'fileformat'. |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
892 * When "always_inc_changedtick" is TRUE b:changedtick is incremented also when |
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
893 * the changed flag was off. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 void |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
896 unchanged(buf_T *buf, int ff, int always_inc_changedtick) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 if (buf->b_changed || (ff && file_ff_differs(buf, FALSE))) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 buf->b_changed = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 ml_setflags(buf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
902 if (ff) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 save_file_ff(buf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 check_status(buf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 redraw_tabline = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 need_maketitle = TRUE; // set window title later |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
907 ++CHANGEDTICK(buf); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 } |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
909 else if (always_inc_changedtick) |
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16972
diff
changeset
|
910 ++CHANGEDTICK(buf); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 #ifdef FEAT_NETBEANS_INTG |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 netbeans_unmodified(buf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 /* |
18679
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
917 * Save the current values of 'fileformat' and 'fileencoding', so that we know |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
918 * the file must be considered changed when the value is different. |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
919 */ |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
920 void |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
921 save_file_ff(buf_T *buf) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
922 { |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
923 buf->b_start_ffc = *buf->b_p_ff; |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
924 buf->b_start_eol = buf->b_p_eol; |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
925 buf->b_start_bomb = buf->b_p_bomb; |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
926 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18679
diff
changeset
|
927 // Only use free/alloc when necessary, they take time. |
18679
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
928 if (buf->b_start_fenc == NULL |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
929 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
930 { |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
931 vim_free(buf->b_start_fenc); |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
932 buf->b_start_fenc = vim_strsave(buf->b_p_fenc); |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
933 } |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
934 } |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
935 |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
936 /* |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
937 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
938 * from when editing started (save_file_ff() called). |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
939 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
940 * changed and 'binary' is not set. |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
941 * Also when 'endofline' was changed and 'fixeol' is not set. |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
942 * When "ignore_empty" is true don't consider a new, empty buffer to be |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
943 * changed. |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
944 */ |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
945 int |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
946 file_ff_differs(buf_T *buf, int ignore_empty) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
947 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18679
diff
changeset
|
948 // In a buffer that was never loaded the options are not valid. |
18679
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
949 if (buf->b_flags & BF_NEVERLOADED) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
950 return FALSE; |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
951 if (ignore_empty |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
952 && (buf->b_flags & BF_NEW) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
953 && buf->b_ml.ml_line_count == 1 |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
954 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
955 return FALSE; |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
956 if (buf->b_start_ffc != *buf->b_p_ff) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
957 return TRUE; |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
958 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
959 return TRUE; |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
960 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
961 return TRUE; |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
962 if (buf->b_start_fenc == NULL) |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
963 return (*buf->b_p_fenc != NUL); |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
964 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0); |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
965 } |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
966 |
fd95d4dbeb37
patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
967 /* |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 * Insert string "p" at the cursor position. Stops at a NUL byte. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 * Handles Replace mode and multi-byte characters. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 ins_bytes(char_u *p) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 ins_bytes_len(p, (int)STRLEN(p)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 * Insert string "p" with length "len" at the cursor position. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 * Handles Replace mode and multi-byte characters. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 ins_bytes_len(char_u *p, int len) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 int i; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 int n; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 if (has_mbyte) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 for (i = 0; i < len; i += n) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 if (enc_utf8) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 // avoid reading past p[len] |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 n = utfc_ptr2len_len(p + i, len - i); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 n = (*mb_ptr2len)(p + i); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 ins_char_bytes(p + i, n); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 for (i = 0; i < len; ++i) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 ins_char(p[i]); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 * Insert or replace a single character at the cursor position. |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1004 * When in MODE_REPLACE or MODE_VREPLACE state, replace any existing character. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 * Caller must have prepared for undo. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 * For multi-byte characters we get the whole character, the caller must |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 * convert bytes to a character. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 ins_char(int c) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 char_u buf[MB_MAXBYTES + 1]; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 int n = (*mb_char2bytes)(c, buf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 // When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 // Happens for CTRL-Vu9900. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 if (buf[0] == 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 buf[0] = '\n'; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 ins_char_bytes(buf, n); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 ins_char_bytes(char_u *buf, int charlen) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 int c = buf[0]; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 int newlen; // nr of bytes inserted |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 int oldlen; // nr of bytes deleted (0 when not replacing) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 char_u *p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 char_u *newp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 char_u *oldp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 int linelen; // length of old line including NUL |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 colnr_T col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 linenr_T lnum = curwin->w_cursor.lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 int i; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 // Break tabs if needed. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 if (virtual_active() && curwin->w_cursor.coladd > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 coladvance_force(getviscol()); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 col = curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 oldp = ml_get(lnum); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 linelen = (int)STRLEN(oldp) + 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 // The lengths default to the values for when not replacing. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 oldlen = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 newlen = charlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 if (State & REPLACE_FLAG) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 if (State & VREPLACE_FLAG) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 colnr_T new_vcol = 0; // init for GCC |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 colnr_T vcol; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 int old_list; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 // Disable 'list' temporarily, unless 'cpo' contains the 'L' flag. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 // Returns the old value of list, so when finished, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 // curwin->w_p_list should be set back to this. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 old_list = curwin->w_p_list; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 if (old_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 curwin->w_p_list = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 // In virtual replace mode each character may replace one or more |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 // characters (zero if it's a TAB). Count the number of bytes to |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 // be deleted to make room for the new character, counting screen |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 // cells. May result in adding spaces to fill a gap. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 getvcol(curwin, &curwin->w_cursor, NULL, &vcol, NULL); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 new_vcol = vcol + chartabsize(buf, vcol); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 while (oldp[col + oldlen] != NUL && vcol < new_vcol) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 vcol += chartabsize(oldp + col + oldlen, vcol); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 // Don't need to remove a TAB that takes us to the right |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 // position. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 if (vcol > new_vcol && oldp[col + oldlen] == TAB) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 oldlen += (*mb_ptr2len)(oldp + col + oldlen); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 // Deleted a bit too much, insert spaces. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 if (vcol > new_vcol) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 newlen += vcol - new_vcol; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 curwin->w_p_list = old_list; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 else if (oldp[col] != NUL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 // normal replace |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 oldlen = (*mb_ptr2len)(oldp + col); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 // Push the replaced bytes onto the replace stack, so that they can be |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 // put back when BS is used. The bytes of a multi-byte character are |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 // done the other way around, so that the first byte is popped off |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 // first (it tells the byte length of the character). |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 replace_push(NUL); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 for (i = 0; i < oldlen; ++i) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 if (has_mbyte) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 i += replace_push_mb(oldp + col + i) - 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 replace_push(oldp[col + i]); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1105 newp = alloc(linelen + newlen - oldlen); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 if (newp == NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 return; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 // Copy bytes before the cursor. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 if (col > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 mch_memmove(newp, oldp, (size_t)col); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 // Copy bytes after the changed character(s). |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 p = newp + col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 if (linelen > col + oldlen) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 mch_memmove(p + newlen, oldp + col + oldlen, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 (size_t)(linelen - col - oldlen)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 // Insert or overwrite the new character. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 mch_memmove(p, buf, charlen); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 i = charlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 // Fill with spaces when necessary. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 while (i < newlen) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 p[i++] = ' '; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 // Replace the line in the buffer. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 ml_replace(lnum, newp, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 // mark the buffer as changed and prepare for displaying |
28931
b57caac54649
patch 8.2.4988: textprop in wrong position when replacing multi-byte chars
Bram Moolenaar <Bram@vim.org>
parents:
28893
diff
changeset
|
1131 changed_bytes(lnum, col); |
b57caac54649
patch 8.2.4988: textprop in wrong position when replacing multi-byte chars
Bram Moolenaar <Bram@vim.org>
parents:
28893
diff
changeset
|
1132 #ifdef FEAT_PROP_POPUP |
b57caac54649
patch 8.2.4988: textprop in wrong position when replacing multi-byte chars
Bram Moolenaar <Bram@vim.org>
parents:
28893
diff
changeset
|
1133 if (curbuf->b_has_textprop && newlen != oldlen) |
b57caac54649
patch 8.2.4988: textprop in wrong position when replacing multi-byte chars
Bram Moolenaar <Bram@vim.org>
parents:
28893
diff
changeset
|
1134 adjust_prop_columns(lnum, col, newlen - oldlen, |
b57caac54649
patch 8.2.4988: textprop in wrong position when replacing multi-byte chars
Bram Moolenaar <Bram@vim.org>
parents:
28893
diff
changeset
|
1135 State & REPLACE_FLAG ? APC_SUBSTITUTE : 0); |
b57caac54649
patch 8.2.4988: textprop in wrong position when replacing multi-byte chars
Bram Moolenaar <Bram@vim.org>
parents:
28893
diff
changeset
|
1136 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 // If we're in Insert or Replace mode and 'showmatch' is set, then briefly |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 // show the match for right parens and braces. |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1140 if (p_sm && (State & MODE_INSERT) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 && msg_silent == 0 |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
1142 && !ins_compl_active()) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 if (has_mbyte) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 showmatch(mb_ptr2char(buf)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 showmatch(c); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 #ifdef FEAT_RIGHTLEFT |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 if (!p_ri || (State & REPLACE_FLAG)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 // Normal insert: move cursor right |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 curwin->w_cursor.col += charlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 // TODO: should try to update w_row here, to avoid recomputing it later. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 * Insert a string at the cursor position. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 * Note: Does NOT handle Replace mode. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 * Caller must have prepared for undo. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 ins_str(char_u *s) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 char_u *oldp, *newp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 int newlen = (int)STRLEN(s); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 int oldlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 colnr_T col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 linenr_T lnum = curwin->w_cursor.lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 if (virtual_active() && curwin->w_cursor.coladd > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 coladvance_force(getviscol()); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 col = curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 oldp = ml_get(lnum); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 oldlen = (int)STRLEN(oldp); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1182 newp = alloc(oldlen + newlen + 1); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 if (newp == NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 return; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 if (col > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 mch_memmove(newp, oldp, (size_t)col); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 mch_memmove(newp + col, s, (size_t)newlen); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 ml_replace(lnum, newp, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 inserted_bytes(lnum, col, newlen); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 curwin->w_cursor.col += newlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 * Delete one character under the cursor. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 * If "fixpos" is TRUE, don't leave the cursor on the NUL after the line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 * Caller must have prepared for undo. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 * return FAIL for failure, OK otherwise |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 int |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 del_char(int fixpos) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 if (has_mbyte) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 // Make sure the cursor is at the start of a character. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 mb_adjust_cursor(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 if (*ml_get_cursor() == NUL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 return FAIL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 return del_chars(1L, fixpos); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 return del_bytes(1L, fixpos, TRUE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 * Like del_bytes(), but delete characters instead of bytes. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 int |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 del_chars(long count, int fixpos) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 long bytes = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 long i; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 char_u *p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 int l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 p = ml_get_cursor(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 for (i = 0; i < count && *p != NUL; ++i) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 l = (*mb_ptr2len)(p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 bytes += l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 p += l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 return del_bytes(bytes, fixpos, TRUE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 * Delete "count" bytes under the cursor. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 * If "fixpos" is TRUE, don't leave the cursor on the NUL after the line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 * Caller must have prepared for undo. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 * Return FAIL for failure, OK otherwise. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 int |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 del_bytes( |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 long count, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 int fixpos_arg, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 int use_delcombine UNUSED) // 'delcombine' option applies |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 char_u *oldp, *newp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 colnr_T oldlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 colnr_T newlen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 linenr_T lnum = curwin->w_cursor.lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 colnr_T col = curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 int alloc_newp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 long movelen; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 int fixpos = fixpos_arg; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 oldp = ml_get(lnum); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 oldlen = (int)STRLEN(oldp); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 // Can't do anything when the cursor is on the NUL after the line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 if (col >= oldlen) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 return FAIL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 // If "count" is zero there is nothing to do. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 if (count == 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 return OK; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 // If "count" is negative the caller must be doing something wrong. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 if (count < 1) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 { |
26897
d02d40f0261c
patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26811
diff
changeset
|
1272 siemsg(e_invalid_count_for_del_bytes_nr, count); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 return FAIL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 // If 'delcombine' is set and deleting (less than) one character, only |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 // delete the last combining character. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 if (p_deco && use_delcombine && enc_utf8 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 && utfc_ptr2len(oldp + col) >= count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 int cc[MAX_MCO]; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 int n; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 (void)utfc_ptr2char(oldp + col, cc); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 if (cc[0] != NUL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 // Find the last composing char, there can be several. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 n = col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 do |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 col = n; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 count = utf_ptr2len(oldp + n); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 n += count; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 } while (UTF_COMPOSINGLIKE(oldp + col, oldp + n)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 fixpos = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1297 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 // When count is too big, reduce it. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 movelen = (long)oldlen - (long)col - count + 1; // includes trailing NUL |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 if (movelen <= 1) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 // If we just took off the last character of a non-blank line, and |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 // fixpos is TRUE, we don't want to end up positioned at the NUL, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 // unless "restart_edit" is set or 'virtualedit' contains "onemore". |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 if (col > 0 && fixpos && restart_edit == 0 |
29660
e134ff00be57
patch 9.0.0170: various minor code formatting issues
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
1307 && (get_ve_flags() & VE_ONEMORE) == 0) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 --curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 curwin->w_cursor.coladd = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 if (has_mbyte) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 curwin->w_cursor.col -= |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 (*mb_head_off)(oldp, oldp + curwin->w_cursor.col); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 count = oldlen - col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 movelen = 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 newlen = oldlen - count; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 // If the old line has been allocated the deletion can be done in the |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 // existing line. Otherwise a new line has to be allocated |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 // Can't do this when using Netbeans, because we would need to invoke |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 // netbeans_removed(), which deallocates the line. Let ml_replace() take |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 // care of notifying Netbeans. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 #ifdef FEAT_NETBEANS_INTG |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 if (netbeans_active()) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 alloc_newp = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 alloc_newp = !ml_line_alloced(); // check if oldp was allocated |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 if (!alloc_newp) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 newp = oldp; // use same allocated memory |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 { // need to allocate a new line |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1335 newp = alloc(newlen + 1); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1336 if (newp == NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 return FAIL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 mch_memmove(newp, oldp, (size_t)col); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 mch_memmove(newp + col, oldp + col + count, (size_t)movelen); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 if (alloc_newp) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 ml_replace(lnum, newp, FALSE); |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
1343 #ifdef FEAT_PROP_POPUP |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 // Also move any following text properties. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 if (oldlen + 1 < curbuf->b_ml.ml_line_len) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 mch_memmove(newp + newlen + 1, oldp + oldlen + 1, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 (size_t)curbuf->b_ml.ml_line_len - oldlen - 1); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 curbuf->b_ml.ml_line_len -= count; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1351 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1354 // mark the buffer as changed and prepare for displaying |
19534
36ec10251b2b
patch 8.2.0324: text property not updated correctly when inserting/deleting
Bram Moolenaar <Bram@vim.org>
parents:
19027
diff
changeset
|
1355 inserted_bytes(lnum, col, -count); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1356 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1357 return OK; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 * open_line: Add a new line below or above the current line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 * |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1363 * For MODE_VREPLACE state, we only add a new line when we get to the end of |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1364 * the file, otherwise we just start replacing the next line. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 * |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1366 * Caller must take care of undo. Since MODE_VREPLACE may affect any number of |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 * lines however, it may call u_save_cursor() again when starting to change a |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 * new line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 * "flags": OPENLINE_DELSPACES delete spaces after cursor |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 * OPENLINE_DO_COM format comments |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 * OPENLINE_KEEPTRAIL keep trailing spaces |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 * OPENLINE_MARKFIX adjust mark positions after the line break |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 * OPENLINE_COM_LIST format comments with list or 2nd line indent |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 * "second_line_indent": indent for after ^^D in Insert mode or if flag |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 * OPENLINE_COM_LIST |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1377 * "did_do_comment" is set to TRUE when intentionally putting the comment |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1378 * leader in fromt of the new line. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 * Return OK for success, FAIL for failure |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 int |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 open_line( |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 int dir, // FORWARD or BACKWARD |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 int flags, |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1386 int second_line_indent, |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1387 int *did_do_comment UNUSED) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 char_u *saved_line; // copy of the original line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 char_u *next_line = NULL; // copy of the next line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 char_u *p_extra = NULL; // what goes to next line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 int less_cols = 0; // less columns for mark in new line |
28865
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
1393 int less_cols_off = 0; // columns to skip for mark and |
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
1394 // textprop adjustment |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 pos_T old_cursor; // old cursor position |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 int newcol = 0; // new cursor column |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 int newindent = 0; // auto-indent of the new line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 int n; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 int trunc_line = FALSE; // truncate current line afterwards |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 int retval = FAIL; // return value |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 int extra_len = 0; // length of p_extra string |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 int lead_len; // length of comment leader |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1403 int comment_start = 0; // start index of the comment leader |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 char_u *lead_flags; // position in 'comments' for comment leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 char_u *leader = NULL; // copy of comment leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 char_u *allocated = NULL; // allocated memory |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 char_u *p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 int saved_char = NUL; // init for GCC |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 pos_T *pos; |
26524
c37950e3d740
patch 8.2.3791: build error with +cindent but without +smartindent
Bram Moolenaar <Bram@vim.org>
parents:
26516
diff
changeset
|
1410 int do_cindent; |
28856
948877671c54
patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents:
28841
diff
changeset
|
1411 int do_si = may_do_si(); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 int no_si = FALSE; // reset did_si afterwards |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 int first_char = NUL; // init for GCC |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 int vreplace_mode; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 int did_append; // appended a new line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 int saved_pi = curbuf->b_p_pi; // copy of preserveindent setting |
30261
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30047
diff
changeset
|
1417 #ifdef FEAT_PROP_POPUP |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30047
diff
changeset
|
1418 int at_eol; // cursor after last character |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30047
diff
changeset
|
1419 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 // make a copy of the current line so we can mess with it |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 saved_line = vim_strsave(ml_get_curline()); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18679
diff
changeset
|
1423 if (saved_line == NULL) // out of memory! |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 return FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 |
30261
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30047
diff
changeset
|
1426 #ifdef FEAT_PROP_POPUP |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30047
diff
changeset
|
1427 at_eol = curwin->w_cursor.col >= (int)STRLEN(saved_line); |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30047
diff
changeset
|
1428 #endif |
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30047
diff
changeset
|
1429 |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 if (State & VREPLACE_FLAG) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1432 // With MODE_VREPLACE we make a copy of the next line, which we will be |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 // starting to replace. First make the new line empty and let vim play |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 // with the indenting and comment leader to its heart's content. Then |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 // we grab what it ended up putting on the new line, put back the |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 // original line, and call ins_char() to put each new character onto |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 // the line, replacing what was there before and pushing the right |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 // stuff onto the replace stack. -- webb. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 if (curwin->w_cursor.lnum < orig_line_count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 next_line = vim_strsave((char_u *)""); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 if (next_line == NULL) // out of memory! |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 goto theend; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1446 // In MODE_VREPLACE state, a NL replaces the rest of the line, and |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1447 // starts replacing the next line, so push all of the characters left |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1448 // on the line onto the replace stack. We'll push any other characters |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1449 // that might be replaced at the start of the next line (due to |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1450 // autoindent etc) a bit later. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 replace_push(NUL); // Call twice because BS over NL expects it |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 replace_push(NUL); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 p = saved_line + curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 while (*p != NUL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 if (has_mbyte) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 p += replace_push_mb(p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 replace_push(*p++); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 saved_line[curwin->w_cursor.col] = NUL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
1464 if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 p_extra = saved_line + curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 if (do_si) // need first char after new line break |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 p = skipwhite(p_extra); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 first_char = *p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 extra_len = (int)STRLEN(p_extra); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 saved_char = *p_extra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 *p_extra = NUL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 u_clearline(); // cannot do "U" command when adding lines |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 did_si = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 ai_col = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 // If we just did an auto-indent, then we didn't type anything on |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 // the prior line, and it should be truncated. Do this even if 'ai' is not |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 // set because automatically inserting a comment leader also sets did_ai. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 if (dir == FORWARD && did_ai) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 trunc_line = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 // If 'autoindent' and/or 'smartindent' is set, try to figure out what |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 // indent to use for the new line. |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
1489 if (curbuf->b_p_ai || do_si) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 // count white space on current line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 #ifdef FEAT_VARTABS |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 newindent = get_indent_str_vtab(saved_line, curbuf->b_p_ts, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 curbuf->b_p_vts_array, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1495 #else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 if (newindent == 0 && !(flags & OPENLINE_COM_LIST)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 newindent = second_line_indent; // for ^^D command in insert mode |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 // Do smart indenting. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 // In insert/replace mode (only when dir == FORWARD) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 // we may move some text to the next line. If it starts with '{' |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 // don't add an indent. Fixes inserting a NL before '{' in line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 // "if (condition) {" |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1506 if (!trunc_line && do_si && *saved_line != NUL |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 && (p_extra == NULL || first_char != '{')) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 char_u *ptr; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 char_u last_char; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 old_cursor = curwin->w_cursor; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 ptr = saved_line; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 if (flags & OPENLINE_DO_COM) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 lead_len = get_leader_len(ptr, NULL, FALSE, TRUE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 lead_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 if (dir == FORWARD) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 // Skip preprocessor directives, unless they are |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 // recognised as comments. |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18068
diff
changeset
|
1522 if ( lead_len == 0 && ptr[0] == '#') |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1523 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 while (ptr[0] == '#' && curwin->w_cursor.lnum > 1) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 ptr = ml_get(--curwin->w_cursor.lnum); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 newindent = get_indent(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1527 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 if (flags & OPENLINE_DO_COM) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 lead_len = get_leader_len(ptr, NULL, FALSE, TRUE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 lead_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1532 if (lead_len > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1534 // This case gets the following right: |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 // /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 // * A comment (read '\' as '/'). |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 // */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1538 // #define IN_THE_WAY |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1539 // This should line up here; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1540 p = skipwhite(ptr); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1541 if (p[0] == '/' && p[1] == '*') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1542 p++; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1543 if (p[0] == '*') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1544 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1545 for (p++; *p; p++) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1546 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 if (p[0] == '/' && p[-1] == '*') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 // End of C comment, indent should line up |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1550 // with the line containing the start of |
29340
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29050
diff
changeset
|
1551 // the comment. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 curwin->w_cursor.col = (colnr_T)(p - ptr); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 if ((pos = findmatch(NULL, NUL)) != NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1555 curwin->w_cursor.lnum = pos->lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 newindent = get_indent(); |
29340
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29050
diff
changeset
|
1557 break; |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1558 } |
29340
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29050
diff
changeset
|
1559 // this may make "ptr" invalid, get it again |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29050
diff
changeset
|
1560 ptr = ml_get(curwin->w_cursor.lnum); |
fba9e366ced4
patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents:
29050
diff
changeset
|
1561 p = ptr + curwin->w_cursor.col; |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1562 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1563 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1564 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1565 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1566 else // Not a comment line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1567 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1568 // Find last non-blank in line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1569 p = ptr + STRLEN(ptr) - 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1570 while (p > ptr && VIM_ISWHITE(*p)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1571 --p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1572 last_char = *p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1573 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 // find the character just before the '{' or ';' |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1575 if (last_char == '{' || last_char == ';') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1576 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1577 if (p > ptr) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 --p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1579 while (p > ptr && VIM_ISWHITE(*p)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1580 --p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1581 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1582 // Try to catch lines that are split over multiple |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1583 // lines. eg: |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1584 // if (condition && |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1585 // condition) { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1586 // Should line up here! |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1587 // } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1588 if (*p == ')') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1589 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1590 curwin->w_cursor.col = (colnr_T)(p - ptr); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1591 if ((pos = findmatch(NULL, '(')) != NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1592 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1593 curwin->w_cursor.lnum = pos->lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1594 newindent = get_indent(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1595 ptr = ml_get_curline(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1596 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 // If last character is '{' do indent, without |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 // checking for "if" and the like. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 if (last_char == '{') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 did_si = TRUE; // do indent |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 no_si = TRUE; // don't delete it when '{' typed |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1605 // Look for "if" and the like, use 'cinwords'. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 // Don't do this if the previous line ended in ';' or |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 // '}'. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1608 else if (last_char != ';' && last_char != '}' |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1609 && cin_is_cinword(ptr)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 did_si = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 else // dir == BACKWARD |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 // Skip preprocessor directives, unless they are |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 // recognised as comments. |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18068
diff
changeset
|
1617 if (lead_len == 0 && ptr[0] == '#') |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 int was_backslashed = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1621 while ((ptr[0] == '#' || was_backslashed) && |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 if (*ptr && ptr[STRLEN(ptr) - 1] == '\\') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 was_backslashed = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 was_backslashed = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 ptr = ml_get(++curwin->w_cursor.lnum); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 if (was_backslashed) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 newindent = 0; // Got to end of file |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 newindent = get_indent(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1634 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 p = skipwhite(ptr); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1636 if (*p == '}') // if line starts with '}': do indent |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 did_si = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1638 else // can delete indent when '{' typed |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1639 can_si_back = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1640 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 curwin->w_cursor = old_cursor; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1643 if (do_si) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 can_si = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 did_ai = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1649 // May do indenting after opening a new line. |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1650 do_cindent = !p_paste && (curbuf->b_p_cin |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
1651 #ifdef FEAT_EVAL |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1652 || *curbuf->b_p_inde != NUL |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
1653 #endif |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1654 ) |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1655 && in_cinkeys(dir == FORWARD |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1656 ? KEY_OPEN_FORW |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1657 : KEY_OPEN_BACK, ' ', linewhite(curwin->w_cursor.lnum)); |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1658 |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 // Find out if the current line starts with a comment leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1660 // This may then be inserted in front of the new line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1661 end_comment_pending = NUL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 if (flags & OPENLINE_DO_COM) |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1663 { |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1664 lead_len = get_leader_len(saved_line, &lead_flags, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1665 dir == BACKWARD, TRUE); |
28765
38698deeda58
patch 8.2.4907: some users do not want a line comment always inserted
Bram Moolenaar <Bram@vim.org>
parents:
28425
diff
changeset
|
1666 if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD |
28972
864fa5276e78
patch 8.2.5008: when 'formatoptions' contains "/" wrongly wrapping comment
Bram Moolenaar <Bram@vim.org>
parents:
28942
diff
changeset
|
1667 && (!has_format_option(FO_NO_OPEN_COMS) |
864fa5276e78
patch 8.2.5008: when 'formatoptions' contains "/" wrongly wrapping comment
Bram Moolenaar <Bram@vim.org>
parents:
28942
diff
changeset
|
1668 || (flags & OPENLINE_FORMAT))) |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1669 { |
26811
f0fdd992cfb9
patch 8.2.3934: repeating line comment is undesired for "O" command
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
1670 // Check for a line comment after code. |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1671 comment_start = check_linecomment(saved_line); |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1672 if (comment_start != MAXCOL) |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1673 { |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1674 lead_len = get_leader_len(saved_line + comment_start, |
26811
f0fdd992cfb9
patch 8.2.3934: repeating line comment is undesired for "O" command
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
1675 &lead_flags, FALSE, TRUE); |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1676 if (lead_len != 0) |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1677 { |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1678 lead_len += comment_start; |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1679 if (did_do_comment != NULL) |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1680 *did_do_comment = TRUE; |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1681 } |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1682 } |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1683 } |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1684 } |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 lead_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 if (lead_len > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 char_u *lead_repl = NULL; // replaces comment leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 int lead_repl_len = 0; // length of *lead_repl |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 char_u lead_middle[COM_MAX_LEN]; // middle-comment string |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 char_u lead_end[COM_MAX_LEN]; // end-comment string |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1693 char_u *comment_end = NULL; // where lead_end has been found |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1694 int extra_space = FALSE; // append extra space |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1695 int current_flag; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1696 int require_blank = FALSE; // requires blank after middle |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1697 char_u *p2; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1698 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1699 // If the comment leader has the start, middle or end flag, it may not |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1700 // be used or may be replaced with the middle leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1701 for (p = lead_flags; *p && *p != ':'; ++p) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1702 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1703 if (*p == COM_BLANK) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1704 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1705 require_blank = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1706 continue; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1707 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1708 if (*p == COM_START || *p == COM_MIDDLE) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1709 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1710 current_flag = *p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1711 if (*p == COM_START) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1712 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1713 // Doing "O" on a start of comment does not insert leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 if (dir == BACKWARD) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 lead_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1718 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1720 // find start of middle part |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1721 (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ","); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1722 require_blank = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1723 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1724 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1725 // Isolate the strings of the middle and end leader. |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18679
diff
changeset
|
1726 while (*p && p[-1] != ':') // find end of middle flags |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1727 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1728 if (*p == COM_BLANK) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1729 require_blank = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1730 ++p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1731 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1732 (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ","); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1733 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1734 while (*p && p[-1] != ':') // find end of end flags |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1736 // Check whether we allow automatic ending of comments |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 if (*p == COM_AUTO_END) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 end_comment_pending = -1; // means we want to set it |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1739 ++p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 n = copy_option_part(&p, lead_end, COM_MAX_LEN, ","); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 if (end_comment_pending == -1) // we can set it now |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1744 end_comment_pending = lead_end[n - 1]; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1745 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1746 // If the end of the comment is in the same line, don't use |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1747 // the comment leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 if (dir == FORWARD) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1750 for (p = saved_line + lead_len; *p; ++p) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1751 if (STRNCMP(p, lead_end, n) == 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1752 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1753 comment_end = p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1754 lead_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1755 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1756 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1757 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1758 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1759 // Doing "o" on a start of comment inserts the middle leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1760 if (lead_len > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 if (current_flag == COM_START) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1764 lead_repl = lead_middle; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1765 lead_repl_len = (int)STRLEN(lead_middle); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1767 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 // If we have hit RETURN immediately after the start |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1769 // comment leader, then put a space after the middle |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1770 // comment leader on the next line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 if (!VIM_ISWHITE(saved_line[lead_len - 1]) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1772 && ((p_extra != NULL |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1773 && (int)curwin->w_cursor.col == lead_len) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 || (p_extra == NULL |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 && saved_line[lead_len] == NUL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1776 || require_blank)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1777 extra_space = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1781 if (*p == COM_END) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 // Doing "o" on the end of a comment does not insert leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 // Remember where the end is, might want to use it to find the |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1785 // start (for C-comments). |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 if (dir == FORWARD) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1787 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1788 comment_end = skipwhite(saved_line); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 lead_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1790 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1792 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1793 // Doing "O" on the end of a comment inserts the middle leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1794 // Find the string for the middle leader, searching backwards. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1795 while (p > curbuf->b_p_com && *p != ',') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1796 --p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1797 for (lead_repl = p; lead_repl > curbuf->b_p_com |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1798 && lead_repl[-1] != ':'; --lead_repl) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 ; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1800 lead_repl_len = (int)(p - lead_repl); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1801 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1802 // We can probably always add an extra space when doing "O" on |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1803 // the comment-end |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1804 extra_space = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1806 // Check whether we allow automatic ending of comments |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1807 for (p2 = p; *p2 && *p2 != ':'; p2++) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1808 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 if (*p2 == COM_AUTO_END) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 end_comment_pending = -1; // means we want to set it |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1812 if (end_comment_pending == -1) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 // Find last character in end-comment string |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 while (*p2 && *p2 != ',') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 p2++; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 end_comment_pending = p2[-1]; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1818 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 if (*p == COM_FIRST) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1823 // Comment leader for first line only: Don't repeat leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1824 // when using "O", blank out leader when using "o". |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1825 if (dir == BACKWARD) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 lead_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 lead_repl = (char_u *)""; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 lead_repl_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 if (lead_len) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1837 // allocate buffer (may concatenate p_extra later) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1838 leader = alloc(lead_len + lead_repl_len + extra_space + extra_len |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1839 + (second_line_indent > 0 ? second_line_indent : 0) + 1); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1840 allocated = leader; // remember to free it later |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1841 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 if (leader == NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1843 lead_len = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1845 { |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1846 int li; |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1847 |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 vim_strncpy(leader, saved_line, lead_len); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1849 |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1850 // TODO: handle multi-byte and double width chars |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1851 for (li = 0; li < comment_start; ++li) |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1852 if (!VIM_ISWHITE(leader[li])) |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1853 leader[li] = ' '; |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1854 |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 // Replace leader with lead_repl, right or left adjusted |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1856 if (lead_repl != NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1857 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1858 int c = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 int off = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1860 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 for (p = lead_flags; *p != NUL && *p != ':'; ) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1863 if (*p == COM_RIGHT || *p == COM_LEFT) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1864 c = *p++; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1865 else if (VIM_ISDIGIT(*p) || *p == '-') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1866 off = getdigits(&p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 ++p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1869 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1870 if (c == COM_RIGHT) // right adjusted leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1871 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 // find last non-white in the leader to line up with |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 for (p = leader + lead_len - 1; p > leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 && VIM_ISWHITE(*p); --p) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1875 ; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 ++p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 // Compute the length of the replaced characters in |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 // screen characters, not bytes. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 int repl_size = vim_strnsize(lead_repl, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 lead_repl_len); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 int old_size = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 char_u *endp = p; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 int l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 while (old_size < repl_size && p > leader) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 MB_PTR_BACK(leader, p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 old_size += ptr2cells(p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 l = lead_repl_len - (int)(endp - p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 if (l != 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 mch_memmove(endp + l, endp, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 (size_t)((leader + lead_len) - endp)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 lead_len += l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 mch_memmove(p, lead_repl, (size_t)lead_repl_len); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 if (p + lead_repl_len > leader + lead_len) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 p[lead_repl_len] = NUL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 // blank-out any other chars from the old leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 while (--p >= leader) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 int l = mb_head_off(leader, p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 if (l > 1) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 p -= l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 if (ptr2cells(p) > 1) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1912 p[1] = ' '; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1913 --l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 mch_memmove(p + 1, p + l + 1, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 (size_t)((leader + lead_len) - (p + l + 1))); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1917 lead_len -= l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1918 *p = ' '; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1919 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 else if (!VIM_ISWHITE(*p)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 *p = ' '; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1922 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 else // left adjusted leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1925 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 p = skipwhite(leader); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 // Compute the length of the replaced characters in |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 // screen characters, not bytes. Move the part that is |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 // not to be overwritten. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 int repl_size = vim_strnsize(lead_repl, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 lead_repl_len); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 int i; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 int l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 for (i = 0; i < lead_len && p[i] != NUL; i += l) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 l = (*mb_ptr2len)(p + i); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 if (vim_strnsize(p, i + l) > repl_size) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1941 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1942 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 if (i != lead_repl_len) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 mch_memmove(p + lead_repl_len, p + i, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1946 (size_t)(lead_len - i - (p - leader))); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1947 lead_len += lead_repl_len - i; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1948 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 mch_memmove(p, lead_repl, (size_t)lead_repl_len); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1951 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1952 // Replace any remaining non-white chars in the old |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 // leader by spaces. Keep Tabs, the indent must |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1954 // remain the same. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 for (p += lead_repl_len; p < leader + lead_len; ++p) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1956 if (!VIM_ISWHITE(*p)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1958 // Don't put a space before a TAB. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1959 if (p + 1 < leader + lead_len && p[1] == TAB) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1960 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1961 --lead_len; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1962 mch_memmove(p, p + 1, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1963 (leader + lead_len) - p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1964 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1965 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1966 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1967 int l = (*mb_ptr2len)(p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1969 if (l > 1) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1970 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1971 if (ptr2cells(p) > 1) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 // Replace a double-wide char with |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 // two spaces |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1975 --l; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 *p++ = ' '; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 mch_memmove(p + 1, p + l, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 (leader + lead_len) - p); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1980 lead_len -= l - 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 *p = ' '; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1984 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1985 *p = NUL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1988 // Recompute the indent, it may have changed. |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
1989 if (curbuf->b_p_ai || do_si) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1990 #ifdef FEAT_VARTABS |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 newindent = get_indent_str_vtab(leader, curbuf->b_p_ts, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1992 curbuf->b_p_vts_array, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1993 #else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 newindent = get_indent_str(leader, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 (int)curbuf->b_p_ts, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 // Add the indent offset |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1999 if (newindent + off < 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2001 off = -newindent; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2002 newindent = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 newindent += off; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2007 // Correct trailing spaces for the shift, so that |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2008 // alignment remains equal. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 while (off > 0 && lead_len > 0 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 && leader[lead_len - 1] == ' ') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2011 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2012 // Don't do it when there is a tab before the space |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2013 if (vim_strchr(skipwhite(leader), '\t') != NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2014 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2015 --lead_len; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2016 --off; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2017 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2018 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 // If the leader ends in white space, don't add an |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2020 // extra space |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2021 if (lead_len > 0 && VIM_ISWHITE(leader[lead_len - 1])) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 extra_space = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 leader[lead_len] = NUL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2024 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2025 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2026 if (extra_space) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2027 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2028 leader[lead_len++] = ' '; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2029 leader[lead_len] = NUL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2030 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2031 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2032 newcol = lead_len; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2033 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2034 // if a new indent will be set below, remove the indent that |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2035 // is in the comment leader |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
2036 if (newindent || did_si) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2037 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2038 while (lead_len && VIM_ISWHITE(*leader)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2039 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2040 --lead_len; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2041 --newcol; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2042 ++leader; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2043 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2044 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2045 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2047 did_si = can_si = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2048 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 else if (comment_end != NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 // We have finished a comment, so we don't use the leader. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2052 // If this was a C-comment and 'ai' or 'si' is set do a normal |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 // indent to align with the line containing the start of the |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2054 // comment. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2055 if (comment_end[0] == '*' && comment_end[1] == '/' && |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
2056 (curbuf->b_p_ai || do_si)) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 old_cursor = curwin->w_cursor; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2059 curwin->w_cursor.col = (colnr_T)(comment_end - saved_line); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 if ((pos = findmatch(NULL, NUL)) != NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2061 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2062 curwin->w_cursor.lnum = pos->lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2063 newindent = get_indent(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2064 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2065 curwin->w_cursor = old_cursor; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2066 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2067 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2068 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2069 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2070 // (State == MODE_INSERT || State == MODE_REPLACE), only when dir == FORWARD |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2071 if (p_extra != NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2072 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2073 *p_extra = saved_char; // restore char that NUL replaced |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2074 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2075 // When 'ai' set or "flags" has OPENLINE_DELSPACES, skip to the first |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2076 // non-blank. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2077 // |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2078 // When in MODE_REPLACE state, put the deleted blanks on the replace |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2079 // stack, preceded by a NUL, so they can be put back when a BS is |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2080 // entered. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2081 if (REPLACE_NORMAL(State)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18679
diff
changeset
|
2082 replace_push(NUL); // end of extra blanks |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2083 if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2084 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 while ((*p_extra == ' ' || *p_extra == '\t') |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 && (!enc_utf8 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 || !utf_iscomposing(utf_ptr2char(p_extra + 1)))) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2088 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 if (REPLACE_NORMAL(State)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 replace_push(*p_extra); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 ++p_extra; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 ++less_cols_off; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2093 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2095 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2096 // columns for marks adjusted for removed columns |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2097 less_cols = (int)(p_extra - saved_line); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2099 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2100 if (p_extra == NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2101 p_extra = (char_u *)""; // append empty line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2103 // concatenate leader and p_extra, if there is a leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2104 if (lead_len) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2105 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2106 if (flags & OPENLINE_COM_LIST && second_line_indent > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2107 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2108 int i; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 int padding = second_line_indent |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 - (newindent + (int)STRLEN(leader)); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2111 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2112 // Here whitespace is inserted after the comment char. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2113 // Below, set_indent(newindent, SIN_INSERT) will insert the |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2114 // whitespace needed before the comment char. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2115 for (i = 0; i < padding; i++) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 STRCAT(leader, " "); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2118 less_cols--; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2119 newcol++; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2120 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2121 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2122 STRCAT(leader, p_extra); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2123 p_extra = leader; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2124 did_ai = TRUE; // So truncating blanks works with comments |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2125 less_cols -= lead_len; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2126 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2127 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2128 end_comment_pending = NUL; // turns out there was no leader |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2129 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 old_cursor = curwin->w_cursor; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2131 if (dir == BACKWARD) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2132 --curwin->w_cursor.lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2133 if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2135 if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, FALSE) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2136 == FAIL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 goto theend; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 // Postpone calling changed_lines(), because it would mess up folding |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 // with markers. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2140 // Skip mark_adjust when adding a line after the last one, there can't |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2141 // be marks there. But still needed in diff mode. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2142 if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 #ifdef FEAT_DIFF |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2144 || curwin->w_p_diff |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2145 #endif |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2146 ) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2148 did_append = TRUE; |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
2149 #ifdef FEAT_PROP_POPUP |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2150 if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0) |
28865
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
2151 // Properties after the split move to the next line. |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
2152 adjust_props_for_split(curwin->w_cursor.lnum, curwin->w_cursor.lnum, |
30261
6b658ef69e93
patch 9.0.0466: virtual text wrong after adding line break after line
Bram Moolenaar <Bram@vim.org>
parents:
30047
diff
changeset
|
2153 curwin->w_cursor.col + 1, 0, at_eol); |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16660
diff
changeset
|
2154 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2155 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2156 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2157 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2158 // In MODE_VREPLACE state we are starting to replace the next line. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2159 curwin->w_cursor.lnum++; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2160 if (curwin->w_cursor.lnum >= Insstart.lnum + vr_lines_changed) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2161 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2162 // In case we NL to a new line, BS to the previous one, and NL |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2163 // again, we don't want to save the new line for undo twice. |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18679
diff
changeset
|
2164 (void)u_save_cursor(); // errors are ignored! |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2165 vr_lines_changed++; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2166 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2167 ml_replace(curwin->w_cursor.lnum, p_extra, TRUE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2168 changed_bytes(curwin->w_cursor.lnum, 0); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2169 curwin->w_cursor.lnum--; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2170 did_append = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2171 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2172 |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
2173 if (newindent || did_si) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2174 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2175 ++curwin->w_cursor.lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2176 if (did_si) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2177 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2178 int sw = (int)get_sw_value(curbuf); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2179 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2180 if (p_sr) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2181 newindent -= newindent % sw; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2182 newindent += sw; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2183 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2184 // Copy the indent |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2185 if (curbuf->b_p_ci) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2186 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2187 (void)copy_indent(newindent, saved_line); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2188 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2189 // Set the 'preserveindent' option so that any further screwing |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2190 // with the line doesn't entirely destroy our efforts to preserve |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2191 // it. It gets restored at the function end. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2192 curbuf->b_p_pi = TRUE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2193 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2194 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2195 (void)set_indent(newindent, SIN_INSERT); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2196 less_cols -= curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2197 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2198 ai_col = curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2199 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2200 // In MODE_REPLACE state, for each character in the new indent, there |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2201 // must be a NUL on the replace stack, for when it is deleted with BS |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2202 if (REPLACE_NORMAL(State)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2203 for (n = 0; n < (int)curwin->w_cursor.col; ++n) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2204 replace_push(NUL); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2205 newcol += curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2206 if (no_si) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2207 did_si = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2208 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2209 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2210 // In MODE_REPLACE state, for each character in the extra leader, there |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2211 // must be a NUL on the replace stack, for when it is deleted with BS. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2212 if (REPLACE_NORMAL(State)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2213 while (lead_len-- > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2214 replace_push(NUL); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2215 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 curwin->w_cursor = old_cursor; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2217 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2218 if (dir == FORWARD) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2219 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2220 if (trunc_line || (State & MODE_INSERT)) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2221 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2222 // truncate current line at cursor |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2223 saved_line[curwin->w_cursor.col] = NUL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2224 // Remove trailing white space, unless OPENLINE_KEEPTRAIL used. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2225 if (trunc_line && !(flags & OPENLINE_KEEPTRAIL)) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2226 truncate_spaces(saved_line); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2227 ml_replace(curwin->w_cursor.lnum, saved_line, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2228 saved_line = NULL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2229 if (did_append) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2230 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2231 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2232 curwin->w_cursor.lnum + 1, 1L); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2233 did_append = FALSE; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2234 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2235 // Move marks after the line break to the new line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2236 if (flags & OPENLINE_MARKFIX) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2237 mark_col_adjust(curwin->w_cursor.lnum, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 curwin->w_cursor.col + less_cols_off, |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 1L, (long)-less_cols, 0); |
28865
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
2240 #ifdef FEAT_PROP_POPUP |
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
2241 // Keep into account the deleted blanks on the new line. |
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
2242 if (curbuf->b_has_textprop && less_cols_off != 0) |
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
2243 adjust_prop_columns(curwin->w_cursor.lnum + 1, 0, |
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
2244 -less_cols_off, 0); |
a04815de0bd3
patch 8.2.4955: text property in wrong position after auto-indent
Bram Moolenaar <Bram@vim.org>
parents:
28856
diff
changeset
|
2245 #endif |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2246 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2247 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2248 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2250 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 // Put the cursor on the new line. Careful: the scrollup() above may |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2252 // have moved w_cursor, we must use old_cursor. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 curwin->w_cursor.lnum = old_cursor.lnum + 1; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2254 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 if (did_append) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2256 changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2257 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 curwin->w_cursor.col = newcol; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2259 curwin->w_cursor.coladd = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2260 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2261 // In MODE_VREPLACE state, we are handling the replace stack ourselves, so |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2262 // stop fixthisline() from doing it (via change_indent()) by telling it |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2263 // we're in normal MODE_INSERT state. |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2264 if (State & VREPLACE_FLAG) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2266 vreplace_mode = State; // So we know to put things right later |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2267 State = MODE_INSERT; |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2268 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2269 else |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2270 vreplace_mode = 0; |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
2271 |
30853
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2272 if (!p_paste) |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2273 { |
30853
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2274 if (leader == NULL |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2275 && !use_indentexpr_for_lisp() |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2276 && curbuf->b_p_lisp |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2277 && curbuf->b_p_ai) |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2278 { |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2279 // do lisp indenting |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2280 fixthisline(get_lisp_indent); |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2281 ai_col = (colnr_T)getwhitecols_curline(); |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2282 } |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2283 else if (do_cindent || (curbuf->b_p_ai && use_indentexpr_for_lisp())) |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2284 { |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2285 // do 'cindent' or 'indentexpr' indenting |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2286 do_c_expr_indent(); |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2287 ai_col = (colnr_T)getwhitecols_curline(); |
40df8a6515f6
patch 9.0.0761: cannot use 'indentexpr' for Lisp indenting
Bram Moolenaar <Bram@vim.org>
parents:
30839
diff
changeset
|
2288 } |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2289 } |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28931
diff
changeset
|
2290 |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2291 if (vreplace_mode != 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2292 State = vreplace_mode; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2293 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2294 // Finally, MODE_VREPLACE gets the stuff on the new line, then puts back |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2295 // the original line, and inserts the new stuff char by char, pushing old |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28765
diff
changeset
|
2296 // stuff onto the replace stack (via ins_char()). |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2297 if (State & VREPLACE_FLAG) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2298 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2299 // Put new line in p_extra |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2300 p_extra = vim_strsave(ml_get_curline()); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2301 if (p_extra == NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2302 goto theend; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2303 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2304 // Put back original line |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2305 ml_replace(curwin->w_cursor.lnum, next_line, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2306 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2307 // Insert new stuff into line again |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 curwin->w_cursor.col = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2309 curwin->w_cursor.coladd = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2310 ins_bytes(p_extra); // will call changed_bytes() |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2311 vim_free(p_extra); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2312 next_line = NULL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2313 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2314 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2315 retval = OK; // success! |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2316 theend: |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2317 curbuf->b_p_pi = saved_pi; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2318 vim_free(saved_line); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2319 vim_free(next_line); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2320 vim_free(allocated); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2321 return retval; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2322 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2323 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2324 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2325 * Delete from cursor to end of line. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2326 * Caller must have prepared for undo. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 * If "fixpos" is TRUE fix the cursor position when done. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2328 * |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2329 * Return FAIL for failure, OK otherwise. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2330 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2331 int |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2332 truncate_line(int fixpos) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2333 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2334 char_u *newp; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2335 linenr_T lnum = curwin->w_cursor.lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2336 colnr_T col = curwin->w_cursor.col; |
28841
77a00aa3e215
patch 8.2.4944: text properties are wrong after "cc"
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2337 char_u *old_line; |
77a00aa3e215
patch 8.2.4944: text properties are wrong after "cc"
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2338 int deleted; |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2339 |
28841
77a00aa3e215
patch 8.2.4944: text properties are wrong after "cc"
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2340 old_line = ml_get(lnum); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2341 if (col == 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2342 newp = vim_strsave((char_u *)""); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2343 else |
28841
77a00aa3e215
patch 8.2.4944: text properties are wrong after "cc"
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2344 newp = vim_strnsave(old_line, col); |
77a00aa3e215
patch 8.2.4944: text properties are wrong after "cc"
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2345 deleted = (int)STRLEN(old_line) - col; |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2346 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2347 if (newp == NULL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2348 return FAIL; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2349 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2350 ml_replace(lnum, newp, FALSE); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2351 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2352 // mark the buffer as changed and prepare for displaying |
28841
77a00aa3e215
patch 8.2.4944: text properties are wrong after "cc"
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2353 inserted_bytes(lnum, curwin->w_cursor.col, -deleted); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2354 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2355 // If "fixpos" is TRUE we don't want to end up positioned at the NUL. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2356 if (fixpos && curwin->w_cursor.col > 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2357 --curwin->w_cursor.col; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2358 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2359 return OK; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2360 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2361 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2362 /* |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2363 * Delete "nlines" lines at the cursor. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2364 * Saves the lines for undo first if "undo" is TRUE. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2365 */ |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2366 void |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2367 del_lines(long nlines, int undo) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2368 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2369 long n; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2370 linenr_T first = curwin->w_cursor.lnum; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2371 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2372 if (nlines <= 0) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2373 return; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2374 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2375 // save the deleted lines for undo |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2376 if (undo && u_savedel(first, nlines) == FAIL) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2377 return; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2378 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2379 for (n = 0; n < nlines; ) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2380 { |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2381 if (curbuf->b_ml.ml_flags & ML_EMPTY) // nothing to delete |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2382 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2383 |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2384 ml_delete_flags(first, ML_DEL_MESSAGE); |
16631
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2385 ++n; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2386 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2387 // If we delete the last line in the file, stop |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2388 if (first > curbuf->b_ml.ml_line_count) |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2389 break; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2390 } |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2391 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2392 // Correct the cursor position before calling deleted_lines_mark(), it may |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2393 // trigger a callback to display the cursor. |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2394 curwin->w_cursor.col = 0; |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2395 check_cursor_lnum(); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2396 |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2397 // adjust marks, mark the buffer as changed and prepare for displaying |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2398 deleted_lines_mark(first, n); |
7217a9c5adb3
Add missing files from patch 8.1.1318
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2399 } |