comparison src/xdisp.c @ 20473:f8b70ad2fc2a

(message_dolog): Update PT and ZV properly when at end of buffer, when we convert between multibyte and single-byte. Properly initialize i. (message_dolog): Convert between single-byte and multibyte when inserting text into *Messages*.
author Richard M. Stallman <rms@gnu.org>
date Sun, 21 Dec 1997 01:20:26 +0000
parents 67f1753dc577
children 9946c5fb4ff7
comparison
equal deleted inserted replaced
20472:79ea90039b23 20473:f8b70ad2fc2a
283 if (!NILP (Vmessage_log_max)) 283 if (!NILP (Vmessage_log_max))
284 { 284 {
285 struct buffer *oldbuf; 285 struct buffer *oldbuf;
286 int oldpoint, oldbegv, oldzv; 286 int oldpoint, oldbegv, oldzv;
287 int old_windows_or_buffers_changed = windows_or_buffers_changed; 287 int old_windows_or_buffers_changed = windows_or_buffers_changed;
288 int point_at_end = 0;
289 int zv_at_end = 0;
288 290
289 oldbuf = current_buffer; 291 oldbuf = current_buffer;
290 Fset_buffer (Fget_buffer_create (build_string ("*Messages*"))); 292 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
291 current_buffer->undo_list = Qt; 293 current_buffer->undo_list = Qt;
292 oldpoint = PT; 294 oldpoint = PT;
293 oldbegv = BEGV; 295 oldbegv = BEGV;
294 oldzv = ZV; 296 oldzv = ZV;
295 BEGV = BEG; 297 BEGV = BEG;
296 ZV = Z; 298 ZV = Z;
297 if (oldpoint == Z) 299 if (oldpoint == Z)
298 oldpoint += len + nlflag; 300 point_at_end = 1;
299 if (oldzv == Z) 301 if (oldzv == Z)
300 oldzv += len + nlflag; 302 zv_at_end = 1;
301 TEMP_SET_PT (Z); 303 TEMP_SET_PT (Z);
302 if (len) 304
305 /* Insert the string--maybe converting multibyte to single byte
306 or vice versa, so that all the text fits the buffer. */
307 if (! NILP (oldbuf->enable_multibyte_characters)
308 && NILP (current_buffer->enable_multibyte_characters))
309 {
310 int c, i = 0, nbytes;
311 /* Convert a multibyte string to single-byte
312 for the *Message* buffer. */
313 while (i < len)
314 {
315 c = STRING_CHAR (m + i, len - i);
316 i += XFASTINT (Fchar_bytes (make_number (c)));
317 /* Truncate the character to its last byte--we can only hope
318 the user is happy with the character he gets,
319 since if it isn't right, there is no way to do it right. */
320 c &= 0xff;
321 insert_char (c);
322 }
323 }
324 else if (NILP (oldbuf->enable_multibyte_characters)
325 && ! NILP (current_buffer->enable_multibyte_characters))
326 {
327 int c, i = 0;
328 /* Convert a single-byte string to multibyte
329 for the *Message* buffer. */
330 while (i < len)
331 {
332 c = m[i++];
333 /* Convert non-ascii chars as if for self-insert. */
334 if (c >= 0200 && c <= 0377)
335 c += nonascii_insert_offset;
336 insert_char (c);
337 }
338 }
339 else if (len)
303 insert_1 (m, len, 1, 0); 340 insert_1 (m, len, 1, 0);
341
304 if (nlflag) 342 if (nlflag)
305 { 343 {
306 int this_bol, prev_bol, dup; 344 int this_bol, prev_bol, dup;
307 insert_1 ("\n", 1, 1, 0); 345 insert_1 ("\n", 1, 1, 0);
308 346
348 oldzv -= min (pos, oldzv) - BEG; 386 oldzv -= min (pos, oldzv) - BEG;
349 del_range_1 (BEG, pos, 0); 387 del_range_1 (BEG, pos, 0);
350 } 388 }
351 } 389 }
352 BEGV = oldbegv; 390 BEGV = oldbegv;
353 ZV = oldzv; 391 if (zv_at_end)
354 TEMP_SET_PT (oldpoint); 392 ZV = Z;
393 else
394 ZV = oldzv;
395 if (point_at_end)
396 TEMP_SET_PT (Z);
397 else
398 TEMP_SET_PT (oldpoint);
355 set_buffer_internal (oldbuf); 399 set_buffer_internal (oldbuf);
356 windows_or_buffers_changed = old_windows_or_buffers_changed; 400 windows_or_buffers_changed = old_windows_or_buffers_changed;
357 message_log_need_newline = !nlflag; 401 message_log_need_newline = !nlflag;
358 } 402 }
359 } 403 }