-
Notifications
You must be signed in to change notification settings - Fork 7
/
bindable.c
129 lines (106 loc) · 3.21 KB
/
bindable.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* bindable.c -- implements bindable.h */
#include "bindable.h"
#include <stdlib.h>
#include "defines.h"
#include "buffer.h"
#include "display.h" /* vttidy() */
#include "file.h"
#include "input.h"
#include "lock.h"
#include "mlout.h"
#include "terminal.h"
/* Fancy quit command, as implemented by Norm. If any buffer has changed
do a write on that buffer and exit emacs, otherwise simply exit.
*/
BINDABLE( quickexit) {
buffer_p oldcb = curbp ; /* save in case we fail */
for( buffer_p bp = bheadp ; bp != NULL ; bp = bp->b_bufp) {
if( (bp->b_flag & (BFCHG | BFTRUNC | BFINVS)) == BFCHG) {
/* Changed, Not truncated and real buffer */
curbp = bp ; /* make that buffer cur */
mloutfmt( "(Saving %s)", bp->b_fname) ;
int status = filesave( f, n) ;
if( status != TRUE) {
curbp = oldcb ; /* restore curbp */
return status ;
}
}
}
return quit( f, n) ; /* conditionally quit */
}
/* Quit command. If an argument, always quit. Otherwise confirm if a buffer
* has been changed and not written out. Normally bound to "C-X C-C".
*/
BINDABLE( quit) {
int s ; /* status of user query */
if( f != FALSE /* Argument forces it. */
|| anycb() == FALSE /* All buffers clean. */
/* User says it's OK. */
|| (s = mlyesno( "Modified buffers exist. Leave anyway")) == TRUE) {
#if (FILOCK && BSD) || SVR4
if( lockrel() != TRUE) {
TTputc('\n') ;
TTputc('\r') ;
TTclose() ;
TTkclose() ;
exit( EXIT_FAILURE) ;
}
#endif
vttidy() ;
if( f)
exit( n) ;
else
exit( EXIT_SUCCESS) ;
}
mloutstr( "") ;
return s ;
}
/* Begin a keyboard macro.
* Error if not at the top level in keyboard processing. Set up variables and
* return.
*/
BBINDABLE( ctlxlp) {
if( kbdmode != STOP)
return mloutfail( "%Macro already active") ;
mloutstr( "(Start macro)") ;
kbdptr = kbdm ;
kbdend = kbdptr ;
kbdmode = RECORD ;
return TRUE ;
}
/* End keyboard macro. Check for the same limit conditions as the above
* routine. Set up the variables and return to the caller.
*/
BBINDABLE( ctlxrp) {
if( kbdmode == STOP)
return mloutfail( "%Macro not active") ;
if (kbdmode == RECORD) {
mloutstr( "(End macro)") ;
kbdmode = STOP;
}
return TRUE ;
}
/* Execute a macro.
* The command argument is the number of times to loop. Quit as soon as a
* command gets an error. Return TRUE if all ok, else FALSE.
*/
BBINDABLE( ctlxe) {
if( kbdmode != STOP)
return mloutfail( "%Macro already active") ;
if( n <= 0)
return TRUE ;
kbdrep = n ; /* remember how many times to execute */
kbdmode = PLAY ; /* start us in play mode */
kbdptr = kbdm ; /* at the beginning */
return TRUE ;
}
/* abort:
* Beep the beeper. Kill off any keyboard macro, etc., that is in progress.
* Sometimes called as a routine, to do general aborting of stuff.
*/
BINDABLE( ctrlg) {
kbdmode = STOP ;
mloutfmt( "%B(Aborted)") ;
return ABORT ;
}
/* end of bindable.c */