4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: When getchar() returns a mouse button click there is no way to get
12 the mouse coordinates.
13 Solution: Add v:mouse_win, v:mouse_lnum and v:mouse_col.
14 Files: runtime/doc/eval.txt, src/eval.c, src/vim.h
17 *** ../vim-7.0.154/runtime/doc/eval.txt Tue Oct 3 14:43:31 2006
18 --- runtime/doc/eval.txt Wed Nov 1 15:20:42 2006
21 ! *eval.txt* For Vim version 7.0. Last change: 2006 Sep 22
24 VIM REFERENCE MANUAL by Bram Moolenaar
26 ! *eval.txt* For Vim version 7.0. Last change: 2006 Nov 01
29 VIM REFERENCE MANUAL by Bram Moolenaar
33 'guitabtooltip'. Only valid while one of these expressions is
34 being evaluated. Read-only when in the |sandbox|.
36 + *v:mouse_win* *mouse_win-variable*
37 + v:mouse_win Window number for a mouse click obtained with |getchar()|.
38 + First window has number 1, like with |winnr()|. The value is
39 + zero when there was no mouse button click.
41 + *v:mouse_lnum* *mouse_lnum-variable*
42 + v:mouse_lnum Line number for a mouse click obtained with |getchar()|.
43 + This is the text line number, not the screen line number. The
44 + value is zero when there was no mouse button click.
46 + *v:mouse_col* *mouse_col-variable*
47 + v:mouse_col Column number for a mouse click obtained with |getchar()|.
48 + This is the screen column number, like with |virtcol()|. The
49 + value is zero when there was no mouse button click.
51 *v:prevcount* *prevcount-variable*
52 v:prevcount The count given for the last but one Normal mode command.
53 This is the v:count value of the previous command. Useful if
57 one-byte character it is the character itself as a number.
58 Use nr2char() to convert it to a String.
60 + When the user clicks a mouse button, the mouse event will be
61 + returned. The position can then be found in |v:mouse_col|,
62 + |v:mouse_lnum| and |v:mouse_win|. This example positions the
63 + mouse as it would normally happen: >
65 + if c == "\<LeftMouse>" && v:mouse_win > 0
66 + exe v:mouse_win . "wincmd w"
68 + exe "normal " . v:mouse_col . "|"
71 There is no prompt, you will somehow have to make clear to the
72 user that a character has to be typed.
73 There is no mapping for the character.
74 *** ../vim-7.0.154/src/eval.c Tue Oct 24 13:51:47 2006
75 --- src/eval.c Wed Nov 1 13:39:52 2006
79 {VV_NAME("swapchoice", VAR_STRING), 0},
80 {VV_NAME("swapcommand", VAR_STRING), VV_RO},
81 {VV_NAME("char", VAR_STRING), VV_RO},
82 + {VV_NAME("mouse_win", VAR_NUMBER), 0},
83 + {VV_NAME("mouse_lnum", VAR_NUMBER), 0},
84 + {VV_NAME("mouse_col", VAR_NUMBER), 0},
94 + vimvars[VV_MOUSE_WIN].vv_nr = 0;
95 + vimvars[VV_MOUSE_LNUM].vv_nr = 0;
96 + vimvars[VV_MOUSE_COL].vv_nr = 0;
98 rettv->vval.v_number = n;
99 if (IS_SPECIAL(n) || mod_mask != 0)
105 rettv->v_type = VAR_STRING;
106 rettv->vval.v_string = vim_strsave(temp);
109 + if (n == K_LEFTMOUSE
110 + || n == K_LEFTMOUSE_NM
112 + || n == K_LEFTRELEASE
113 + || n == K_LEFTRELEASE_NM
114 + || n == K_MIDDLEMOUSE
115 + || n == K_MIDDLEDRAG
116 + || n == K_MIDDLERELEASE
117 + || n == K_RIGHTMOUSE
118 + || n == K_RIGHTDRAG
119 + || n == K_RIGHTRELEASE
122 + || n == K_X1RELEASE
125 + || n == K_X2RELEASE
126 + || n == K_MOUSEDOWN
129 + int row = mouse_row;
130 + int col = mouse_col;
133 + # ifdef FEAT_WINDOWS
138 + if (row >= 0 && col >= 0)
140 + /* Find the window at the mouse coordinates and compute the
141 + * text position. */
142 + win = mouse_find_win(&row, &col);
143 + (void)mouse_comp_pos(win, &row, &col, &lnum);
144 + # ifdef FEAT_WINDOWS
145 + for (wp = firstwin; wp != win; wp = wp->w_next)
148 + vimvars[VV_MOUSE_WIN].vv_nr = n;
149 + vimvars[VV_MOUSE_LNUM].vv_nr = lnum;
150 + vimvars[VV_MOUSE_COL].vv_nr = col + 1;
157 *** ../vim-7.0.154/src/vim.h Tue Aug 29 18:16:37 2006
158 --- src/vim.h Wed Nov 1 13:11:16 2006
161 #define VV_SWAPCHOICE 46
162 #define VV_SWAPCOMMAND 47
164 ! #define VV_LEN 49 /* number of v: vars */
166 #ifdef FEAT_CLIPBOARD
169 #define VV_SWAPCHOICE 46
170 #define VV_SWAPCOMMAND 47
172 ! #define VV_MOUSE_WIN 49
173 ! #define VV_MOUSE_LNUM 50
174 ! #define VV_MOUSE_COL 51
175 ! #define VV_LEN 52 /* number of v: vars */
177 #ifdef FEAT_CLIPBOARD
179 *** ../vim-7.0.154/src/version.c Wed Nov 1 12:43:07 2006
180 --- src/version.c Wed Nov 1 15:22:33 2006
184 { /* Add new patch number below this line */
190 hundred-and-one symptoms of being an internet addict:
191 138. You develop a liking for cold coffee.
193 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
194 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
195 \\\ download, build and distribute -- http://www.A-A-P.org ///
196 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///