2021-07-23 20:58:23 -04:00
|
|
|
/* bindable.c -- implements bindable.h */
|
2013-06-04 23:48:40 -04:00
|
|
|
#include "bindable.h"
|
|
|
|
|
2013-10-08 21:43:15 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-09-20 06:10:30 -04:00
|
|
|
#include "defines.h"
|
2013-06-04 23:48:40 -04:00
|
|
|
#include "buffer.h"
|
2021-08-09 03:45:01 -04:00
|
|
|
#include "display.h" /* vttidy() */
|
2013-06-04 23:48:40 -04:00
|
|
|
#include "file.h"
|
|
|
|
#include "input.h"
|
2013-09-20 22:24:45 -04:00
|
|
|
#include "lock.h"
|
2015-02-12 23:31:59 -05:00
|
|
|
#include "mlout.h"
|
2013-09-25 09:45:05 -04:00
|
|
|
#include "terminal.h"
|
2013-06-04 23:48:40 -04:00
|
|
|
|
2021-08-09 03:45:01 -04:00
|
|
|
|
|
|
|
/* Fancy quit command, as implemented by Norm. If any buffer has changed
|
|
|
|
do a write on that buffer and exit emacs, otherwise simply exit.
|
2013-06-04 23:48:40 -04:00
|
|
|
*/
|
2021-08-09 03:45:01 -04:00
|
|
|
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 */
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:45:01 -04:00
|
|
|
|
|
|
|
/* Quit command. If an argument, always quit. Otherwise confirm if a buffer
|
2013-06-04 23:48:40 -04:00
|
|
|
* has been changed and not written out. Normally bound to "C-X C-C".
|
|
|
|
*/
|
2021-08-09 03:45:01 -04:00
|
|
|
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) ;
|
|
|
|
}
|
2013-06-04 23:48:40 -04:00
|
|
|
#endif
|
2021-08-09 03:45:01 -04:00
|
|
|
vttidy() ;
|
|
|
|
if( f)
|
|
|
|
exit( n) ;
|
|
|
|
else
|
|
|
|
exit( EXIT_SUCCESS) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
mloutstr( "") ;
|
|
|
|
return s ;
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:45:01 -04:00
|
|
|
|
|
|
|
/* Begin a keyboard macro.
|
2013-06-04 23:48:40 -04:00
|
|
|
* Error if not at the top level in keyboard processing. Set up variables and
|
|
|
|
* return.
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BBINDABLE( ctlxlp) {
|
2021-08-09 03:45:01 -04:00
|
|
|
if( kbdmode != STOP)
|
|
|
|
return mloutfail( "%Macro already active") ;
|
|
|
|
|
|
|
|
mloutstr( "(Start macro)") ;
|
|
|
|
kbdptr = kbdm ;
|
|
|
|
kbdend = kbdptr ;
|
|
|
|
kbdmode = RECORD ;
|
|
|
|
return TRUE ;
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:45:01 -04:00
|
|
|
|
|
|
|
/* End keyboard macro. Check for the same limit conditions as the above
|
2013-06-04 23:48:40 -04:00
|
|
|
* routine. Set up the variables and return to the caller.
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BBINDABLE( ctlxrp) {
|
2021-08-09 03:45:01 -04:00
|
|
|
if( kbdmode == STOP)
|
|
|
|
return mloutfail( "%Macro not active") ;
|
|
|
|
|
|
|
|
if (kbdmode == RECORD) {
|
|
|
|
mloutstr( "(End macro)") ;
|
|
|
|
kbdmode = STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE ;
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:45:01 -04:00
|
|
|
|
|
|
|
/* Execute a macro.
|
2013-06-04 23:48:40 -04:00
|
|
|
* 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.
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BBINDABLE( ctlxe) {
|
2021-08-09 03:45:01 -04:00
|
|
|
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 ;
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:45:01 -04:00
|
|
|
|
|
|
|
/* abort:
|
2021-07-23 20:58:23 -04:00
|
|
|
* Beep the beeper. Kill off any keyboard macro, etc., that is in progress.
|
|
|
|
* Sometimes called as a routine, to do general aborting of stuff.
|
2013-06-04 23:48:40 -04:00
|
|
|
*/
|
2021-08-09 03:45:01 -04:00
|
|
|
BINDABLE( ctrlg) {
|
|
|
|
kbdmode = STOP ;
|
|
|
|
mloutfmt( "%B(Aborted)") ;
|
|
|
|
return ABORT ;
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
|
|
|
|
2021-07-23 20:58:23 -04:00
|
|
|
/* end of bindable.c */
|