Support git commit --amend/--signoff
[bpt/emacs.git] / src / frame.c
index 0871100..edb9003 100644 (file)
@@ -24,21 +24,16 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdio.h>
 #include <errno.h>
 #include <limits.h>
-#include <setjmp.h>
 
 #include <c-ctype.h>
 
 #include "lisp.h"
 #include "character.h"
-#ifdef HAVE_X_WINDOWS
-#include "xterm.h"
-#endif
-#ifdef WINDOWSNT
-#include "w32term.h"
-#endif
-#ifdef HAVE_NS
-#include "nsterm.h"
-#endif
+
+#ifdef HAVE_WINDOW_SYSTEM
+#include TERM_HEADER
+#endif /* HAVE_WINDOW_SYSTEM */
+
 #include "buffer.h"
 /* These help us bind and responding to switch-frame events.  */
 #include "commands.h"
@@ -58,11 +53,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "dosfns.h"
 #endif
 
-
-#ifdef HAVE_WINDOW_SYSTEM
-
-#endif
-
 #ifdef HAVE_NS
 Lisp_Object Qns_parse_geometry;
 #endif
@@ -130,12 +120,12 @@ static void x_report_frame_params (struct frame *, Lisp_Object *);
 #endif
 
 /* These setters are used only in this file, so they can be private.  */
-static inline void
+static void
 fset_buffer_predicate (struct frame *f, Lisp_Object val)
 {
   f->buffer_predicate = val;
 }
-static inline void
+static void
 fset_minibuffer_window (struct frame *f, Lisp_Object val)
 {
   f->minibuffer_window = val;
@@ -148,8 +138,8 @@ set_menu_bar_lines_1 (Lisp_Object window, int n)
   struct window *w = XWINDOW (window);
 
   w->last_modified = 0;
-  WSET (w, top_line, make_number (XFASTINT (w->top_line) + n));
-  WSET (w, total_lines, make_number (XFASTINT (w->total_lines) - n));
+  wset_top_line (w, make_number (XFASTINT (w->top_line) + n));
+  wset_total_lines (w, make_number (XFASTINT (w->total_lines) - n));
 
   /* Handle just the top child in a vertical split.  */
   if (!NILP (w->vchild))
@@ -223,7 +213,7 @@ See also `frame-live-p'.  */)
     case output_ns:
       return Qns;
     default:
-      abort ();
+      emacs_abort ();
     }
 }
 
@@ -305,20 +295,20 @@ make_frame (int mini_p)
   if (mini_p)
     {
       mini_window = make_window ();
-      WSET (XWINDOW (root_window), next, mini_window);
-      WSET (XWINDOW (mini_window), prev, root_window);
+      wset_next (XWINDOW (root_window), mini_window);
+      wset_prev (XWINDOW (mini_window), root_window);
       XWINDOW (mini_window)->mini = 1;
-      WSET (XWINDOW (mini_window), frame, frame);
+      wset_frame (XWINDOW (mini_window), frame);
       fset_minibuffer_window (f, mini_window);
     }
   else
     {
       mini_window = Qnil;
-      WSET (XWINDOW (root_window), next, Qnil);
+      wset_next (XWINDOW (root_window), Qnil);
       fset_minibuffer_window (f, Qnil);
     }
 
-  WSET (XWINDOW (root_window), frame, frame);
+  wset_frame (XWINDOW (root_window), frame);
 
   /* 10 is arbitrary,
      just so that there is "something there."
@@ -327,21 +317,21 @@ make_frame (int mini_p)
   SET_FRAME_COLS (f, 10);
   FRAME_LINES (f) = 10;
 
-  WSET (XWINDOW (root_window), total_cols, make_number (10));
-  WSET (XWINDOW (root_window), total_lines, make_number (mini_p ? 9 : 10));
+  wset_total_cols (XWINDOW (root_window), make_number (10));
+  wset_total_lines (XWINDOW (root_window), make_number (mini_p ? 9 : 10));
 
   if (mini_p)
     {
-      WSET (XWINDOW (mini_window), total_cols, make_number (10));
-      WSET (XWINDOW (mini_window), top_line, make_number (9));
-      WSET (XWINDOW (mini_window), total_lines, make_number (1));
+      wset_total_cols (XWINDOW (mini_window), make_number (10));
+      wset_top_line (XWINDOW (mini_window), make_number (9));
+      wset_total_lines (XWINDOW (mini_window), make_number (1));
     }
 
   /* Choose a buffer for the frame's root window.  */
   {
     Lisp_Object buf;
 
-    WSET (XWINDOW (root_window), buffer, Qt);
+    wset_buffer (XWINDOW (root_window), Qt);
     buf = Fcurrent_buffer ();
     /* If buf is a 'hidden' buffer (i.e. one whose name starts with
        a space), try to find another one.  */
@@ -360,7 +350,7 @@ make_frame (int mini_p)
 
   if (mini_p)
     {
-      WSET (XWINDOW (mini_window), buffer, Qt);
+      wset_buffer (XWINDOW (mini_window), Qt);
       set_window_buffer (mini_window,
                         (NILP (Vminibuffer_list)
                          ? get_minibuffer (0)
@@ -409,8 +399,8 @@ make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lis
           XSETFRAME (frame_dummy, f);
           GCPRO1 (frame_dummy);
          /* If there's no minibuffer frame to use, create one.  */
-         KSET (kb, Vdefault_minibuffer_frame,
-               call1 (intern ("make-initial-minibuffer-frame"), display));
+         kset_default_minibuffer_frame
+           (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
           UNGCPRO;
        }
 
@@ -458,9 +448,9 @@ make_minibuffer_frame (void)
   mini_window = f->root_window;
   fset_minibuffer_window (f, mini_window);
   XWINDOW (mini_window)->mini = 1;
-  WSET (XWINDOW (mini_window), next, Qnil);
-  WSET (XWINDOW (mini_window), prev, Qnil);
-  WSET (XWINDOW (mini_window), frame, frame);
+  wset_next (XWINDOW (mini_window), Qnil);
+  wset_prev (XWINDOW (mini_window), Qnil);
+  wset_frame (XWINDOW (mini_window), frame);
 
   /* Put the proper buffer in that window.  */
 
@@ -629,7 +619,7 @@ affects all frames on the same terminal device.  */)
 #ifdef MSDOS
   if (sf->output_method != output_msdos_raw
       && sf->output_method != output_termcap)
-    abort ();
+    emacs_abort ();
 #else /* not MSDOS */
 
 #ifdef WINDOWSNT                           /* This should work now! */
@@ -776,7 +766,7 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor
          Lisp_Object focus;
 
          if (!FRAMEP (XCAR (tail)))
-           abort ();
+           emacs_abort ();
 
          focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
 
@@ -864,7 +854,7 @@ to that frame.  */)
   (Lisp_Object event)
 {
   /* Preserve prefix arg that the command loop just cleared.  */
-  KSET (current_kboard, Vprefix_arg, Vcurrent_prefix_arg);
+  kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
   Frun_hooks (1, &Qmouse_leave_buffer_hook);
   return do_switch_frame (event, 0, 0, Qnil);
 }
@@ -906,7 +896,7 @@ next_frame (Lisp_Object frame, Lisp_Object minibuf)
 
   /* There must always be at least one frame in Vframe_list.  */
   if (! CONSP (Vframe_list))
-    abort ();
+    emacs_abort ();
 
   /* If this frame is dead, it won't be in Vframe_list, and we'll loop
      forever.  Forestall that.  */
@@ -984,7 +974,7 @@ prev_frame (Lisp_Object frame, Lisp_Object minibuf)
 
   /* There must always be at least one frame in Vframe_list.  */
   if (! CONSP (Vframe_list))
-    abort ();
+    emacs_abort ();
 
   prev = Qnil;
   for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
@@ -993,7 +983,7 @@ prev_frame (Lisp_Object frame, Lisp_Object minibuf)
 
       f = XCAR (tail);
       if (!FRAMEP (f))
-       abort ();
+       emacs_abort ();
 
       if (EQ (frame, f) && !NILP (prev))
        return prev;
@@ -1308,6 +1298,11 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
      structures can still refer to it.  */
   fset_menu_bar_vector (f, Qnil);
 
+  /* If FRAME's buffer lists contains killed
+     buffers, this helps GC to reclaim them.  */
+  fset_buffer_list (f, Qnil);
+  fset_buried_buffer_list (f, Qnil);
+
   free_font_driver_list (f);
   xfree (f->namebuf);
   xfree (f->decode_mode_spec_buffer);
@@ -1394,7 +1389,7 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
 
          this = XCAR (frames);
          if (!FRAMEP (this))
-           abort ();
+           emacs_abort ();
          f1 = XFRAME (this);
 
          if (kb == FRAME_KBOARD (f1))
@@ -1430,7 +1425,7 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
 
          this = XCAR (frames);
          if (!FRAMEP (this))
-           abort ();
+           emacs_abort ();
          f1 = XFRAME (this);
 
          /* Consider only frames on the same kboard
@@ -1456,13 +1451,13 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
             that is prohibited at the top; you can't delete surrogate
             minibuffer frames.  */
          if (NILP (frame_with_minibuf))
-           abort ();
+           emacs_abort ();
 
-         KSET (kb, Vdefault_minibuffer_frame, frame_with_minibuf);
+         kset_default_minibuffer_frame (kb, frame_with_minibuf);
        }
       else
        /* No frames left on this kboard--say no minibuffer either.  */
-       KSET (kb, Vdefault_minibuffer_frame, Qnil);
+       kset_default_minibuffer_frame (kb, Qnil);
     }
 
   /* Cause frame titles to update--necessary if we now have just one frame.  */
@@ -1700,7 +1695,7 @@ make_frame_visible_1 (Lisp_Object window)
       w = XWINDOW (window);
 
       if (!NILP (w->buffer))
-       BSET (XBUFFER (w->buffer), display_time, Fcurrent_time ());
+       bset_display_time (XBUFFER (w->buffer), Fcurrent_time ());
 
       if (!NILP (w->vchild))
        make_frame_visible_1 (w->vchild);
@@ -2117,7 +2112,7 @@ store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
              swap_in_global_binding (sym);
            break;
          }
-       default: abort ();
+       default: emacs_abort ();
        }
     }
 
@@ -3033,9 +3028,9 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
 void
 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
 {
-  char buf[16];
   Lisp_Object tem;
-  unsigned long w;
+  uprintmax_t w;
+  char buf[INT_BUFSIZE_BOUND (w)];
 
   /* Represent negative positions (off the top or left screen edge)
      in a way that Fmodify_frame_parameters will understand correctly.  */
@@ -3072,17 +3067,17 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
      MS-Windows it returns a value whose type is HANDLE, which is
      actually a pointer.  Explicit casting avoids compiler
      warnings.  */
-  w = (unsigned long) FRAME_X_WINDOW (f);
+  w = (uintptr_t) FRAME_X_WINDOW (f);
   store_in_alist (alistptr, Qwindow_id,
-                 make_formatted_string (buf, "%lu", w));
+                 make_formatted_string (buf, "%"pMu, w));
 #ifdef HAVE_X_WINDOWS
 #ifdef USE_X_TOOLKIT
   /* Tooltip frame may not have this widget.  */
   if (FRAME_X_OUTPUT (f)->widget)
 #endif
-    w = (unsigned long) FRAME_OUTER_WINDOW (f);
+    w = (uintptr_t) FRAME_OUTER_WINDOW (f);
   store_in_alist (alistptr, Qouter_window_id,
-                 make_formatted_string (buf, "%lu", w));
+                 make_formatted_string (buf, "%"pMu, w));
 #endif
   store_in_alist (alistptr, Qicon_name, f->icon_name);
   FRAME_SAMPLE_VISIBILITY (f);
@@ -3538,9 +3533,9 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     f->alpha[i] = newval[i];
 
 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
-  BLOCK_INPUT;
+  block_input ();
   x_set_frame_alpha (f);
-  UNBLOCK_INPUT;
+  unblock_input ();
 #endif
 
   return;
@@ -3844,7 +3839,7 @@ x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
              }
 
            default:
-             abort ();
+             emacs_abort ();
            }
        }
       else
@@ -3902,6 +3897,95 @@ x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
 }
 
 
+#if !defined (HAVE_X_WINDOWS) && defined (NoValue)
+
+/*
+ *    XParseGeometry parses strings of the form
+ *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
+ *   width, height, xoffset, and yoffset are unsigned integers.
+ *   Example:  "=80x24+300-49"
+ *   The equal sign is optional.
+ *   It returns a bitmask that indicates which of the four values
+ *   were actually found in the string.  For each value found,
+ *   the corresponding argument is updated;  for each value
+ *   not found, the corresponding argument is left unchanged.
+ */
+
+static int
+XParseGeometry (char *string,
+               int *x, int *y,
+               unsigned int *width, unsigned int *height)
+{
+  int mask = NoValue;
+  char *strind;
+  unsigned long int tempWidth, tempHeight;
+  long int tempX, tempY;
+  char *nextCharacter;
+
+  if (string == NULL || *string == '\0')
+    return mask;
+  if (*string == '=')
+    string++;  /* ignore possible '=' at beg of geometry spec */
+
+  strind = string;
+  if (*strind != '+' && *strind != '-' && *strind != 'x')
+    {
+      tempWidth = strtoul (strind, &nextCharacter, 10);
+      if (strind == nextCharacter)
+       return 0;
+      strind = nextCharacter;
+      mask |= WidthValue;
+    }
+
+  if (*strind == 'x' || *strind == 'X')
+    {
+      strind++;
+      tempHeight = strtoul (strind, &nextCharacter, 10);
+      if (strind == nextCharacter)
+       return 0;
+      strind = nextCharacter;
+      mask |= HeightValue;
+    }
+
+  if (*strind == '+' || *strind == '-')
+    {
+      if (*strind == '-')
+       mask |= XNegative;
+      tempX = strtol (strind, &nextCharacter, 10);
+      if (strind == nextCharacter)
+       return 0;
+      strind = nextCharacter;
+      mask |= XValue;
+      if (*strind == '+' || *strind == '-')
+       {
+         if (*strind == '-')
+           mask |= YNegative;
+         tempY = strtol (strind, &nextCharacter, 10);
+         if (strind == nextCharacter)
+           return 0;
+         strind = nextCharacter;
+         mask |= YValue;
+       }
+    }
+
+  /* If strind isn't at the end of the string then it's an invalid
+     geometry specification. */
+
+  if (*strind != '\0')
+    return 0;
+
+  if (mask & XValue)
+    *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
+  if (mask & YValue)
+    *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
+  if (mask & WidthValue)
+    *width = min (tempWidth, UINT_MAX);
+  if (mask & HeightValue)
+    *height = min (tempHeight, UINT_MAX);
+  return mask;
+}
+
+#endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
 
 \f
 /* NS used to define x-parse-geometry in ns-win.el, but that confused
@@ -3922,15 +4006,16 @@ or a list (- N) meaning -N pixels relative to bottom/right corner.
 On Nextstep, this just calls `ns-parse-geometry'.  */)
   (Lisp_Object string)
 {
-#ifdef HAVE_NS
-  return call1 (Qns_parse_geometry, string);
-#else
   int geometry, x, y;
   unsigned int width, height;
   Lisp_Object result;
 
   CHECK_STRING (string);
 
+#ifdef HAVE_NS
+  if (strchr (SSDATA (string), ' ') != NULL)
+    return call1 (Qns_parse_geometry, string);
+#endif
   geometry = XParseGeometry (SSDATA (string),
                             &x, &y, &width, &height);
   result = Qnil;
@@ -3966,7 +4051,6 @@ On Nextstep, this just calls `ns-parse-geometry'.  */)
     result = Fcons (Fcons (Qheight, make_number (height)), result);
 
   return result;
-#endif /* HAVE_NS */
 }
 
 
@@ -4247,7 +4331,6 @@ syms_of_frame (void)
   DEFSYM (Qx, "x");
   DEFSYM (Qw32, "w32");
   DEFSYM (Qpc, "pc");
-  DEFSYM (Qmac, "mac");
   DEFSYM (Qns, "ns");
   DEFSYM (Qvisible, "visible");
   DEFSYM (Qbuffer_predicate, "buffer-predicate");