Show
Ignore:
Timestamp:
02/17/98 01:45:05 (11 years ago)
Author:
himi
Message:

Meadow--Multilingual Enhancement to GNU Emacs with ADvantages Over Windows

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/GNU/src/cmds.c

    r1488 r1490  
    11/* Simple built-in editing commands. 
    2    Copyright (C) 1985, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc. 
     2   Copyright (C) 1985, 93, 94, 95, 96, 1997 Free Software Foundation, Inc. 
    33 
    44This file is part of GNU Emacs. 
     
    2828#include "window.h" 
    2929#include "keyboard.h" 
    30 #include "dispextern.h" 
    3130 
    3231Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function; 
     
    4140Lisp_Object Vself_insert_face_command; 
    4241 
     42/* Offset to add to a non-ASCII value when inserting it.  */ 
     43int nonascii_insert_offset; 
     44 
    4345extern Lisp_Object Qface; 
    4446  
     47/* Return buffer position which is N characters after `point'.  */ 
     48int 
     49forward_point (n) 
     50     int n; 
     51{ 
     52  int pos = PT, c; 
     53 
     54  if (!NILP (current_buffer->enable_multibyte_characters)) 
     55    { 
     56      /* Simply adding N to `point' doesn't work because of multi-byte 
     57         form.  We had better not use INC_POS and DEC_POS because they 
     58         check the gap position every time.  But, for the moment, we 
     59         need working code.  */ 
     60      if (n > 0) 
     61        { 
     62          while (pos < ZV && n--) INC_POS (pos); 
     63          if (pos < ZV) n++; 
     64        } 
     65      else 
     66        { 
     67          while (pos > BEGV && n++) DEC_POS (pos); 
     68          if (pos > BEGV) n--; 
     69        } 
     70    } 
     71  pos += n; 
     72 
     73  return pos; 
     74} 
     75 
    4576DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, 
    4677  "Return buffer position N characters after (before if N negative) point.") 
     
    5081  CHECK_NUMBER (n, 0); 
    5182 
    52   return make_number (PT + XINT (n)); 
     83  return make_number (forward_point (XINT (n))); 
    5384} 
    5485 
     
    70101     proposed position, then set point.  */ 
    71102  { 
    72     int new_point = PT + XINT (n); 
     103    int new_point = forward_point (XINT (n)); 
    73104 
    74105    if (new_point < BEGV) 
     
    115146     Lisp_Object n; 
    116147{ 
    117   int opoint = PT, opoint_byte = PT_BYTE; 
    118   int pos, pos_byte; 
    119   int count, shortage; 
    120   int temp; 
     148  int pos2 = PT; 
     149  int pos; 
     150  int count, shortage, negp; 
    121151 
    122152  if (NILP (n)) 
     
    128158    } 
    129159 
    130   if (count <= 0) 
    131     shortage = scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1, 1); 
    132   else 
    133     shortage = scan_newline (PT, PT_BYTE, ZV, ZV_BYTE, count, 1); 
    134  
    135   /* Since scan_newline does TEMP_SET_PT_BOTH, 
    136      and we want to set PT "for real", 
    137      go back to the old point and then come back here.  */ 
    138   pos = PT; 
    139   pos_byte = PT_BYTE; 
    140   TEMP_SET_PT_BOTH (opoint, opoint_byte); 
    141   SET_PT_BOTH (pos, pos_byte); 
    142  
     160  negp = count <= 0; 
     161  pos = scan_buffer ('\n', pos2, 0, count - negp, &shortage, 1); 
    143162  if (shortage > 0 
    144       && (count <= 0 
     163      && (negp 
    145164          || (ZV > BEGV 
    146               && PT != opoint 
    147               && (FETCH_BYTE (PT_BYTE - 1) != '\n')))) 
     165              && pos != pos2 
     166              && FETCH_BYTE (pos - 1) != '\n'))) 
    148167    shortage--; 
    149  
    150   return make_number (count <= 0 ? - shortage : shortage); 
     168  SET_PT (pos); 
     169  return make_number (negp ? - shortage : shortage); 
    151170} 
    152171 
     
    201220  CHECK_NUMBER (n, 0); 
    202221 
    203   pos = PT + XINT (n); 
     222  pos = forward_point (XINT (n)); 
    204223  if (NILP (killflag)) 
    205224    { 
     
    237256  Lisp_Object value; 
    238257  int deleted_special = 0; 
    239   int pos, pos_byte, i; 
     258  int pos, i; 
    240259 
    241260  CHECK_NUMBER (n, 0); 
     
    243262  /* See if we are about to delete a tab or newline backwards.  */ 
    244263  pos = PT; 
    245   pos_byte = PT_BYTE; 
    246   for (i = 0; i < XINT (n) && pos_byte > BEGV_BYTE; i++) 
     264  for (i = 0; i < XINT (n) && pos > BEGV; i++) 
    247265    { 
    248266      int c; 
    249267 
    250       DEC_BOTH (pos, pos_byte); 
    251       c = FETCH_BYTE (pos_byte); 
     268      DEC_POS (pos); 
     269      c = FETCH_BYTE (pos); 
    252270      if (c == '\t' || c == '\n') 
    253271        { 
     
    262280      && ! NILP (current_buffer->overwrite_mode) 
    263281      && ! deleted_special 
    264       && ! (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')) 
     282      && ! (PT == ZV || FETCH_BYTE (PT) == '\n')) 
    265283    { 
    266284      int column = current_column (); 
     
    269287      i = column - current_column (); 
    270288      Finsert_char (make_number (' '), make_number (i), Qnil); 
    271       /* Whitespace chars are ASCII chars, so we can simply subtract.  */ 
    272       SET_PT_BOTH (PT - i, PT_BYTE - i); 
     289      SET_PT (PT - i); 
    273290    } 
    274291  else 
     
    297314         We pass internal_self_insert the unmodified character 
    298315         because it itself does this offsetting.  */ 
    299       if (! NILP (current_buffer->enable_multibyte_characters)) 
    300         modified_char = unibyte_char_to_multibyte (modified_char); 
     316      if (modified_char >= 0200 && modified_char <= 0377 
     317          && ! NILP (current_buffer->enable_multibyte_characters)) 
     318        modified_char += nonascii_insert_offset; 
    301319 
    302320      XSETFASTINT (n, XFASTINT (n) - 2); 
     
    328346   A value of 2 means this did things that call for an undo boundary.  */ 
    329347 
    330 int 
    331348internal_self_insert (c, noautofill) 
    332349     int c; 
     
    342359  /* Working buffer and pointer for multi-byte form of C.  */ 
    343360  unsigned char workbuf[4], *str; 
    344   int chars_to_delete = 0; 
     361  int number_to_delete = 0; 
    345362  int spaces_to_insert = 0; 
     363 
     364  if (c >= 0200 && c <= 0377 
     365      && ! NILP (current_buffer->enable_multibyte_characters)) 
     366    c += nonascii_insert_offset; 
    346367 
    347368  overwrite = current_buffer->overwrite_mode; 
     
    352373  /* At first, get multi-byte form of C in STR.  */ 
    353374  if (!NILP (current_buffer->enable_multibyte_characters)) 
    354     { 
    355       c = unibyte_char_to_multibyte (c); 
    356       len = CHAR_STRING (c, workbuf, str); 
    357     } 
    358   else 
    359     { 
    360       workbuf[0] = (SINGLE_BYTE_CHAR_P (c) 
    361                     ? c 
    362                     : multibyte_char_to_unibyte (c, Qnil)); 
    363       str = workbuf; 
    364       len = 1; 
    365     } 
     375    len = CHAR_STRING (c, workbuf, str); 
     376  else 
     377    workbuf[0] = c, str = workbuf, len = 1; 
     378 
    366379  if (!NILP (overwrite) 
    367380      && PT < ZV) 
     
    376389         C2 and several characters following C2.  */ 
    377390 
    378       /* This is the character after point.  */ 
    379       int c2 = FETCH_CHAR (PT_BYTE); 
    380  
    381       /* Column the cursor should be placed at after this insertion. 
     391      /* A code at `point'.  Since this is checked only against 
     392         NEWLINE and TAB, we don't need a character code but only the 
     393         first byte of multi-byte form.  */ 
     394      unsigned char c2 = FETCH_BYTE (PT); 
     395      /* A column the cursor should be placed at after this insertion. 
    382396         The correct value should be calculated only when necessary.  */ 
    383397      int target_clm = 0; 
     
    394408                    && XINT (current_buffer->tab_width) > 0 
    395409                    && XFASTINT (current_buffer->tab_width) < 20 
    396                     && (target_clm = (current_column ()  
    397                                       + XINT (Fchar_width (make_number (c2)))), 
     410                    && ((NILP (current_buffer->enable_multibyte_characters) 
     411                         ? (target_clm = current_column () + 1) 
     412                         : (target_clm = current_column () + WIDTH_BY_CHAR_HEAD (str[0]))), 
    398413                        target_clm % XFASTINT (current_buffer->tab_width))))) 
    399414        { 
    400415          int pos = PT; 
    401           int pos_byte = PT_BYTE; 
    402416 
    403417          if (target_clm == 0) 
    404             chars_to_delete = 1
     418            number_to_delete = forward_point (1) - PT
    405419          else 
    406420            { 
     
    413427                = XFASTINT (Fmove_to_column (make_number (target_clm), Qnil)); 
    414428 
    415               chars_to_delete = PT - pos; 
     429              number_to_delete = PT - pos; 
    416430 
    417431              if (actual_clm > target_clm) 
     
    422436                } 
    423437            } 
    424           SET_PT_BOTH (pos, pos_byte); 
     438          SET_PT (pos); 
    425439          hairy = 2; 
    426440        } 
     
    453467    } 
    454468 
    455   if (chars_to_delete) 
    456     { 
    457       string = make_string_from_bytes (str, 1, len); 
     469  if (number_to_delete) 
     470    { 
     471      string = make_string (str, len); 
    458472      if (spaces_to_insert) 
    459473        { 
     
    463477        } 
    464478 
    465       replace_range (PT, PT + chars_to_delete, string, 1, 1, 1); 
    466       Fforward_char (make_number (1 + spaces_to_insert)); 
     479      replace_range (PT, PT + number_to_delete, string, 1, 1); 
     480      SET_PT (PT + XSTRING (string)->size); 
    467481    } 
    468482  else 
     
    476490 
    477491      if (c == '\n') 
    478         /* After inserting a newline, move to previous line and fill 
    479            that.  Must have the newline in place already so filling and 
    480            justification, if any, know where the end is going to be. */ 
    481         SET_PT_BOTH (PT - 1, PT_BYTE - 1); 
     492        /* After inserting a newline, move to previous line and fill */ 
     493        /* that.  Must have the newline in place already so filling and */ 
     494        /* justification, if any, know where the end is going to be. */ 
     495        SET_PT (PT - 1); 
    482496      tem = call0 (current_buffer->auto_fill_function); 
    483497      if (c == '\n') 
    484         SET_PT_BOTH (PT + 1, PT_BYTE + 1); 
     498        SET_PT (PT + 1); 
    485499      if (!NILP (tem)) 
    486500        hairy = 2; 
     
    492506      && EQ (current_kboard->Vlast_command, Vself_insert_face_command)) 
    493507    { 
    494       Fput_text_property (make_number (PT - 1), make_number (PT), 
    495                           Qface, Vself_insert_face, Qnil); 
     508      Lisp_Object before, after; 
     509      XSETINT (before, PT - len); 
     510      XSETINT (after, PT); 
     511      Fput_text_property (before, after, Qface, Vself_insert_face, Qnil); 
    496512      Vself_insert_face = Qnil; 
    497513    } 
     
    511527/* module initialization */ 
    512528 
    513 void 
    514529syms_of_cmds () 
    515530{ 
     
    537552More precisely, a char with closeparen syntax is self-inserted."); 
    538553  Vblink_paren_function = Qnil; 
     554 
     555  DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset, 
     556    "Offset to add to a non-ascii code 0200...0377 when inserting it.\n\ 
     557This applies only when multibyte characters are enabled, and it serves\n\ 
     558to convert a Latin-1 or similar 8-bit character code to the corresponding\n\ 
     559Emacs character code."); 
     560  nonascii_insert_offset = 0; 
    539561 
    540562  defsubr (&Sforward_point); 
     
    551573} 
    552574 
    553 void 
    554575keys_of_cmds () 
    555576{