Merge from emacs-23; up to 2010-06-01T01:49:15Z!monnier@iro.umontreal.ca
[bpt/emacs.git] / src / cm.h
CommitLineData
9889c728 1/* Cursor motion calculation definitions for GNU Emacs
73b0cd50 2 Copyright (C) 1985, 1989, 2001-2011 Free Software Foundation, Inc.
9889c728
JB
3
4This file is part of GNU Emacs.
5
b9b1cc14 6GNU Emacs is free software: you can redistribute it and/or modify
9889c728 7it under the terms of the GNU General Public License as published by
b9b1cc14
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
9889c728
JB
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
b9b1cc14 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
9889c728
JB
18
19/* Holds the minimum and maximum costs for the parametrized capabilities. */
20struct parmcap
21 {
22 int mincost, maxcost;
23 };
24
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. */
28
29struct cm
30 {
31 /* Cursor position. -1 in *both* variables means the cursor
32 position is unknown, in order to force absolute cursor motion. */
33
34 int cm_curY; /* Current row */
35 int cm_curX; /* Current column */
36
37 /* Capabilities from termcap */
38 char *cm_up; /* up (up) */
39 char *cm_down; /* down (do) */
40 char *cm_left; /* left (le) */
41 char *cm_right; /* right (nd) */
42 char *cm_home; /* home (ho) */
43 char *cm_cr; /* carriage return (cr) */
44 char *cm_ll; /* last line (ll) */
45 char *cm_tab; /* tab (ta) */
46 char *cm_backtab; /* backtab (bt) */
47 char *cm_abs; /* absolute (cm) */
48 char *cm_habs; /* horizontal absolute (ch) */
49 char *cm_vabs; /* vertical absolute (cv) */
50#if 0
51 char *cm_ds; /* "don't send" string (ds) */
52#endif
53 char *cm_multiup; /* multiple up (UP) */
54 char *cm_multidown; /* multiple down (DO) */
55 char *cm_multileft; /* multiple left (LE) */
56 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
63 printing (xn) */
64 unsigned int cm_usetabs:1; /* if set, use tabs */
65 unsigned int cm_losewrap:1; /* if reach right margin, forget cursor
66 location */
67 unsigned int cm_autolf:1; /* \r performs a \r\n (rn) */
68
69 /* Parametrized capabilities. This needs to be a struct since
70 the costs are accessed through pointers. */
71
72#if 0
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) */
80#endif
81
82 /* Costs for the non-parametrized capabilities */
83 int cc_up; /* cost for up */
84 int cc_down; /* etc. */
85 int cc_left;
86 int cc_right;
87 int cc_home;
88 int cc_cr;
89 int cc_ll;
90 int cc_tab;
91 int cc_backtab;
92 /* These are temporary, until the code is installed to use the
93 struct parmcap fields above. */
94 int cc_abs;
95 int cc_habs;
96 int cc_vabs;
97 };
98
9889c728 99extern char PC; /* Pad character */
0dc57298 100
9889c728
JB
101/* Shorthand */
102#ifndef NoCMShortHand
6548cf00
KL
103#define curY(tty) (tty)->Wcm->cm_curY
104#define curX(tty) (tty)->Wcm->cm_curX
105#define Up(tty) (tty)->Wcm->cm_up
106#define Down(tty) (tty)->Wcm->cm_down
107#define Left(tty) (tty)->Wcm->cm_left
108#define Right(tty) (tty)->Wcm->cm_right
109#define Tab(tty) (tty)->Wcm->cm_tab
110#define BackTab(tty) (tty)->Wcm->cm_backtab
111#define TabWidth(tty) (tty)->Wcm->cm_tabwidth
112#define CR(tty) (tty)->Wcm->cm_cr
113#define Home(tty) (tty)->Wcm->cm_home
114#define LastLine(tty) (tty)->Wcm->cm_ll
115#define AbsPosition(tty) (tty)->Wcm->cm_abs
116#define ColPosition(tty) (tty)->Wcm->cm_habs
117#define RowPosition(tty) (tty)->Wcm->cm_vabs
118#define MultiUp(tty) (tty)->Wcm->cm_multiup
119#define MultiDown(tty) (tty)->Wcm->cm_multidown
120#define MultiLeft(tty) (tty)->Wcm->cm_multileft
121#define MultiRight(tty) (tty)->Wcm->cm_multiright
122#define AutoWrap(tty) (tty)->Wcm->cm_autowrap
123#define MagicWrap(tty) (tty)->Wcm->cm_magicwrap
124#define UseTabs(tty) (tty)->Wcm->cm_usetabs
125#define FrameRows(tty) (tty)->Wcm->cm_rows
126#define FrameCols(tty) (tty)->Wcm->cm_cols
127
128#define UpCost(tty) (tty)->Wcm->cc_up
129#define DownCost(tty) (tty)->Wcm->cc_down
130#define LeftCost(tty) (tty)->Wcm->cc_left
131#define RightCost(tty) (tty)->Wcm->cc_right
132#define HomeCost(tty) (tty)->Wcm->cc_home
133#define CRCost(tty) (tty)->Wcm->cc_cr
134#define LastLineCost(tty) (tty)->Wcm->cc_ll
135#define TabCost(tty) (tty)->Wcm->cc_tab
136#define BackTabCost(tty) (tty)->Wcm->cc_backtab
137#define AbsPositionCost(tty) (tty)->Wcm->cc_abs
138#define ColPositionCost(tty) (tty)->Wcm->cc_habs
139#define RowPositionCost(tty) (tty)->Wcm->cc_vabs
140#define MultiUpCost(tty) (tty)->Wcm->cc_multiup
141#define MultiDownCost(tty) (tty)->Wcm->cc_multidown
142#define MultiLeftCost(tty) (tty)->Wcm->cc_multileft
143#define MultiRightCost(tty) (tty)->Wcm->cc_multiright
9889c728
JB
144#endif
145
6548cf00
KL
146#define cmat(tty,row,col) (curY(tty) = (row), curX(tty) = (col))
147#define cmplus(tty,n) \
148 { \
149 if ((curX (tty) += (n)) >= FrameCols (tty) && !MagicWrap (tty)) \
150 { \
151 if ((tty)->Wcm->cm_losewrap) losecursor (tty); \
152 else if (AutoWrap (tty)) curX (tty) = 0, curY (tty)++; \
153 else curX (tty)--; \
154 } \
9889c728
JB
155 }
156
6548cf00 157#define losecursor(tty) (curX(tty) = -1, curY(tty) = -1)
9889c728
JB
158
159extern int cost;
3a35a84c 160extern int evalcost (int c);
9889c728 161
28d440ab
KL
162#define emacs_tputs(tty, str, affcnt, putc) (current_tty = (tty), tputs (str, affcnt, putc))
163
28d7d09f 164extern struct tty_display_info *current_tty;
383e0970
J
165extern void cmcheckmagic (struct tty_display_info *);
166extern int cmputc (int);
167extern void cmcostinit (struct tty_display_info *);
168extern void cmgoto (struct tty_display_info *, int, int);
169extern void Wcm_clear (struct tty_display_info *);
170extern int Wcm_init (struct tty_display_info *);
ab5796a9 171