aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-02-08 00:45:16 +0000
committerKarl Heuer1995-02-08 00:45:16 +0000
commitff6c30e51ee06eab216acce238c2dd46ecd29847 (patch)
treef3434f39a840b75857dcc740a8e1abc9e0ecb4b2
parent47cf9d3a96eb8290087971ef52b813f80e4df1e7 (diff)
downloademacs-ff6c30e51ee06eab216acce238c2dd46ecd29847.tar.gz
emacs-ff6c30e51ee06eab216acce238c2dd46ecd29847.zip
(message_log_check_duplicate): New function.
(message_dolog): Delete previous line if the new one is a duplicate. Include a counter if appropriate. Don't bother truncating the buffer until after adding newline.
-rw-r--r--src/xdisp.c91
1 files changed, 83 insertions, 8 deletions
diff --git a/src/xdisp.c b/src/xdisp.c
index a4ff8d25fc6..faf2271387c 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -148,6 +148,7 @@ int debug_end_pos;
148/* Nonzero means display mode line highlighted */ 148/* Nonzero means display mode line highlighted */
149int mode_line_inverse_video; 149int mode_line_inverse_video;
150 150
151static int message_log_check_duplicate ();
151static void echo_area_display (); 152static void echo_area_display ();
152void mark_window_display_accurate (); 153void mark_window_display_accurate ();
153static void redisplay_windows (); 154static void redisplay_windows ();
@@ -254,15 +255,52 @@ message_dolog (m, len, nlflag)
254 if (len) 255 if (len)
255 insert_1 (m, len, 1, 0); 256 insert_1 (m, len, 1, 0);
256 if (nlflag) 257 if (nlflag)
257 insert_1 ("\n", 1, 1, 0);
258 if (NATNUMP (Vmessage_log_max))
259 { 258 {
260 int pos = scan_buffer ('\n', PT, 0, 259 int this_bol, prev_bol, dup;
261 -XFASTINT (Vmessage_log_max) - 1, 0, 1); 260 insert_1 ("\n", 1, 1, 0);
262 oldpoint -= min (pos, oldpoint) - BEG; 261
263 oldbegv -= min (pos, oldbegv) - BEG; 262 this_bol = scan_buffer ('\n', Z, 0, -2, 0, 0);
264 oldzv -= min (pos, oldzv) - BEG; 263 if (this_bol > BEG)
265 del_range_1 (BEG, pos, 0); 264 {
265 prev_bol = scan_buffer ('\n', this_bol, 0, -2, 0, 0);
266 dup = message_log_check_duplicate (prev_bol, this_bol);
267 if (dup)
268 {
269 if (oldpoint > prev_bol)
270 oldpoint -= min (this_bol, oldpoint) - prev_bol;
271 if (oldbegv > prev_bol)
272 oldbegv -= min (this_bol, oldbegv) - prev_bol;
273 if (oldzv > prev_bol)
274 oldzv -= min (this_bol, oldzv) - prev_bol;
275 del_range_1 (prev_bol, this_bol, 0);
276 if (dup > 1)
277 {
278 char dupstr[40];
279 int duplen;
280
281 /* If you change this format, don't forget to also
282 change message_log_check_duplicate. */
283 sprintf (dupstr, " [%d times]", dup);
284 duplen = strlen (dupstr);
285 TEMP_SET_PT (Z-1);
286 if (oldpoint == Z)
287 oldpoint += duplen;
288 if (oldzv == Z)
289 oldzv += duplen;
290 insert_1 (dupstr, duplen, 1, 0);
291 }
292 }
293 }
294
295 if (NATNUMP (Vmessage_log_max))
296 {
297 int pos = scan_buffer ('\n', Z, 0,
298 -XFASTINT (Vmessage_log_max) - 1, 0, 0);
299 oldpoint -= min (pos, oldpoint) - BEG;
300 oldbegv -= min (pos, oldbegv) - BEG;
301 oldzv -= min (pos, oldzv) - BEG;
302 del_range_1 (BEG, pos, 0);
303 }
266 } 304 }
267 BEGV = oldbegv; 305 BEGV = oldbegv;
268 ZV = oldzv; 306 ZV = oldzv;
@@ -273,6 +311,43 @@ message_dolog (m, len, nlflag)
273} 311}
274 312
275 313
314/* We are at the end of the buffer after just having inserted a newline.
315 (Note: We depend on the fact we won't be crossing the gap.)
316 Check to see if the most recent message looks a lot like the previous one.
317 Return 0 if different, 1 if the new one should just replace it, or a
318 value N > 1 if we should also append " [N times]". */
319static int
320message_log_check_duplicate (prev_bol, this_bol)
321 int prev_bol, this_bol;
322{
323 int i;
324 int len = Z - 1 - this_bol;
325 int seen_dots = 0;
326 char *p1 = BUF_CHAR_ADDRESS (current_buffer, prev_bol);
327 char *p2 = BUF_CHAR_ADDRESS (current_buffer, this_bol);
328
329 for (i = 0; i < len; i++)
330 {
331 if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.'
332 && p1[i] != '\n')
333 seen_dots = 1;
334 if (p1[i] != p2[i])
335 return seen_dots;
336 }
337 p1 += len;
338 if (*p1 == '\n')
339 return 2;
340 if (*p1++ == ' ' && *p1++ == '[')
341 {
342 int n = 0;
343 while (*p1 >= '0' && *p1 <= '9')
344 n = n * 10 + *p1++ - '0';
345 if (strncmp (p1, " times]\n", 8) == 0)
346 return n+1;
347 }
348 return 0;
349}
350
276/* Display an echo area message M with a specified length of LEN chars. 351/* Display an echo area message M with a specified length of LEN chars.
277 The string may include null characters. If m is 0, clear out any 352 The string may include null characters. If m is 0, clear out any
278 existing message, and let the minibuffer text show through. 353 existing message, and let the minibuffer text show through.