/* Simple built-in editing commands.
Copyright (C) 1985, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002,
- 2003, 2004, 2005, 2006, 2007, 2008
+ 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
+#include <setjmp.h>
#include "lisp.h"
#include "commands.h"
#include "buffer.h"
#include "keyboard.h"
#include "keymap.h"
#include "dispextern.h"
+#include "frame.h"
Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function;
/* This is the command that set up Vself_insert_face. */
Lisp_Object Vself_insert_face_command;
-extern Lisp_Object Qface;
-extern Lisp_Object Vtranslation_table_for_input;
+static int internal_self_insert (int, int);
\f
DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0,
doc: /* Return buffer position N characters after (before if N negative) point. */)
- (n)
- Lisp_Object n;
+ (Lisp_Object n)
{
CHECK_NUMBER (n);
}
DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "^p",
- doc: /* Move point right N characters (left if N is negative).
-On reaching end of buffer, stop and signal error. */)
- (n)
- Lisp_Object n;
+ doc: /* Move point N characters forward (backward if N is negative).
+On reaching end or beginning of buffer, stop and signal error.
+
+Depending on the bidirectional context, the movement may be to the
+right or to the left on the screen. This is in contrast with
+\\[right-char], which see. */)
+ (Lisp_Object n)
{
if (NILP (n))
XSETFASTINT (n, 1);
}
DEFUN ("backward-char", Fbackward_char, Sbackward_char, 0, 1, "^p",
- doc: /* Move point left N characters (right if N is negative).
-On attempt to pass beginning or end of buffer, stop and signal error. */)
- (n)
- Lisp_Object n;
+ doc: /* Move point N characters backward (forward if N is negative).
+On attempt to pass beginning or end of buffer, stop and signal error.
+
+Depending on the bidirectional context, the movement may be to the
+right or to the left on the screen. This is in contrast with
+\\[left-char], which see. */)
+ (Lisp_Object n)
{
if (NILP (n))
XSETFASTINT (n, 1);
DEFUN ("forward-line", Fforward_line, Sforward_line, 0, 1, "^p",
doc: /* Move N lines forward (backward if N is negative).
-Precisely, if point is on line I, move to the start of line I + N.
+Precisely, if point is on line I, move to the start of line I + N
+\("start of line" in the logical order).
If there isn't room, go as far as possible (no error).
Returns the count of lines left to move. If moving forward,
that is N - number of lines moved; if backward, N + number moved.
With positive N, a non-empty line at the end counts as one line
- successfully moved (for the return value). */)
- (n)
- Lisp_Object n;
+successfully moved (for the return value). */)
+ (Lisp_Object n)
{
int opoint = PT, opoint_byte = PT_BYTE;
int pos, pos_byte;
}
DEFUN ("beginning-of-line", Fbeginning_of_line, Sbeginning_of_line, 0, 1, "^p",
- doc: /* Move point to beginning of current line.
+ doc: /* Move point to beginning of current line (in the logical order).
With argument N not nil or 1, move forward N - 1 lines first.
If point reaches the beginning or end of buffer, it stops there.
This function constrains point to the current field unless this moves
-point to a different line than the original, unconstrained result. If
-N is nil or 1, and a front-sticky field starts at point, the point
+point to a different line than the original, unconstrained result.
+If N is nil or 1, and a front-sticky field starts at point, the point
does not move. To ignore field boundaries bind
`inhibit-field-text-motion' to t, or use the `forward-line' function
instead. For instance, `(forward-line 0)' does the same thing as
`(beginning-of-line)', except that it ignores field boundaries. */)
- (n)
- Lisp_Object n;
+ (Lisp_Object n)
{
if (NILP (n))
XSETFASTINT (n, 1);
}
DEFUN ("end-of-line", Fend_of_line, Send_of_line, 0, 1, "^p",
- doc: /* Move point to end of current line.
+ doc: /* Move point to end of current line (in the logical order).
With argument N not nil or 1, move forward N - 1 lines first.
If point reaches the beginning or end of buffer, it stops there.
To ignore intangibility, bind `inhibit-point-motion-hooks' to t.
N is nil or 1, and a rear-sticky field ends at point, the point does
not move. To ignore field boundaries bind `inhibit-field-text-motion'
to t. */)
- (n)
- Lisp_Object n;
+ (Lisp_Object n)
{
int newpos;
doc: /* Delete the following N characters (previous if N is negative).
Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
Interactively, N is the prefix arg, and KILLFLAG is set if
-N was explicitly specified. */)
- (n, killflag)
- Lisp_Object n, killflag;
+N was explicitly specified.
+
+The command `delete-forward' is preferable for interactive use. */)
+ (Lisp_Object n, Lisp_Object killflag)
{
int pos;
return Qnil;
}
-DEFUN ("delete-backward-char", Fdelete_backward_char, Sdelete_backward_char,
- 1, 2, "p\nP",
- doc: /* Delete the previous N characters (following if N is negative).
-Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
-Interactively, N is the prefix arg, and KILLFLAG is set if
-N was explicitly specified. */)
- (n, killflag)
- Lisp_Object n, killflag;
-{
- Lisp_Object value;
- int deleted_special = 0;
- int pos, pos_byte, i;
+static int nonundocount;
+/* Note that there's code in command_loop_1 which typically avoids
+ calling this. */
+DEFUN ("self-insert-command", Fself_insert_command, Sself_insert_command, 1, 1, "p",
+ doc: /* Insert the character you type.
+Whichever character you type to run this command is inserted.
+Before insertion, `expand-abbrev' is executed if the inserted character does
+not have word syntax and the previous character in the buffer does.
+After insertion, the value of `auto-fill-function' is called if the
+`auto-fill-chars' table has a non-nil value for the inserted character. */)
+ (Lisp_Object n)
+{
+ int remove_boundary = 1;
CHECK_NUMBER (n);
- /* See if we are about to delete a tab or newline backwards. */
- pos = PT;
- pos_byte = PT_BYTE;
- for (i = 0; i < XINT (n) && pos_byte > BEGV_BYTE; i++)
- {
- int c;
+ if (!EQ (Vthis_command, current_kboard->Vlast_command))
+ nonundocount = 0;
- DEC_BOTH (pos, pos_byte);
- c = FETCH_BYTE (pos_byte);
- if (c == '\t' || c == '\n')
+ if (NILP (Vexecuting_kbd_macro)
+ && !EQ (minibuf_window, selected_window))
+ {
+ if (nonundocount <= 0 || nonundocount >= 20)
{
- deleted_special = 1;
- break;
+ remove_boundary = 0;
+ nonundocount = 0;
}
+ nonundocount++;
}
- /* In overwrite mode, back over columns while clearing them out,
- unless at end of line. */
- if (XINT (n) > 0
- && ! NILP (current_buffer->overwrite_mode)
- && ! deleted_special
- && ! (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n'))
- {
- int column = (int) current_column (); /* iftc */
-
- value = Fdelete_char (make_number (-XINT (n)), killflag);
- i = column - (int) current_column (); /* iftc */
- Finsert_char (make_number (' '), make_number (i), Qnil);
- /* Whitespace chars are ASCII chars, so we can simply subtract. */
- SET_PT_BOTH (PT - i, PT_BYTE - i);
- }
- else
- value = Fdelete_char (make_number (-XINT (n)), killflag);
-
- return value;
-}
-
-/* Note that there's code in command_loop_1 which typically avoids
- calling this. */
-DEFUN ("self-insert-command", Fself_insert_command, Sself_insert_command, 1, 1, "p",
- doc: /* Insert the character you type.
-Whichever character you type to run this command is inserted. */)
- (n)
- Lisp_Object n;
-{
- CHECK_NUMBER (n);
+ if (remove_boundary
+ && CONSP (current_buffer->undo_list)
+ && NILP (XCAR (current_buffer->undo_list)))
+ /* Remove the undo_boundary that was just pushed. */
+ current_buffer->undo_list = XCDR (current_buffer->undo_list);
/* Barf if the key that invoked this was not a character. */
- if (!CHARACTERP (last_command_char))
+ if (!CHARACTERP (last_command_event))
bitch_at_user ();
{
int character = translate_char (Vtranslation_table_for_input,
- XINT (last_command_char));
+ XINT (last_command_event));
if (XINT (n) >= 2 && NILP (current_buffer->overwrite_mode))
{
- int modified_char = character;
- /* Add the offset to the character, for Finsert_char.
- We pass internal_self_insert the unmodified character
- because it itself does this offsetting. */
- if (! NILP (current_buffer->enable_multibyte_characters))
- modified_char = unibyte_char_to_multibyte (modified_char);
-
XSETFASTINT (n, XFASTINT (n) - 2);
/* The first one might want to expand an abbrev. */
internal_self_insert (character, 1);
/* The bulk of the copies of this char can be inserted simply.
We don't have to handle a user-specified face specially
because it will get inherited from the first char inserted. */
- Finsert_char (make_number (modified_char), n, Qt);
+ Finsert_char (make_number (character), n, Qt);
/* The last one might want to auto-fill. */
internal_self_insert (character, 0);
}
else
while (XINT (n) > 0)
{
+ int val;
/* Ok since old and new vals both nonneg */
XSETFASTINT (n, XFASTINT (n) - 1);
- internal_self_insert (character, XFASTINT (n) != 0);
+ val = internal_self_insert (character, XFASTINT (n) != 0);
+ if (val == 2)
+ nonundocount = 0;
+ frame_make_pointer_invisible ();
}
}
static Lisp_Object Qexpand_abbrev;
-int
-internal_self_insert (c, noautofill)
- int c;
- int noautofill;
+static int
+internal_self_insert (int c, int noautofill)
{
int hairy = 0;
Lisp_Object tem;
hairy = 2;
}
- if (NILP (current_buffer->enable_multibyte_characters))
- MAKE_CHAR_MULTIBYTE (c);
synt = SYNTAX (c);
if (!NILP (current_buffer->abbrev_mode)
&& PT > BEGV
&& (!NILP (current_buffer->enable_multibyte_characters)
? SYNTAX (XFASTINT (Fprevious_char ())) == Sword
- : (SYNTAX (unibyte_char_to_multibyte (XFASTINT (Fprevious_char ())))
+ : (SYNTAX (UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ())))
== Sword)))
{
int modiff = MODIFF;
/* If we expanded an abbrev which has a hook,
and the hook has a non-nil `no-self-insert' property,
return right away--don't really self-insert. */
- if (! NILP (sym) && ! NILP (XSYMBOL (sym)->function)
+ if (SYMBOLP (sym) && ! NILP (sym) && ! NILP (XSYMBOL (sym)->function)
&& SYMBOLP (XSYMBOL (sym)->function))
{
Lisp_Object prop;
/* module initialization */
void
-syms_of_cmds ()
+syms_of_cmds (void)
{
- Qkill_backward_chars = intern ("kill-backward-chars");
+ Qkill_backward_chars = intern_c_string ("kill-backward-chars");
staticpro (&Qkill_backward_chars);
- Qkill_forward_chars = intern ("kill-forward-chars");
+ Qkill_forward_chars = intern_c_string ("kill-forward-chars");
staticpro (&Qkill_forward_chars);
- Qoverwrite_mode_binary = intern ("overwrite-mode-binary");
+ Qoverwrite_mode_binary = intern_c_string ("overwrite-mode-binary");
staticpro (&Qoverwrite_mode_binary);
- Qexpand_abbrev = intern ("expand-abbrev");
+ Qexpand_abbrev = intern_c_string ("expand-abbrev");
staticpro (&Qexpand_abbrev);
DEFVAR_LISP ("self-insert-face", &Vself_insert_face,
defsubr (&Send_of_line);
defsubr (&Sdelete_char);
- defsubr (&Sdelete_backward_char);
-
defsubr (&Sself_insert_command);
}
void
-keys_of_cmds ()
+keys_of_cmds (void)
{
int n;
+ nonundocount = 0;
initial_define_key (global_map, Ctl ('I'), "self-insert-command");
for (n = 040; n < 0177; n++)
initial_define_key (global_map, n, "self-insert-command");
initial_define_key (global_map, Ctl ('A'), "beginning-of-line");
initial_define_key (global_map, Ctl ('B'), "backward-char");
- initial_define_key (global_map, Ctl ('D'), "delete-char");
initial_define_key (global_map, Ctl ('E'), "end-of-line");
initial_define_key (global_map, Ctl ('F'), "forward-char");
- initial_define_key (global_map, 0177, "delete-backward-char");
}
/* arch-tag: 022ba3cd-67f9-4978-9c5d-7d2b18d8644e