aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorTom Tromey2013-08-19 21:53:07 -0600
committerTom Tromey2013-08-19 21:53:07 -0600
commit6d75555c5cc3d2a629646cee7629e67530fa7a36 (patch)
tree3852804dd234ad613ea8691332e10b92c027e87d /src/buffer.c
parentcc231cbe45d27a1906d268fb72d3b4105a2e9c65 (diff)
parent8c2f38aaab7a7a2f0605416fc2ee38701e41ab61 (diff)
downloademacs-6d75555c5cc3d2a629646cee7629e67530fa7a36.tar.gz
emacs-6d75555c5cc3d2a629646cee7629e67530fa7a36.zip
merge from trunk
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c94
1 files changed, 46 insertions, 48 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 3ca1bd98b29..8a1ad607e0b 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -106,9 +106,9 @@ static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
106static void swap_out_buffer_local_variables (struct buffer *b); 106static void swap_out_buffer_local_variables (struct buffer *b);
107static void reset_buffer_local_variables (struct buffer *, bool); 107static void reset_buffer_local_variables (struct buffer *, bool);
108 108
109/* Alist of all buffer names vs the buffers. */ 109/* Alist of all buffer names vs the buffers. This used to be
110/* This used to be a variable, but is no longer, 110 a Lisp-visible variable, but is no longer, to prevent lossage
111 to prevent lossage due to user rplac'ing this alist or its elements. */ 111 due to user rplac'ing this alist or its elements. */
112Lisp_Object Vbuffer_alist; 112Lisp_Object Vbuffer_alist;
113 113
114static Lisp_Object Qkill_buffer_query_functions; 114static Lisp_Object Qkill_buffer_query_functions;
@@ -201,9 +201,9 @@ bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val)
201 b->INTERNAL_FIELD (buffer_file_coding_system) = val; 201 b->INTERNAL_FIELD (buffer_file_coding_system) = val;
202} 202}
203static void 203static void
204bset_cache_long_line_scans (struct buffer *b, Lisp_Object val) 204bset_cache_long_scans (struct buffer *b, Lisp_Object val)
205{ 205{
206 b->INTERNAL_FIELD (cache_long_line_scans) = val; 206 b->INTERNAL_FIELD (cache_long_scans) = val;
207} 207}
208static void 208static void
209bset_case_fold_search (struct buffer *b, Lisp_Object val) 209bset_case_fold_search (struct buffer *b, Lisp_Object val)
@@ -476,8 +476,7 @@ If there is no such live buffer, return nil.
476See also `find-buffer-visiting'. */) 476See also `find-buffer-visiting'. */)
477 (register Lisp_Object filename) 477 (register Lisp_Object filename)
478{ 478{
479 register Lisp_Object tail, buf, tem; 479 register Lisp_Object tail, buf, handler;
480 Lisp_Object handler;
481 480
482 CHECK_STRING (filename); 481 CHECK_STRING (filename);
483 filename = Fexpand_file_name (filename, Qnil); 482 filename = Fexpand_file_name (filename, Qnil);
@@ -492,13 +491,10 @@ See also `find-buffer-visiting'. */)
492 return BUFFERP (handled_buf) ? handled_buf : Qnil; 491 return BUFFERP (handled_buf) ? handled_buf : Qnil;
493 } 492 }
494 493
495 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 494 FOR_EACH_LIVE_BUFFER (tail, buf)
496 { 495 {
497 buf = Fcdr (XCAR (tail));
498 if (!BUFFERP (buf)) continue;
499 if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue; 496 if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue;
500 tem = Fstring_equal (BVAR (XBUFFER (buf), filename), filename); 497 if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), filename), filename)))
501 if (!NILP (tem))
502 return buf; 498 return buf;
503 } 499 }
504 return Qnil; 500 return Qnil;
@@ -507,15 +503,12 @@ See also `find-buffer-visiting'. */)
507Lisp_Object 503Lisp_Object
508get_truename_buffer (register Lisp_Object filename) 504get_truename_buffer (register Lisp_Object filename)
509{ 505{
510 register Lisp_Object tail, buf, tem; 506 register Lisp_Object tail, buf;
511 507
512 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 508 FOR_EACH_LIVE_BUFFER (tail, buf)
513 { 509 {
514 buf = Fcdr (XCAR (tail));
515 if (!BUFFERP (buf)) continue;
516 if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue; 510 if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue;
517 tem = Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename); 511 if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename)))
518 if (!NILP (tem))
519 return buf; 512 return buf;
520 } 513 }
521 return Qnil; 514 return Qnil;
@@ -588,6 +581,7 @@ even if it is dead. The return value is never nil. */)
588 581
589 b->newline_cache = 0; 582 b->newline_cache = 0;
590 b->width_run_cache = 0; 583 b->width_run_cache = 0;
584 b->bidi_paragraph_cache = 0;
591 bset_width_table (b, Qnil); 585 bset_width_table (b, Qnil);
592 b->prevent_redisplay_optimizations_p = 1; 586 b->prevent_redisplay_optimizations_p = 1;
593 587
@@ -811,6 +805,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
811 805
812 b->newline_cache = 0; 806 b->newline_cache = 0;
813 b->width_run_cache = 0; 807 b->width_run_cache = 0;
808 b->bidi_paragraph_cache = 0;
814 bset_width_table (b, Qnil); 809 bset_width_table (b, Qnil);
815 810
816 name = Fcopy_sequence (name); 811 name = Fcopy_sequence (name);
@@ -1579,10 +1574,8 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1579 } 1574 }
1580 1575
1581 /* Consider alist of all buffers next. */ 1576 /* Consider alist of all buffers next. */
1582 tail = Vbuffer_alist; 1577 FOR_EACH_LIVE_BUFFER (tail, buf)
1583 for (; CONSP (tail); tail = XCDR (tail))
1584 { 1578 {
1585 buf = Fcdr (XCAR (tail));
1586 if (candidate_buffer (buf, buffer) 1579 if (candidate_buffer (buf, buffer)
1587 /* If the frame has a buffer_predicate, disregard buffers that 1580 /* If the frame has a buffer_predicate, disregard buffers that
1588 don't fit the predicate. */ 1581 don't fit the predicate. */
@@ -1619,12 +1612,9 @@ other_buffer_safely (Lisp_Object buffer)
1619{ 1612{
1620 Lisp_Object tail, buf; 1613 Lisp_Object tail, buf;
1621 1614
1622 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 1615 FOR_EACH_LIVE_BUFFER (tail, buf)
1623 { 1616 if (candidate_buffer (buf, buffer))
1624 buf = Fcdr (XCAR (tail)); 1617 return buf;
1625 if (candidate_buffer (buf, buffer))
1626 return buf;
1627 }
1628 1618
1629 buf = Fget_buffer (build_string ("*scratch*")); 1619 buf = Fget_buffer (build_string ("*scratch*"));
1630 if (NILP (buf)) 1620 if (NILP (buf))
@@ -1958,6 +1948,11 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1958 free_region_cache (b->width_run_cache); 1948 free_region_cache (b->width_run_cache);
1959 b->width_run_cache = 0; 1949 b->width_run_cache = 0;
1960 } 1950 }
1951 if (b->bidi_paragraph_cache)
1952 {
1953 free_region_cache (b->bidi_paragraph_cache);
1954 b->bidi_paragraph_cache = 0;
1955 }
1961 bset_width_table (b, Qnil); 1956 bset_width_table (b, Qnil);
1962 unblock_input (); 1957 unblock_input ();
1963 bset_undo_list (b, Qnil); 1958 bset_undo_list (b, Qnil);
@@ -2368,6 +2363,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2368 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2363 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
2369 swapfield (newline_cache, struct region_cache *); 2364 swapfield (newline_cache, struct region_cache *);
2370 swapfield (width_run_cache, struct region_cache *); 2365 swapfield (width_run_cache, struct region_cache *);
2366 swapfield (bidi_paragraph_cache, struct region_cache *);
2371 current_buffer->prevent_redisplay_optimizations_p = 1; 2367 current_buffer->prevent_redisplay_optimizations_p = 1;
2372 other_buffer->prevent_redisplay_optimizations_p = 1; 2368 other_buffer->prevent_redisplay_optimizations_p = 1;
2373 swapfield (overlays_before, struct Lisp_Overlay *); 2369 swapfield (overlays_before, struct Lisp_Overlay *);
@@ -2414,7 +2410,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2414 live window points to that window's buffer. So since we 2410 live window points to that window's buffer. So since we
2415 just swapped the markers between the two buffers, we need 2411 just swapped the markers between the two buffers, we need
2416 to undo the effect of this swap for window markers. */ 2412 to undo the effect of this swap for window markers. */
2417 Lisp_Object w = Fselected_window (), ws = Qnil; 2413 Lisp_Object w = selected_window, ws = Qnil;
2418 Lisp_Object buf1, buf2; 2414 Lisp_Object buf1, buf2;
2419 XSETBUFFER (buf1, current_buffer); XSETBUFFER (buf2, other_buffer); 2415 XSETBUFFER (buf1, current_buffer); XSETBUFFER (buf2, other_buffer);
2420 2416
@@ -3151,8 +3147,8 @@ struct sortvec
3151static int 3147static int
3152compare_overlays (const void *v1, const void *v2) 3148compare_overlays (const void *v1, const void *v2)
3153{ 3149{
3154 const struct sortvec *s1 = (const struct sortvec *) v1; 3150 const struct sortvec *s1 = v1;
3155 const struct sortvec *s2 = (const struct sortvec *) v2; 3151 const struct sortvec *s2 = v2;
3156 if (s1->priority != s2->priority) 3152 if (s1->priority != s2->priority)
3157 return s1->priority < s2->priority ? -1 : 1; 3153 return s1->priority < s2->priority ? -1 : 1;
3158 if (s1->beg != s2->beg) 3154 if (s1->beg != s2->beg)
@@ -3258,8 +3254,8 @@ static ptrdiff_t overlay_str_len;
3258static int 3254static int
3259cmp_for_strings (const void *as1, const void *as2) 3255cmp_for_strings (const void *as1, const void *as2)
3260{ 3256{
3261 struct sortstr *s1 = (struct sortstr *)as1; 3257 struct sortstr const *s1 = as1;
3262 struct sortstr *s2 = (struct sortstr *)as2; 3258 struct sortstr const *s2 = as2;
3263 if (s1->size != s2->size) 3259 if (s1->size != s2->size)
3264 return s2->size < s1->size ? -1 : 1; 3260 return s2->size < s1->size ? -1 : 1;
3265 if (s1->priority != s2->priority) 3261 if (s1->priority != s2->priority)
@@ -4757,7 +4753,7 @@ static struct mmap_region *
4757mmap_find (void *start, void *end) 4753mmap_find (void *start, void *end)
4758{ 4754{
4759 struct mmap_region *r; 4755 struct mmap_region *r;
4760 char *s = (char *) start, *e = (char *) end; 4756 char *s = start, *e = end;
4761 4757
4762 for (r = mmap_regions; r; r = r->next) 4758 for (r = mmap_regions; r; r = r->next)
4763 { 4759 {
@@ -4916,7 +4912,7 @@ mmap_alloc (void **var, size_t nbytes)
4916 } 4912 }
4917 else 4913 else
4918 { 4914 {
4919 struct mmap_region *r = (struct mmap_region *) p; 4915 struct mmap_region *r = p;
4920 4916
4921 r->nbytes_specified = nbytes; 4917 r->nbytes_specified = nbytes;
4922 r->nbytes_mapped = map; 4918 r->nbytes_mapped = map;
@@ -5056,7 +5052,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
5056 memory_full (nbytes); 5052 memory_full (nbytes);
5057 } 5053 }
5058 5054
5059 b->text->beg = (unsigned char *) p; 5055 b->text->beg = p;
5060 unblock_input (); 5056 unblock_input ();
5061} 5057}
5062 5058
@@ -5084,7 +5080,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5084 memory_full (nbytes); 5080 memory_full (nbytes);
5085 } 5081 }
5086 5082
5087 BUF_BEG_ADDR (b) = (unsigned char *) p; 5083 BUF_BEG_ADDR (b) = p;
5088 unblock_input (); 5084 unblock_input ();
5089} 5085}
5090 5086
@@ -5182,7 +5178,7 @@ init_buffer_once (void)
5182 bset_buffer_file_coding_system (&buffer_defaults, Qnil); 5178 bset_buffer_file_coding_system (&buffer_defaults, Qnil);
5183 XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); 5179 XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70);
5184 XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); 5180 XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0);
5185 bset_cache_long_line_scans (&buffer_defaults, Qnil); 5181 bset_cache_long_scans (&buffer_defaults, Qnil);
5186 bset_file_truename (&buffer_defaults, Qnil); 5182 bset_file_truename (&buffer_defaults, Qnil);
5187 XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); 5183 XSETFASTINT (BVAR (&buffer_defaults, display_count), 0);
5188 XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); 5184 XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0);
@@ -5246,7 +5242,7 @@ init_buffer_once (void)
5246 XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx; 5242 XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx;
5247 XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx; 5243 XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx;
5248 XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx; 5244 XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx;
5249 XSETFASTINT (BVAR (&buffer_local_flags, cache_long_line_scans), idx); ++idx; 5245 XSETFASTINT (BVAR (&buffer_local_flags, cache_long_scans), idx); ++idx;
5250 XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx; 5246 XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx;
5251 XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx); ++idx; 5247 XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx); ++idx;
5252 XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx); ++idx; 5248 XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx); ++idx;
@@ -5402,11 +5398,7 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring,
5402 bo_fwd->predicate = predicate; 5398 bo_fwd->predicate = predicate;
5403 sym->declared_special = 1; 5399 sym->declared_special = 1;
5404 sym->redirect = SYMBOL_FORWARDED; 5400 sym->redirect = SYMBOL_FORWARDED;
5405 { 5401 SET_SYMBOL_FWD (sym, (union Lisp_Fwd *) bo_fwd);
5406 /* I tried to do the job without a cast, but it seems impossible.
5407 union Lisp_Fwd *fwd; &(fwd->u_buffer_objfwd) = bo_fwd; */
5408 SET_SYMBOL_FWD (sym, (union Lisp_Fwd *)bo_fwd);
5409 }
5410 XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym); 5402 XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym);
5411 5403
5412 if (PER_BUFFER_IDX (offset) == 0) 5404 if (PER_BUFFER_IDX (offset) == 0)
@@ -6115,7 +6107,7 @@ An entry (apply FUN-NAME . ARGS) means undo the change with
6115 6107
6116An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo 6108An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo
6117in the active region. BEG and END is the range affected by this entry 6109in the active region. BEG and END is the range affected by this entry
6118and DELTA is the number of bytes added or deleted in that range by 6110and DELTA is the number of characters added or deleted in that range by
6119this change. 6111this change.
6120 6112
6121An entry (MARKER . DISTANCE) indicates that the marker MARKER 6113An entry (MARKER . DISTANCE) indicates that the marker MARKER
@@ -6133,8 +6125,8 @@ If the value of the variable is t, undo information is not recorded. */);
6133 DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil, 6125 DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil,
6134 doc: /* Non-nil means the mark and region are currently active in this buffer. */); 6126 doc: /* Non-nil means the mark and region are currently active in this buffer. */);
6135 6127
6136 DEFVAR_PER_BUFFER ("cache-long-line-scans", &BVAR (current_buffer, cache_long_line_scans), Qnil, 6128 DEFVAR_PER_BUFFER ("cache-long-scans", &BVAR (current_buffer, cache_long_scans), Qnil,
6137 doc: /* Non-nil means that Emacs should use caches to handle long lines more quickly. 6129 doc: /* Non-nil means that Emacs should use caches in attempt to speedup buffer scans.
6138 6130
6139Normally, the line-motion functions work by scanning the buffer for 6131Normally, the line-motion functions work by scanning the buffer for
6140newlines. Columnar operations (like `move-to-column' and 6132newlines. Columnar operations (like `move-to-column' and
@@ -6144,18 +6136,24 @@ buffer's lines are very long (say, more than 500 characters), these
6144motion functions will take longer to execute. Emacs may also take 6136motion functions will take longer to execute. Emacs may also take
6145longer to update the display. 6137longer to update the display.
6146 6138
6147If `cache-long-line-scans' is non-nil, these motion functions cache the 6139If `cache-long-scans' is non-nil, these motion functions cache the
6148results of their scans, and consult the cache to avoid rescanning 6140results of their scans, and consult the cache to avoid rescanning
6149regions of the buffer until the text is modified. The caches are most 6141regions of the buffer until the text is modified. The caches are most
6150beneficial when they prevent the most searching---that is, when the 6142beneficial when they prevent the most searching---that is, when the
6151buffer contains long lines and large regions of characters with the 6143buffer contains long lines and large regions of characters with the
6152same, fixed screen width. 6144same, fixed screen width.
6153 6145
6154When `cache-long-line-scans' is non-nil, processing short lines will 6146When `cache-long-scans' is non-nil, processing short lines will
6155become slightly slower (because of the overhead of consulting the 6147become slightly slower (because of the overhead of consulting the
6156cache), and the caches will use memory roughly proportional to the 6148cache), and the caches will use memory roughly proportional to the
6157number of newlines and characters whose screen width varies. 6149number of newlines and characters whose screen width varies.
6158 6150
6151Bidirectional editing also requires buffer scans to find paragraph
6152separators. If you have large paragraphs or no paragraph separators
6153at all, these scans may be slow. If `cache-long-scans' is non-nil,
6154results of these scans are cached. This doesn't help too much if
6155paragraphs are of the reasonable (few thousands of characters) size.
6156
6159The caches require no explicit maintenance; their accuracy is 6157The caches require no explicit maintenance; their accuracy is
6160maintained internally by the Emacs primitives. Enabling or disabling 6158maintained internally by the Emacs primitives. Enabling or disabling
6161the cache should not affect the behavior of any of the motion 6159the cache should not affect the behavior of any of the motion