1 /* Cursor motion calculation definitions for GNU Emacs
2 Copyright (C) 1985, 1989, 2001-2012 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 /* Holds the minimum and maximum costs for the parameterized capabilities. */
25 /* This structure holds everything needed to do cursor motion except the pad
26 character (PC) and the output speed of the terminal (ospeed), which
27 termcap wants in global variables. */
31 /* Cursor position. -1 in *both* variables means the cursor
32 position is unknown, in order to force absolute cursor motion. */
34 int cm_curY
; /* Current row */
35 int cm_curX
; /* Current column */
37 /* Capabilities from termcap */
38 const char *cm_up
; /* up (up) */
39 const char *cm_down
; /* down (do) */
40 const char *cm_left
; /* left (le) */
41 const char *cm_right
; /* right (nd) */
42 const char *cm_home
; /* home (ho) */
43 const char *cm_cr
; /* carriage return (cr) */
44 const char *cm_ll
; /* last line (ll) */
45 const char *cm_tab
; /* tab (ta) */
46 const char *cm_backtab
; /* backtab (bt) */
47 char *cm_abs
; /* absolute (cm) */
48 const char *cm_habs
; /* horizontal absolute (ch) */
49 const char *cm_vabs
; /* vertical absolute (cv) */
51 const char *cm_ds
; /* "don't send" string (ds) */
53 const char *cm_multiup
; /* multiple up (UP) */
54 const char *cm_multidown
; /* multiple down (DO) */
55 const char *cm_multileft
; /* multiple left (LE) */
56 const char *cm_multiright
; /* multiple right (RI) */
57 int cm_cols
; /* number of cols on screen (co) */
58 int cm_rows
; /* number of rows on screen (li) */
59 int cm_tabwidth
; /* tab width (it) */
60 unsigned int cm_autowrap
:1; /* autowrap flag (am) */
61 unsigned int cm_magicwrap
:1; /* VT-100: cursor stays in last col but
62 will cm_wrap if next char is
64 unsigned int cm_usetabs
:1; /* if set, use tabs */
65 unsigned int cm_losewrap
:1; /* if reach right margin, forget cursor
67 unsigned int cm_autolf
:1; /* \r performs a \r\n (rn) */
69 /* Parameterized capabilities. This needs to be a struct since
70 the costs are accessed through pointers. */
73 struct parmcap cc_abs
; /* absolute (cm) */
74 struct parmcap cc_habs
; /* horizontal absolute (ch) */
75 struct parmcap cc_vabs
; /* vertical absolute (cv) */
76 struct parmcap cc_multiup
; /* multiple up (UP) */
77 struct parmcap cc_multidown
; /* multiple down (DO) */
78 struct parmcap cc_multileft
; /* multiple left (LE) */
79 struct parmcap cc_multiright
; /* multiple right (RI) */
82 /* Costs for the non-parameterized capabilities */
83 int cc_up
; /* cost for up */
84 int cc_down
; /* etc. */
92 /* These are temporary, until the code is installed to use the
93 struct parmcap fields above. */
100 #ifndef NoCMShortHand
101 #define curY(tty) (tty)->Wcm->cm_curY
102 #define curX(tty) (tty)->Wcm->cm_curX
103 #define Up(tty) (tty)->Wcm->cm_up
104 #define Down(tty) (tty)->Wcm->cm_down
105 #define Left(tty) (tty)->Wcm->cm_left
106 #define Right(tty) (tty)->Wcm->cm_right
107 #define Tab(tty) (tty)->Wcm->cm_tab
108 #define BackTab(tty) (tty)->Wcm->cm_backtab
109 #define TabWidth(tty) (tty)->Wcm->cm_tabwidth
110 #define CR(tty) (tty)->Wcm->cm_cr
111 #define Home(tty) (tty)->Wcm->cm_home
112 #define LastLine(tty) (tty)->Wcm->cm_ll
113 #define AbsPosition(tty) (tty)->Wcm->cm_abs
114 #define ColPosition(tty) (tty)->Wcm->cm_habs
115 #define RowPosition(tty) (tty)->Wcm->cm_vabs
116 #define MultiUp(tty) (tty)->Wcm->cm_multiup
117 #define MultiDown(tty) (tty)->Wcm->cm_multidown
118 #define MultiLeft(tty) (tty)->Wcm->cm_multileft
119 #define MultiRight(tty) (tty)->Wcm->cm_multiright
120 #define AutoWrap(tty) (tty)->Wcm->cm_autowrap
121 #define MagicWrap(tty) (tty)->Wcm->cm_magicwrap
122 #define UseTabs(tty) (tty)->Wcm->cm_usetabs
123 #define FrameRows(tty) (tty)->Wcm->cm_rows
124 #define FrameCols(tty) (tty)->Wcm->cm_cols
126 #define UpCost(tty) (tty)->Wcm->cc_up
127 #define DownCost(tty) (tty)->Wcm->cc_down
128 #define LeftCost(tty) (tty)->Wcm->cc_left
129 #define RightCost(tty) (tty)->Wcm->cc_right
130 #define HomeCost(tty) (tty)->Wcm->cc_home
131 #define CRCost(tty) (tty)->Wcm->cc_cr
132 #define LastLineCost(tty) (tty)->Wcm->cc_ll
133 #define TabCost(tty) (tty)->Wcm->cc_tab
134 #define BackTabCost(tty) (tty)->Wcm->cc_backtab
135 #define AbsPositionCost(tty) (tty)->Wcm->cc_abs
136 #define ColPositionCost(tty) (tty)->Wcm->cc_habs
137 #define RowPositionCost(tty) (tty)->Wcm->cc_vabs
138 #define MultiUpCost(tty) (tty)->Wcm->cc_multiup
139 #define MultiDownCost(tty) (tty)->Wcm->cc_multidown
140 #define MultiLeftCost(tty) (tty)->Wcm->cc_multileft
141 #define MultiRightCost(tty) (tty)->Wcm->cc_multiright
144 #define cmat(tty,row,col) (curY(tty) = (row), curX(tty) = (col))
145 #define cmplus(tty,n) \
147 if ((curX (tty) += (n)) >= FrameCols (tty) && !MagicWrap (tty)) \
149 if ((tty)->Wcm->cm_losewrap) losecursor (tty); \
150 else if (AutoWrap (tty)) curX (tty) = 0, curY (tty)++; \
155 #define losecursor(tty) (curX(tty) = -1, curY(tty) = -1)
158 extern int evalcost (int c
);
160 #define emacs_tputs(tty, str, affcnt, putc) (current_tty = (tty), tputs (str, affcnt, putc))
162 extern struct tty_display_info
*current_tty
;
163 extern void cmcheckmagic (struct tty_display_info
*);
164 extern int cmputc (int);
165 extern void cmcostinit (struct tty_display_info
*);
166 extern void cmgoto (struct tty_display_info
*, int, int);
167 extern void Wcm_clear (struct tty_display_info
*);
168 extern int Wcm_init (struct tty_display_info
*);