]> code.delx.au - gnu-emacs/blobdiff - src/indent.c
(current_column): Remove unused variable `stopchar'.
[gnu-emacs] / src / indent.c
index f53d971018caabab780f128917d367d383681d40..f10221b082a37caa8485e62f6d6ddfc54b629fb2 100644 (file)
@@ -25,6 +25,7 @@ Boston, MA 02111-1307, USA.  */
 #include "charset.h"
 #include "category.h"
 #include "indent.h"
+#include "keyboard.h"
 #include "frame.h"
 #include "window.h"
 #include "termchar.h"
@@ -266,6 +267,31 @@ skip_invisible (pos, next_boundary_p, to, window)
   return pos;
 }
 \f
+/* If a composition starts at POS/POS_BYTE and it doesn't stride over
+   POINT, set *LEN / *LEN_BYTE to the character and byte lengths, *WIDTH
+   to the width, and return 1.  Otherwise, return 0.  */
+
+static int
+check_composition (pos, pos_byte, point, len, len_byte, width)
+     int pos, pos_byte, point;
+     int *len, *len_byte, *width;
+{
+  Lisp_Object prop;
+  int start, end;
+  int id;
+
+  if (! find_composition (pos, -1, &start, &end, &prop, Qnil)
+      || pos != start || point < end)
+    return 0;
+  if ((id = get_composition_id (pos, pos_byte, end - pos, prop, Qnil)) < 0)
+    return 0;
+
+  *len = COMPOSITION_LENGTH (prop);
+  *len_byte = CHAR_TO_BYTE (end) - pos_byte;
+  *width = composition_table[id]->width;
+  return 1;
+}
+\f
 /* Set variables WIDTH and BYTES for a multibyte sequence starting at P.
 
    DP is a display table or NULL.
@@ -273,23 +299,23 @@ skip_invisible (pos, next_boundary_p, to, window)
    This macro is used in current_column_1, Fmove_to_column, and
    compute_motion.  */
 
-#define MULTIBYTE_BYTES_WIDTH(p, dp)                                     \
-  do {                                                                   \
-    int c;                                                               \
-                                                                         \
-    wide_column = 0;                                                     \
-    c = STRING_CHAR_AND_LENGTH (p, MAX_LENGTH_OF_MULTI_BYTE_FORM, bytes); \
-    if (BYTES_BY_CHAR_HEAD (*p) != bytes)                                \
-      width = bytes * 4;                                                 \
-    else                                                                 \
-      {                                                                          \
-       if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))                \
-         width = XVECTOR (DISP_CHAR_VECTOR (dp, c))->size;               \
-       else                                                              \
-         width = WIDTH_BY_CHAR_HEAD (*p);                                \
-       if (width > 1)                                                    \
-         wide_column = width;                                            \
-      }                                                                          \
+#define MULTIBYTE_BYTES_WIDTH(p, dp)                                   \
+  do {                                                                 \
+    int c;                                                             \
+                                                                       \
+    wide_column = 0;                                                   \
+    c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, bytes);       \
+    if (BYTES_BY_CHAR_HEAD (*p) != bytes)                              \
+      width = bytes * 4;                                               \
+    else                                                               \
+      {                                                                        \
+       if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c)))              \
+         width = XVECTOR (DISP_CHAR_VECTOR (dp, c))->size;             \
+       else                                                            \
+         width = WIDTH_BY_CHAR_HEAD (*p);                              \
+       if (width > 1)                                                  \
+         wide_column = width;                                          \
+      }                                                                        \
   } while (0)
 
 DEFUN ("current-column", Fcurrent_column, Scurrent_column, 0, 0, 0,
@@ -328,7 +354,6 @@ current_column ()
   register int tab_width = XINT (current_buffer->tab_width);
   int ctl_arrow = !NILP (current_buffer->ctl_arrow);
   register struct Lisp_Char_Table *dp = buffer_display_table ();
-  int stopchar;
 
   if (PT == last_known_column_point
       && MODIFF == last_known_column_modified)
@@ -464,6 +489,21 @@ current_column_1 ()
          next_boundary_byte = CHAR_TO_BYTE (next_boundary);
        }
 
+      /* Check composition sequence.  */
+      {
+       int len, len_byte, width;
+
+       if (check_composition (scan, scan_byte, opoint,
+                              &len, &len_byte, &width))
+         {
+           scan += len;
+           scan_byte += len_byte;
+           if (scan <= opoint)
+             col += width;
+           continue;
+         }
+      }
+
       c = FETCH_BYTE (scan_byte);
       if (dp != 0
          && ! (multibyte && BASE_LEADING_CODE_P (c))
@@ -794,8 +834,8 @@ The return value is the current column.")
   register int multibyte = !NILP (current_buffer->enable_multibyte_characters);
 
   Lisp_Object val;
-  int prev_col;
-  int c;
+  int prev_col = 0;
+  int c = 0;
   int next_boundary;
 
   int pos_byte, end_byte, next_boundary_byte;
@@ -840,6 +880,19 @@ The return value is the current column.")
       if (col >= goal)
        break;
 
+      /* Check composition sequence.  */
+      {
+       int len, len_byte, width;
+
+       if (check_composition (pos, pos_byte, Z, &len, &len_byte, &width))
+         {
+           pos += len;
+           pos_byte += len_byte;
+           col += width;
+           continue;
+         }
+      }
+
       c = FETCH_BYTE (pos_byte);
       if (dp != 0
          && ! (multibyte && BASE_LEADING_CODE_P (c))
@@ -891,14 +944,21 @@ The return value is the current column.")
      and scan through it again.  */
   if (!NILP (force) && col > goal && c == '\t' && prev_col < goal)
     {
-      int old_point, old_point_byte;
-
-      del_range (PT - 1, PT);
-      Findent_to (make_number (goal), Qnil);
-      old_point = PT;
-      old_point_byte = PT_BYTE;
+      int goal_pt, goal_pt_byte;
+
+      /* Insert spaces in front of the tab to reach GOAL.  Do this
+        first so that a marker at the end of the tab gets
+        adjusted.  */
+      SET_PT_BOTH (PT - 1, PT_BYTE - 1);
+      Finsert_char (make_number (' '), make_number (goal - prev_col), Qt);
+
+      /* Now delete the tab, and indent to COL.  */
+      del_range (PT, PT + 1);
+      goal_pt = PT;
+      goal_pt_byte = PT_BYTE;
       Findent_to (make_number (col), Qnil);
-      SET_PT_BOTH (old_point, old_point_byte);
+      SET_PT_BOTH (goal_pt, goal_pt_byte);
+      
       /* Set the last_known... vars consistently.  */
       col = goal;
     }
@@ -992,7 +1052,7 @@ compute_motion (from, fromvpos, fromhpos, did_motion, to, tovpos, tohpos, width,
 
   register int pos;
   int pos_byte;
-  register int c;
+  register int c = 0;
   register int tab_width = XFASTINT (current_buffer->tab_width);
   register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
   register struct Lisp_Char_Table *dp = window_display_table (win);
@@ -1044,7 +1104,11 @@ compute_motion (from, fromvpos, fromhpos, did_motion, to, tovpos, tohpos, width,
        run cache, because that's based on the buffer's display table.  */
     width_table = 0;
 
-  if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
+  if (tab_width <= 0 || tab_width > 1000)
+    tab_width = 8;
+
+  immediate_quit = 1;
+  QUIT;
 
   pos = prev_pos = from;
   pos_byte = prev_pos_byte = CHAR_TO_BYTE (from);
@@ -1106,6 +1170,7 @@ compute_motion (from, fromvpos, fromhpos, did_motion, to, tovpos, tohpos, width,
          if (newpos >= to)
            {
              pos = min (to, newpos);
+             pos_byte = CHAR_TO_BYTE (pos);
              goto after_loop;
            }
 
@@ -1321,6 +1386,20 @@ compute_motion (from, fromvpos, fromhpos, did_motion, to, tovpos, tohpos, width,
       else
        {
          c = FETCH_BYTE (pos_byte);
+
+         /* Check composition sequence.  */
+         {
+           int len, len_byte, width;
+
+           if (check_composition (pos, pos_byte, to, &len, &len_byte, &width))
+             {
+               pos += len;
+               pos_byte += len_byte;
+               hpos += width;
+               continue;
+             }
+         }
+
          pos++, pos_byte++;
 
          /* Perhaps add some info to the width_run_cache.  */
@@ -1473,6 +1552,7 @@ compute_motion (from, fromvpos, fromhpos, did_motion, to, tovpos, tohpos, width,
   /* Nonzero if have just continued a line */
   val_compute_motion.contin = (contin_hpos && prev_hpos == 0);
 
+  immediate_quit = 0;
   return &val_compute_motion;
 }
 
@@ -1528,26 +1608,26 @@ DEFUN ("compute-motion", Fcompute_motion, Scompute_motion, 7, 7, 0,
      Lisp_Object from, frompos, to, topos;
      Lisp_Object width, offsets, window;
 {
-  Lisp_Object bufpos, hpos, vpos, prevhpos, contin;
+  Lisp_Object bufpos, hpos, vpos, prevhpos;
   struct position *pos;
   int hscroll, tab_offset;
 
   CHECK_NUMBER_COERCE_MARKER (from, 0);
   CHECK_CONS (frompos, 0);
-  CHECK_NUMBER (XCONS (frompos)->car, 0);
-  CHECK_NUMBER (XCONS (frompos)->cdr, 0);
+  CHECK_NUMBER (XCAR (frompos), 0);
+  CHECK_NUMBER (XCDR (frompos), 0);
   CHECK_NUMBER_COERCE_MARKER (to, 0);
   CHECK_CONS (topos, 0);
-  CHECK_NUMBER (XCONS (topos)->car, 0);
-  CHECK_NUMBER (XCONS (topos)->cdr, 0);
+  CHECK_NUMBER (XCAR (topos), 0);
+  CHECK_NUMBER (XCDR (topos), 0);
   CHECK_NUMBER (width, 0);
   if (!NILP (offsets))
     {
       CHECK_CONS (offsets, 0);
-      CHECK_NUMBER (XCONS (offsets)->car, 0);
-      CHECK_NUMBER (XCONS (offsets)->cdr, 0);
-      hscroll = XINT (XCONS (offsets)->car);
-      tab_offset = XINT (XCONS (offsets)->cdr);
+      CHECK_NUMBER (XCAR (offsets), 0);
+      CHECK_NUMBER (XCDR (offsets), 0);
+      hscroll = XINT (XCAR (offsets));
+      tab_offset = XINT (XCDR (offsets));
     }
   else
     hscroll = tab_offset = 0;
@@ -1562,10 +1642,10 @@ DEFUN ("compute-motion", Fcompute_motion, Scompute_motion, 7, 7, 0,
   if (XINT (to) < BEGV || XINT (to) > ZV)
     args_out_of_range_3 (to, make_number (BEGV), make_number (ZV));
 
-  pos = compute_motion (XINT (from), XINT (XCONS (frompos)->cdr),
-                       XINT (XCONS (frompos)->car), 0,
-                       XINT (to), XINT (XCONS (topos)->cdr),
-                       XINT (XCONS (topos)->car),
+  pos = compute_motion (XINT (from), XINT (XCDR (frompos)),
+                       XINT (XCAR (frompos)), 0,
+                       XINT (to), XINT (XCDR (topos)),
+                       XINT (XCAR (topos)),
                        XINT (width), hscroll, tab_offset,
                        XWINDOW (window));
 
@@ -1635,14 +1715,11 @@ vmotion (from, vtarget, w)
                      && indented_beyond_p (XFASTINT (prevline),
                                            CHAR_TO_BYTE (XFASTINT (prevline)),
                                            selective))
-#ifdef USE_TEXT_PROPERTIES
                     /* watch out for newlines with `invisible' property */
                     || (propval = Fget_char_property (prevline,
                                                       Qinvisible,
                                                       text_prop_object),
-                        TEXT_PROP_MEANS_INVISIBLE (propval))
-#endif
-                    ))
+                        TEXT_PROP_MEANS_INVISIBLE (propval))))
            XSETFASTINT (prevline,
                         find_next_newline_no_quit (XFASTINT (prevline) - 1,
                                                    -1));
@@ -1698,13 +1775,10 @@ vmotion (from, vtarget, w)
                  && indented_beyond_p (XFASTINT (prevline),
                                        CHAR_TO_BYTE (XFASTINT (prevline)),
                                        selective))
-#ifdef USE_TEXT_PROPERTIES
                 /* watch out for newlines with `invisible' property */
                 || (propval = Fget_char_property (prevline, Qinvisible,
                                                   text_prop_object),
-                    TEXT_PROP_MEANS_INVISIBLE (propval))
-#endif
-            ))
+                    TEXT_PROP_MEANS_INVISIBLE (propval))))
        XSETFASTINT (prevline,
                     find_next_newline_no_quit (XFASTINT (prevline) - 1,
                                                -1));
@@ -1762,34 +1836,35 @@ whether or not it is currently displayed in some window.")
 {
   struct it it;
   struct text_pos pt;
-  struct buffer *old, *b;
   struct window *w;
+  Lisp_Object old_buffer;
+  struct gcpro gcpro1;
 
   CHECK_NUMBER (lines, 0);
   if (! NILP (window))
     CHECK_WINDOW (window, 0);
   else
     window = selected_window;
-
   w = XWINDOW (window);
-  b = XBUFFER (w->buffer);
-  if (b != current_buffer)
+
+  old_buffer = Qnil;
+  GCPRO1 (old_buffer);
+  if (XBUFFER (w->buffer) != current_buffer)
     {
-      old = current_buffer;
-      set_buffer_internal_1 (b);
+      /* Set the window's buffer temporarily to the current buffer.  */
+      old_buffer = w->buffer;
+      XSETBUFFER (w->buffer, current_buffer);
     }
-  else
-    old = NULL;
       
   SET_TEXT_POS (pt, PT, PT_BYTE);
   start_display (&it, w, pt);
   move_it_by_lines (&it, XINT (lines), 0);
   SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
 
-  if (old)
-    set_buffer_internal_1 (old);
+  if (BUFFERP (old_buffer))
+    w->buffer = old_buffer;
   
-  return make_number (it.vpos);
+  RETURN_UNGCPRO (make_number (it.vpos));
 }