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"
|
|
|
|
#include "display.h"
|
2013-10-09 01:43:32 -04:00
|
|
|
#include "estruct.h"
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Fancy quit command, as implemented by Norm. If the any buffer has
|
|
|
|
* changed do a write on that buffer and exit emacs, otherwise simply exit.
|
|
|
|
*/
|
|
|
|
int quickexit(int f, int n)
|
|
|
|
{
|
|
|
|
struct buffer *bp; /* scanning pointer to buffers */
|
|
|
|
struct buffer *oldcb; /* original current buffer */
|
|
|
|
int status;
|
|
|
|
|
|
|
|
oldcb = curbp; /* save in case we fail */
|
|
|
|
|
|
|
|
bp = bheadp;
|
|
|
|
while (bp != NULL) {
|
|
|
|
if ((bp->b_flag & BFCHG) != 0 /* Changed. */
|
|
|
|
&& (bp->b_flag & BFTRUNC) == 0 /* Not truncated P.K. */
|
|
|
|
&& (bp->b_flag & BFINVS) == 0) { /* Real. */
|
|
|
|
curbp = bp; /* make that buffer cur */
|
2015-02-13 08:48:05 -05:00
|
|
|
mloutfmt( "(Saving %s)", bp->b_fname) ;
|
2013-06-04 23:48:40 -04:00
|
|
|
#if PKCODE
|
|
|
|
#else
|
2015-02-13 08:48:05 -05:00
|
|
|
mloutstr( "\n") ;
|
2013-06-04 23:48:40 -04:00
|
|
|
#endif
|
|
|
|
if ((status = filesave(f, n)) != TRUE) {
|
|
|
|
curbp = oldcb; /* restore curbp */
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bp = bp->b_bufp; /* on to the next buffer */
|
|
|
|
}
|
|
|
|
quit(f, n); /* conditionally quit */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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".
|
|
|
|
*/
|
|
|
|
int quit(int f, int n)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
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();
|
2015-01-29 08:35:47 -05:00
|
|
|
exit( EXIT_FAILURE) ;
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
vttidy();
|
|
|
|
if (f)
|
|
|
|
exit(n);
|
|
|
|
else
|
2015-01-29 08:35:47 -05:00
|
|
|
exit( EXIT_SUCCESS) ;
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
2015-02-13 08:48:05 -05:00
|
|
|
mloutstr( "") ;
|
2013-06-04 23:48:40 -04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Begin a keyboard macro.
|
|
|
|
* Error if not at the top level in keyboard processing. Set up variables and
|
|
|
|
* return.
|
|
|
|
*/
|
|
|
|
int ctlxlp(int f, int n)
|
|
|
|
{
|
|
|
|
if (kbdmode != STOP) {
|
2015-02-13 08:48:05 -05:00
|
|
|
mloutstr( "%Macro already active") ;
|
2013-06-04 23:48:40 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-13 08:48:05 -05:00
|
|
|
mloutstr( "(Start macro)") ;
|
2013-06-04 23:48:40 -04:00
|
|
|
kbdptr = &kbdm[0];
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
int ctlxrp(int f, int n)
|
|
|
|
{
|
|
|
|
if (kbdmode == STOP) {
|
2015-02-13 08:48:05 -05:00
|
|
|
mloutstr( "%Macro not active") ;
|
2013-06-04 23:48:40 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (kbdmode == RECORD) {
|
2015-02-13 08:48:05 -05:00
|
|
|
mloutstr( "(End macro)") ;
|
2013-06-04 23:48:40 -04:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
int ctlxe(int f, int n)
|
|
|
|
{
|
|
|
|
if (kbdmode != STOP) {
|
2015-02-13 08:48:05 -05:00
|
|
|
mloutstr( "%Macro already active") ;
|
2013-06-04 23:48:40 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (n <= 0)
|
|
|
|
return TRUE;
|
|
|
|
kbdrep = n; /* remember how many times to execute */
|
|
|
|
kbdmode = PLAY; /* start us in play mode */
|
|
|
|
kbdptr = &kbdm[0]; /* at the beginning */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-07-23 20:58:23 -04:00
|
|
|
* 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.
|
2013-06-04 23:48:40 -04:00
|
|
|
*/
|
2015-01-20 09:34:28 -05:00
|
|
|
int ctrlg( int f, int n) {
|
|
|
|
kbdmode = STOP ;
|
2015-02-12 23:31:59 -05:00
|
|
|
mloutfmt( "%B(Aborted)") ;
|
2015-01-21 08:30:01 -05:00
|
|
|
return ABORT ;
|
2013-06-04 23:48:40 -04:00
|
|
|
}
|
|
|
|
|
2021-07-23 20:58:23 -04:00
|
|
|
/* end of bindable.c */
|