aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2013-01-09 17:50:22 +0400
committerDmitry Antipov2013-01-09 17:50:22 +0400
commiteefd727851555237c7bc205b7ad255c50ba3fff9 (patch)
tree5009d8d2c8773c64504252c8e8738f14b84d2547 /src
parentccd04887a3f15ce0e52af801d8a70c91d695f78c (diff)
downloademacs-eefd727851555237c7bc205b7ad255c50ba3fff9.tar.gz
emacs-eefd727851555237c7bc205b7ad255c50ba3fff9.zip
* lisp.h (make_gap_1): New prototype.
* buffer.h (GAP_BYTES_DFL, GAP_BYTES_MIN): New macros for the special gap size values. * editfns.c (Fbuffer_size): Rename from Fbufsize to fit the common naming convention. (syms_of_editfns): Adjust defsubr. Drop commented-out obsolete code. * insdel.c (make_gap_larger): Use GAP_BYTES_DFL. (make_gap_smaller): Use GAP_BYTES_MIN. Adjust comment. (make_gap_1): New function to adjust the gap of any buffer. * coding.c (coding_alloc_by_making_gap): Use it. * buffer.c (compact_buffer): Likewise. Use BUF_Z_BYTE, BUF_GAP_SIZE, GAP_BYTES_DFL and GAP_BYTES_MIN. Adjust comment.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog15
-rw-r--r--src/buffer.c18
-rw-r--r--src/buffer.h10
-rw-r--r--src/coding.c9
-rw-r--r--src/editfns.c6
-rw-r--r--src/insdel.c24
-rw-r--r--src/lisp.h1
7 files changed, 54 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c60fa701385..b2a4845c336 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,18 @@
12013-01-09 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * lisp.h (make_gap_1): New prototype.
4 * buffer.h (GAP_BYTES_DFL, GAP_BYTES_MIN): New macros for the special
5 gap size values.
6 * editfns.c (Fbuffer_size): Rename from Fbufsize to fit the common
7 naming convention.
8 (syms_of_editfns): Adjust defsubr. Drop commented-out obsolete code.
9 * insdel.c (make_gap_larger): Use GAP_BYTES_DFL.
10 (make_gap_smaller): Use GAP_BYTES_MIN. Adjust comment.
11 (make_gap_1): New function to adjust the gap of any buffer.
12 * coding.c (coding_alloc_by_making_gap): Use it.
13 * buffer.c (compact_buffer): Likewise. Use BUF_Z_BYTE, BUF_GAP_SIZE,
14 GAP_BYTES_DFL and GAP_BYTES_MIN. Adjust comment.
15
12013-01-08 Juri Linkov <juri@jurta.org> 162013-01-08 Juri Linkov <juri@jurta.org>
2 17
3 * xfaces.c (tty_supports_face_attributes_p): Return 0 for the case 18 * xfaces.c (tty_supports_face_attributes_p): Return 0 for the case
diff --git a/src/buffer.c b/src/buffer.c
index 5999fcb7e7d..51c4d9c71da 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1682,17 +1682,13 @@ compact_buffer (struct buffer *buffer)
1682 if (!buffer->text->inhibit_shrinking) 1682 if (!buffer->text->inhibit_shrinking)
1683 { 1683 {
1684 /* If a buffer's gap size is more than 10% of the buffer 1684 /* If a buffer's gap size is more than 10% of the buffer
1685 size, or larger than 2000 bytes, then shrink it 1685 size, or larger than GAP_BYTES_DFL bytes, then shrink it
1686 accordingly. Keep a minimum size of 20 bytes. */ 1686 accordingly. Keep a minimum size of GAP_BYTES_MIN bytes. */
1687 int size = min (2000, max (20, (buffer->text->z_byte / 10))); 1687 ptrdiff_t size = clip_to_bounds (GAP_BYTES_MIN,
1688 1688 BUF_Z_BYTE (buffer) / 10,
1689 if (buffer->text->gap_size > size) 1689 GAP_BYTES_DFL);
1690 { 1690 if (BUF_GAP_SIZE (buffer) > size)
1691 struct buffer *save_current = current_buffer; 1691 make_gap_1 (buffer, -(BUF_GAP_SIZE (buffer) - size));
1692 current_buffer = buffer;
1693 make_gap (-(buffer->text->gap_size - size));
1694 current_buffer = save_current;
1695 }
1696 } 1692 }
1697 BUF_COMPACT (buffer) = BUF_MODIFF (buffer); 1693 BUF_COMPACT (buffer) = BUF_MODIFF (buffer);
1698 } 1694 }
diff --git a/src/buffer.h b/src/buffer.h
index eb6a9d4d3e1..ec9c34b3eb3 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -320,6 +320,16 @@ while (0)
320#define BUF_BYTES_MAX \ 320#define BUF_BYTES_MAX \
321 (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX)) 321 (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
322 322
323/* Maximum gap size after compact_buffer, in bytes. Also
324 used in make_gap_larger to get some extra reserved space. */
325
326#define GAP_BYTES_DFL 2000
327
328/* Minimum gap size after compact_buffer, in bytes. Also
329 used in make_gap_smaller to avoid too small gap size. */
330
331#define GAP_BYTES_MIN 20
332
323/* Return the address of byte position N in current buffer. */ 333/* Return the address of byte position N in current buffer. */
324 334
325#define BYTE_POS_ADDR(n) \ 335#define BYTE_POS_ADDR(n) \
diff --git a/src/coding.c b/src/coding.c
index 5285a906823..a9bf9032a69 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -1049,14 +1049,7 @@ coding_alloc_by_making_gap (struct coding_system *coding,
1049 GPT -= gap_head_used, GPT_BYTE -= gap_head_used; 1049 GPT -= gap_head_used, GPT_BYTE -= gap_head_used;
1050 } 1050 }
1051 else 1051 else
1052 { 1052 make_gap_1 (XBUFFER (coding->dst_object), bytes);
1053 Lisp_Object this_buffer;
1054
1055 this_buffer = Fcurrent_buffer ();
1056 set_buffer_internal (XBUFFER (coding->dst_object));
1057 make_gap (bytes);
1058 set_buffer_internal (XBUFFER (this_buffer));
1059 }
1060} 1053}
1061 1054
1062 1055
diff --git a/src/editfns.c b/src/editfns.c
index df0dad0669d..26dfdac3ba8 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -968,7 +968,7 @@ usage: (save-current-buffer &rest BODY) */)
968 return unbind_to (count, Fprogn (args)); 968 return unbind_to (count, Fprogn (args));
969} 969}
970 970
971DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0, 971DEFUN ("buffer-size", Fbuffer_size, Sbuffer_size, 0, 1, 0,
972 doc: /* Return the number of characters in the current buffer. 972 doc: /* Return the number of characters in the current buffer.
973If BUFFER, return the number of characters in that buffer instead. */) 973If BUFFER, return the number of characters in that buffer instead. */)
974 (Lisp_Object buffer) 974 (Lisp_Object buffer)
@@ -4883,12 +4883,10 @@ functions if all the text being accessed has this property. */);
4883 defsubr (&Sline_beginning_position); 4883 defsubr (&Sline_beginning_position);
4884 defsubr (&Sline_end_position); 4884 defsubr (&Sline_end_position);
4885 4885
4886/* defsubr (&Smark); */
4887/* defsubr (&Sset_mark); */
4888 defsubr (&Ssave_excursion); 4886 defsubr (&Ssave_excursion);
4889 defsubr (&Ssave_current_buffer); 4887 defsubr (&Ssave_current_buffer);
4890 4888
4891 defsubr (&Sbufsize); 4889 defsubr (&Sbuffer_size);
4892 defsubr (&Spoint_max); 4890 defsubr (&Spoint_max);
4893 defsubr (&Spoint_min); 4891 defsubr (&Spoint_min);
4894 defsubr (&Spoint_min_marker); 4892 defsubr (&Spoint_min_marker);
diff --git a/src/insdel.c b/src/insdel.c
index 52a017a62a2..68b3eddb30b 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -388,14 +388,13 @@ make_gap_larger (ptrdiff_t nbytes_added)
388 ptrdiff_t real_gap_loc_byte; 388 ptrdiff_t real_gap_loc_byte;
389 ptrdiff_t old_gap_size; 389 ptrdiff_t old_gap_size;
390 ptrdiff_t current_size = Z_BYTE - BEG_BYTE + GAP_SIZE; 390 ptrdiff_t current_size = Z_BYTE - BEG_BYTE + GAP_SIZE;
391 enum { enough_for_a_while = 2000 };
392 391
393 if (BUF_BYTES_MAX - current_size < nbytes_added) 392 if (BUF_BYTES_MAX - current_size < nbytes_added)
394 buffer_overflow (); 393 buffer_overflow ();
395 394
396 /* If we have to get more space, get enough to last a while; 395 /* If we have to get more space, get enough to last a while;
397 but do not exceed the maximum buffer size. */ 396 but do not exceed the maximum buffer size. */
398 nbytes_added = min (nbytes_added + enough_for_a_while, 397 nbytes_added = min (nbytes_added + GAP_BYTES_DFL,
399 BUF_BYTES_MAX - current_size); 398 BUF_BYTES_MAX - current_size);
400 399
401 enlarge_buffer_text (current_buffer, nbytes_added); 400 enlarge_buffer_text (current_buffer, nbytes_added);
@@ -443,9 +442,9 @@ make_gap_smaller (ptrdiff_t nbytes_removed)
443 ptrdiff_t real_beg_unchanged; 442 ptrdiff_t real_beg_unchanged;
444 ptrdiff_t new_gap_size; 443 ptrdiff_t new_gap_size;
445 444
446 /* Make sure the gap is at least 20 bytes. */ 445 /* Make sure the gap is at least GAP_BYTES_MIN bytes. */
447 if (GAP_SIZE - nbytes_removed < 20) 446 if (GAP_SIZE - nbytes_removed < GAP_BYTES_MIN)
448 nbytes_removed = GAP_SIZE - 20; 447 nbytes_removed = GAP_SIZE - GAP_BYTES_MIN;
449 448
450 /* Prevent quitting in move_gap. */ 449 /* Prevent quitting in move_gap. */
451 tem = Vinhibit_quit; 450 tem = Vinhibit_quit;
@@ -500,7 +499,20 @@ make_gap (ptrdiff_t nbytes_added)
500 make_gap_smaller (-nbytes_added); 499 make_gap_smaller (-nbytes_added);
501#endif 500#endif
502} 501}
503 502
503/* Add NBYTES to B's gap. It's enough to temporarily
504 fake current_buffer and avoid real switch to B. */
505
506void
507make_gap_1 (struct buffer *b, ptrdiff_t nbytes)
508{
509 struct buffer *oldb = current_buffer;
510
511 current_buffer = b;
512 make_gap (nbytes);
513 current_buffer = oldb;
514}
515
504/* Copy NBYTES bytes of text from FROM_ADDR to TO_ADDR. 516/* Copy NBYTES bytes of text from FROM_ADDR to TO_ADDR.
505 FROM_MULTIBYTE says whether the incoming text is multibyte. 517 FROM_MULTIBYTE says whether the incoming text is multibyte.
506 TO_MULTIBYTE says whether to store the text as multibyte. 518 TO_MULTIBYTE says whether to store the text as multibyte.
diff --git a/src/lisp.h b/src/lisp.h
index e22241f6b2c..a0dcc9ab5f3 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2778,6 +2778,7 @@ extern void move_gap (ptrdiff_t);
2778extern void move_gap_both (ptrdiff_t, ptrdiff_t); 2778extern void move_gap_both (ptrdiff_t, ptrdiff_t);
2779extern _Noreturn void buffer_overflow (void); 2779extern _Noreturn void buffer_overflow (void);
2780extern void make_gap (ptrdiff_t); 2780extern void make_gap (ptrdiff_t);
2781extern void make_gap_1 (struct buffer *, ptrdiff_t);
2781extern ptrdiff_t copy_text (const unsigned char *, unsigned char *, 2782extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
2782 ptrdiff_t, bool, bool); 2783 ptrdiff_t, bool, bool);
2783extern int count_combining_before (const unsigned char *, 2784extern int count_combining_before (const unsigned char *,