]> code.delx.au - gnu-emacs/blobdiff - src/macros.c
Ibuffer: Mark locked buffers
[gnu-emacs] / src / macros.c
index 6d924f6c0806c0863207b9d5fe3c892a8fa1f711..0c703ba1a1f1d4fce234f50ade640519e5c099cc 100644 (file)
@@ -1,13 +1,13 @@
 /* Keyboard macros.
 
-Copyright (C) 1985-1986, 1993, 2000-2015 Free Software Foundation, Inc.
+Copyright (C) 1985-1986, 1993, 2000-2016 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,15 +22,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "lisp.h"
 #include "macros.h"
-#include "commands.h"
-#include "character.h"
-#include "buffer.h"
 #include "window.h"
 #include "keyboard.h"
 
-static Lisp_Object Qexecute_kbd_macro;
-static Lisp_Object Qkbd_macro_termination_hook;
-
 /* Number of successful iterations so far
    for innermost keyboard macro.
    This is not bound at each level,
@@ -45,8 +39,6 @@ EMACS_INT executing_kbd_macro_iterations;
 
 Lisp_Object executing_kbd_macro;
 
-Lisp_Object Fexecute_kbd_macro (Lisp_Object macro, Lisp_Object count, Lisp_Object loopfunc);
-\f
 DEFUN ("start-kbd-macro", Fstart_kbd_macro, Sstart_kbd_macro, 1, 2, "P",
        doc: /* Record subsequent keyboard input, defining a keyboard macro.
 The commands are recorded even as they are executed.
@@ -84,28 +76,21 @@ macro before appending to it.  */)
     }
   else
     {
-      ptrdiff_t i;
-      EMACS_INT len;
+      int incr = 30;
+      ptrdiff_t i, len;
       bool cvt;
 
       /* Check the type of last-kbd-macro in case Lisp code changed it.  */
-      CHECK_VECTOR_OR_STRING (KVAR (current_kboard, Vlast_kbd_macro));
-
-      len = XINT (Flength (KVAR (current_kboard, Vlast_kbd_macro)));
+      len = CHECK_VECTOR_OR_STRING (KVAR (current_kboard, Vlast_kbd_macro));
 
       /* Copy last-kbd-macro into the buffer, in case the Lisp code
         has put another macro there.  */
-      if (current_kboard->kbd_macro_bufsize < len + 30)
-       {
-         if (PTRDIFF_MAX < MOST_POSITIVE_FIXNUM + 30
-             && PTRDIFF_MAX < len + 30)
-           memory_full (SIZE_MAX);
-         current_kboard->kbd_macro_buffer =
-           xpalloc (current_kboard->kbd_macro_buffer,
-                    &current_kboard->kbd_macro_bufsize,
-                    len + 30 - current_kboard->kbd_macro_bufsize, -1,
-                    sizeof *current_kboard->kbd_macro_buffer);
-       }
+      if (current_kboard->kbd_macro_bufsize - incr < len)
+       current_kboard->kbd_macro_buffer =
+         xpalloc (current_kboard->kbd_macro_buffer,
+                  &current_kboard->kbd_macro_bufsize,
+                  len - current_kboard->kbd_macro_bufsize + incr, -1,
+                  sizeof *current_kboard->kbd_macro_buffer);
 
       /* Must convert meta modifier when copying string to vector.  */
       cvt = STRINGP (KVAR (current_kboard, Vlast_kbd_macro));
@@ -199,16 +184,11 @@ store_kbd_macro_char (Lisp_Object c)
     {
       if (kb->kbd_macro_ptr - kb->kbd_macro_buffer == kb->kbd_macro_bufsize)
        {
-         ptrdiff_t ptr_offset, end_offset, nbytes;
-
-         ptr_offset = kb->kbd_macro_ptr - kb->kbd_macro_buffer;
-         end_offset = kb->kbd_macro_end - kb->kbd_macro_buffer;
-         if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *kb->kbd_macro_buffer / 2
-             < kb->kbd_macro_bufsize)
-           memory_full (SIZE_MAX);
-         nbytes = kb->kbd_macro_bufsize * (2 * sizeof *kb->kbd_macro_buffer);
-         kb->kbd_macro_buffer = xrealloc (kb->kbd_macro_buffer, nbytes);
-         kb->kbd_macro_bufsize *= 2;
+         ptrdiff_t ptr_offset = kb->kbd_macro_ptr - kb->kbd_macro_buffer;
+         ptrdiff_t end_offset = kb->kbd_macro_end - kb->kbd_macro_buffer;
+         kb->kbd_macro_buffer = xpalloc (kb->kbd_macro_buffer,
+                                         &kb->kbd_macro_bufsize,
+                                         1, -1, sizeof *kb->kbd_macro_buffer);
          kb->kbd_macro_ptr = kb->kbd_macro_buffer + ptr_offset;
          kb->kbd_macro_end = kb->kbd_macro_buffer + end_offset;
        }
@@ -289,7 +269,7 @@ pop_kbd_macro (Lisp_Object info)
   tem = XCDR (info);
   executing_kbd_macro_index = XINT (XCAR (tem));
   Vreal_this_command = XCDR (tem);
-  Frun_hooks (1, &Qkbd_macro_termination_hook);
+  run_hook (Qkbd_macro_termination_hook);
 }
 
 DEFUN ("execute-kbd-macro", Fexecute_kbd_macro, Sexecute_kbd_macro, 1, 3, 0,
@@ -306,7 +286,6 @@ each iteration of the macro.  Iteration stops if LOOPFUNC returns nil.  */)
   Lisp_Object tem;
   ptrdiff_t pdlcount = SPECPDL_INDEX ();
   EMACS_INT repeat = 1;
-  struct gcpro gcpro1, gcpro2;
   EMACS_INT success_count = 0;
 
   executing_kbd_macro_iterations = 0;
@@ -326,7 +305,6 @@ each iteration of the macro.  Iteration stops if LOOPFUNC returns nil.  */)
                      Vreal_this_command));
   record_unwind_protect (pop_kbd_macro, tem);
 
-  GCPRO2 (final, loopfunc);
   do
     {
       Vexecuting_kbd_macro = final;
@@ -356,7 +334,6 @@ each iteration of the macro.  Iteration stops if LOOPFUNC returns nil.  */)
 
   Vreal_this_command = Vexecuting_kbd_macro;
 
-  UNGCPRO;
   return unbind_to (pdlcount, Qnil);
 }
 \f
@@ -370,8 +347,6 @@ init_macros (void)
 void
 syms_of_macros (void)
 {
-  DEFSYM (Qexecute_kbd_macro, "execute-kbd-macro");
-
   DEFVAR_LISP ("kbd-macro-termination-hook", Vkbd_macro_termination_hook,
                doc: /* Normal hook run whenever a keyboard macro terminates.
 This is run whether the macro ends normally or prematurely due to an error.  */);