aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorroot2013-08-12 12:27:22 +0200
committerroot2013-08-12 12:27:22 +0200
commitc39e73975f7371a6458cd63967d39ba77a1e871a (patch)
tree145fb3d8489ecd65ac6b1887e17a204bff751286 /src/buffer.c
parent2427b15992fe47646a2bf2b55891f1e482dedaa0 (diff)
parent6edea0a595d292c4d3f1a7e862195be07c874e40 (diff)
downloademacs-c39e73975f7371a6458cd63967d39ba77a1e871a.tar.gz
emacs-c39e73975f7371a6458cd63967d39ba77a1e871a.zip
merge from trunk
Conflicts: src/Makefile.in
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c92
1 files changed, 45 insertions, 47 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 063e02e8f6c..f6e61cd28ee 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -112,9 +112,9 @@ static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
112static void swap_out_buffer_local_variables (struct buffer *b); 112static void swap_out_buffer_local_variables (struct buffer *b);
113static void reset_buffer_local_variables (struct buffer *, bool); 113static void reset_buffer_local_variables (struct buffer *, bool);
114 114
115/* Alist of all buffer names vs the buffers. */ 115/* Alist of all buffer names vs the buffers. This used to be
116/* This used to be a variable, but is no longer, 116 a Lisp-visible variable, but is no longer, to prevent lossage
117 to prevent lossage due to user rplac'ing this alist or its elements. */ 117 due to user rplac'ing this alist or its elements. */
118Lisp_Object Vbuffer_alist; 118Lisp_Object Vbuffer_alist;
119 119
120static Lisp_Object Qkill_buffer_query_functions; 120static Lisp_Object Qkill_buffer_query_functions;
@@ -207,9 +207,9 @@ bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val)
207 b->INTERNAL_FIELD (buffer_file_coding_system) = val; 207 b->INTERNAL_FIELD (buffer_file_coding_system) = val;
208} 208}
209static void 209static void
210bset_cache_long_line_scans (struct buffer *b, Lisp_Object val) 210bset_cache_long_scans (struct buffer *b, Lisp_Object val)
211{ 211{
212 b->INTERNAL_FIELD (cache_long_line_scans) = val; 212 b->INTERNAL_FIELD (cache_long_scans) = val;
213} 213}
214static void 214static void
215bset_case_fold_search (struct buffer *b, Lisp_Object val) 215bset_case_fold_search (struct buffer *b, Lisp_Object val)
@@ -482,8 +482,7 @@ If there is no such live buffer, return nil.
482See also `find-buffer-visiting'. */) 482See also `find-buffer-visiting'. */)
483 (register Lisp_Object filename) 483 (register Lisp_Object filename)
484{ 484{
485 register Lisp_Object tail, buf, tem; 485 register Lisp_Object tail, buf, handler;
486 Lisp_Object handler;
487 486
488 CHECK_STRING (filename); 487 CHECK_STRING (filename);
489 filename = Fexpand_file_name (filename, Qnil); 488 filename = Fexpand_file_name (filename, Qnil);
@@ -498,13 +497,10 @@ See also `find-buffer-visiting'. */)
498 return BUFFERP (handled_buf) ? handled_buf : Qnil; 497 return BUFFERP (handled_buf) ? handled_buf : Qnil;
499 } 498 }
500 499
501 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 500 FOR_EACH_LIVE_BUFFER (tail, buf)
502 { 501 {
503 buf = Fcdr (XCAR (tail));
504 if (!BUFFERP (buf)) continue;
505 if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue; 502 if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue;
506 tem = Fstring_equal (BVAR (XBUFFER (buf), filename), filename); 503 if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), filename), filename)))
507 if (!NILP (tem))
508 return buf; 504 return buf;
509 } 505 }
510 return Qnil; 506 return Qnil;
@@ -513,15 +509,12 @@ See also `find-buffer-visiting'. */)
513Lisp_Object 509Lisp_Object
514get_truename_buffer (register Lisp_Object filename) 510get_truename_buffer (register Lisp_Object filename)
515{ 511{
516 register Lisp_Object tail, buf, tem; 512 register Lisp_Object tail, buf;
517 513
518 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 514 FOR_EACH_LIVE_BUFFER (tail, buf)
519 { 515 {
520 buf = Fcdr (XCAR (tail));
521 if (!BUFFERP (buf)) continue;
522 if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue; 516 if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue;
523 tem = Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename); 517 if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename)))
524 if (!NILP (tem))
525 return buf; 518 return buf;
526 } 519 }
527 return Qnil; 520 return Qnil;
@@ -594,6 +587,7 @@ even if it is dead. The return value is never nil. */)
594 587
595 b->newline_cache = 0; 588 b->newline_cache = 0;
596 b->width_run_cache = 0; 589 b->width_run_cache = 0;
590 b->bidi_paragraph_cache = 0;
597 bset_width_table (b, Qnil); 591 bset_width_table (b, Qnil);
598 b->prevent_redisplay_optimizations_p = 1; 592 b->prevent_redisplay_optimizations_p = 1;
599 593
@@ -817,6 +811,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
817 811
818 b->newline_cache = 0; 812 b->newline_cache = 0;
819 b->width_run_cache = 0; 813 b->width_run_cache = 0;
814 b->bidi_paragraph_cache = 0;
820 bset_width_table (b, Qnil); 815 bset_width_table (b, Qnil);
821 816
822 name = Fcopy_sequence (name); 817 name = Fcopy_sequence (name);
@@ -1585,10 +1580,8 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1585 } 1580 }
1586 1581
1587 /* Consider alist of all buffers next. */ 1582 /* Consider alist of all buffers next. */
1588 tail = Vbuffer_alist; 1583 FOR_EACH_LIVE_BUFFER (tail, buf)
1589 for (; CONSP (tail); tail = XCDR (tail))
1590 { 1584 {
1591 buf = Fcdr (XCAR (tail));
1592 if (candidate_buffer (buf, buffer) 1585 if (candidate_buffer (buf, buffer)
1593 /* If the frame has a buffer_predicate, disregard buffers that 1586 /* If the frame has a buffer_predicate, disregard buffers that
1594 don't fit the predicate. */ 1587 don't fit the predicate. */
@@ -1625,12 +1618,9 @@ other_buffer_safely (Lisp_Object buffer)
1625{ 1618{
1626 Lisp_Object tail, buf; 1619 Lisp_Object tail, buf;
1627 1620
1628 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 1621 FOR_EACH_LIVE_BUFFER (tail, buf)
1629 { 1622 if (candidate_buffer (buf, buffer))
1630 buf = Fcdr (XCAR (tail)); 1623 return buf;
1631 if (candidate_buffer (buf, buffer))
1632 return buf;
1633 }
1634 1624
1635 buf = Fget_buffer (build_string ("*scratch*")); 1625 buf = Fget_buffer (build_string ("*scratch*"));
1636 if (NILP (buf)) 1626 if (NILP (buf))
@@ -1966,6 +1956,11 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1966 free_region_cache (b->width_run_cache); 1956 free_region_cache (b->width_run_cache);
1967 b->width_run_cache = 0; 1957 b->width_run_cache = 0;
1968 } 1958 }
1959 if (b->bidi_paragraph_cache)
1960 {
1961 free_region_cache (b->bidi_paragraph_cache);
1962 b->bidi_paragraph_cache = 0;
1963 }
1969 bset_width_table (b, Qnil); 1964 bset_width_table (b, Qnil);
1970 unblock_input (); 1965 unblock_input ();
1971 bset_undo_list (b, Qnil); 1966 bset_undo_list (b, Qnil);
@@ -2376,6 +2371,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2376 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2371 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
2377 swapfield (newline_cache, struct region_cache *); 2372 swapfield (newline_cache, struct region_cache *);
2378 swapfield (width_run_cache, struct region_cache *); 2373 swapfield (width_run_cache, struct region_cache *);
2374 swapfield (bidi_paragraph_cache, struct region_cache *);
2379 current_buffer->prevent_redisplay_optimizations_p = 1; 2375 current_buffer->prevent_redisplay_optimizations_p = 1;
2380 other_buffer->prevent_redisplay_optimizations_p = 1; 2376 other_buffer->prevent_redisplay_optimizations_p = 1;
2381 swapfield (overlays_before, struct Lisp_Overlay *); 2377 swapfield (overlays_before, struct Lisp_Overlay *);
@@ -2422,7 +2418,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2422 live window points to that window's buffer. So since we 2418 live window points to that window's buffer. So since we
2423 just swapped the markers between the two buffers, we need 2419 just swapped the markers between the two buffers, we need
2424 to undo the effect of this swap for window markers. */ 2420 to undo the effect of this swap for window markers. */
2425 Lisp_Object w = Fselected_window (), ws = Qnil; 2421 Lisp_Object w = selected_window, ws = Qnil;
2426 Lisp_Object buf1, buf2; 2422 Lisp_Object buf1, buf2;
2427 XSETBUFFER (buf1, current_buffer); XSETBUFFER (buf2, other_buffer); 2423 XSETBUFFER (buf1, current_buffer); XSETBUFFER (buf2, other_buffer);
2428 2424
@@ -3159,8 +3155,8 @@ struct sortvec
3159static int 3155static int
3160compare_overlays (const void *v1, const void *v2) 3156compare_overlays (const void *v1, const void *v2)
3161{ 3157{
3162 const struct sortvec *s1 = (const struct sortvec *) v1; 3158 const struct sortvec *s1 = v1;
3163 const struct sortvec *s2 = (const struct sortvec *) v2; 3159 const struct sortvec *s2 = v2;
3164 if (s1->priority != s2->priority) 3160 if (s1->priority != s2->priority)
3165 return s1->priority < s2->priority ? -1 : 1; 3161 return s1->priority < s2->priority ? -1 : 1;
3166 if (s1->beg != s2->beg) 3162 if (s1->beg != s2->beg)
@@ -3266,8 +3262,8 @@ static ptrdiff_t overlay_str_len;
3266static int 3262static int
3267cmp_for_strings (const void *as1, const void *as2) 3263cmp_for_strings (const void *as1, const void *as2)
3268{ 3264{
3269 struct sortstr *s1 = (struct sortstr *)as1; 3265 struct sortstr const *s1 = as1;
3270 struct sortstr *s2 = (struct sortstr *)as2; 3266 struct sortstr const *s2 = as2;
3271 if (s1->size != s2->size) 3267 if (s1->size != s2->size)
3272 return s2->size < s1->size ? -1 : 1; 3268 return s2->size < s1->size ? -1 : 1;
3273 if (s1->priority != s2->priority) 3269 if (s1->priority != s2->priority)
@@ -4765,7 +4761,7 @@ static struct mmap_region *
4765mmap_find (void *start, void *end) 4761mmap_find (void *start, void *end)
4766{ 4762{
4767 struct mmap_region *r; 4763 struct mmap_region *r;
4768 char *s = (char *) start, *e = (char *) end; 4764 char *s = start, *e = end;
4769 4765
4770 for (r = mmap_regions; r; r = r->next) 4766 for (r = mmap_regions; r; r = r->next)
4771 { 4767 {
@@ -4924,7 +4920,7 @@ mmap_alloc (void **var, size_t nbytes)
4924 } 4920 }
4925 else 4921 else
4926 { 4922 {
4927 struct mmap_region *r = (struct mmap_region *) p; 4923 struct mmap_region *r = p;
4928 4924
4929 r->nbytes_specified = nbytes; 4925 r->nbytes_specified = nbytes;
4930 r->nbytes_mapped = map; 4926 r->nbytes_mapped = map;
@@ -5064,7 +5060,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
5064 memory_full (nbytes); 5060 memory_full (nbytes);
5065 } 5061 }
5066 5062
5067 b->text->beg = (unsigned char *) p; 5063 b->text->beg = p;
5068 unblock_input (); 5064 unblock_input ();
5069} 5065}
5070 5066
@@ -5092,7 +5088,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5092 memory_full (nbytes); 5088 memory_full (nbytes);
5093 } 5089 }
5094 5090
5095 BUF_BEG_ADDR (b) = (unsigned char *) p; 5091 BUF_BEG_ADDR (b) = p;
5096 unblock_input (); 5092 unblock_input ();
5097} 5093}
5098 5094
@@ -5190,7 +5186,7 @@ init_buffer_once (void)
5190 bset_buffer_file_coding_system (&buffer_defaults, Qnil); 5186 bset_buffer_file_coding_system (&buffer_defaults, Qnil);
5191 XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); 5187 XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70);
5192 XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); 5188 XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0);
5193 bset_cache_long_line_scans (&buffer_defaults, Qnil); 5189 bset_cache_long_scans (&buffer_defaults, Qnil);
5194 bset_file_truename (&buffer_defaults, Qnil); 5190 bset_file_truename (&buffer_defaults, Qnil);
5195 XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); 5191 XSETFASTINT (BVAR (&buffer_defaults, display_count), 0);
5196 XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); 5192 XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0);
@@ -5254,7 +5250,7 @@ init_buffer_once (void)
5254 XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx; 5250 XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx;
5255 XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx; 5251 XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx;
5256 XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx; 5252 XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx;
5257 XSETFASTINT (BVAR (&buffer_local_flags, cache_long_line_scans), idx); ++idx; 5253 XSETFASTINT (BVAR (&buffer_local_flags, cache_long_scans), idx); ++idx;
5258 XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx; 5254 XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx;
5259 XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx); ++idx; 5255 XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx); ++idx;
5260 XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx); ++idx; 5256 XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx); ++idx;
@@ -5410,11 +5406,7 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring,
5410 bo_fwd->predicate = predicate; 5406 bo_fwd->predicate = predicate;
5411 sym->declared_special = 1; 5407 sym->declared_special = 1;
5412 sym->redirect = SYMBOL_FORWARDED; 5408 sym->redirect = SYMBOL_FORWARDED;
5413 { 5409 SET_SYMBOL_FWD (sym, (union Lisp_Fwd *) bo_fwd);
5414 /* I tried to do the job without a cast, but it seems impossible.
5415 union Lisp_Fwd *fwd; &(fwd->u_buffer_objfwd) = bo_fwd; */
5416 SET_SYMBOL_FWD (sym, (union Lisp_Fwd *)bo_fwd);
5417 }
5418 XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym); 5410 XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym);
5419 5411
5420 if (PER_BUFFER_IDX (offset) == 0) 5412 if (PER_BUFFER_IDX (offset) == 0)
@@ -6141,8 +6133,8 @@ If the value of the variable is t, undo information is not recorded. */);
6141 DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil, 6133 DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil,
6142 doc: /* Non-nil means the mark and region are currently active in this buffer. */); 6134 doc: /* Non-nil means the mark and region are currently active in this buffer. */);
6143 6135
6144 DEFVAR_PER_BUFFER ("cache-long-line-scans", &BVAR (current_buffer, cache_long_line_scans), Qnil, 6136 DEFVAR_PER_BUFFER ("cache-long-scans", &BVAR (current_buffer, cache_long_scans), Qnil,
6145 doc: /* Non-nil means that Emacs should use caches to handle long lines more quickly. 6137 doc: /* Non-nil means that Emacs should use caches in attempt to speedup buffer scans.
6146 6138
6147Normally, the line-motion functions work by scanning the buffer for 6139Normally, the line-motion functions work by scanning the buffer for
6148newlines. Columnar operations (like `move-to-column' and 6140newlines. Columnar operations (like `move-to-column' and
@@ -6152,18 +6144,24 @@ buffer's lines are very long (say, more than 500 characters), these
6152motion functions will take longer to execute. Emacs may also take 6144motion functions will take longer to execute. Emacs may also take
6153longer to update the display. 6145longer to update the display.
6154 6146
6155If `cache-long-line-scans' is non-nil, these motion functions cache the 6147If `cache-long-scans' is non-nil, these motion functions cache the
6156results of their scans, and consult the cache to avoid rescanning 6148results of their scans, and consult the cache to avoid rescanning
6157regions of the buffer until the text is modified. The caches are most 6149regions of the buffer until the text is modified. The caches are most
6158beneficial when they prevent the most searching---that is, when the 6150beneficial when they prevent the most searching---that is, when the
6159buffer contains long lines and large regions of characters with the 6151buffer contains long lines and large regions of characters with the
6160same, fixed screen width. 6152same, fixed screen width.
6161 6153
6162When `cache-long-line-scans' is non-nil, processing short lines will 6154When `cache-long-scans' is non-nil, processing short lines will
6163become slightly slower (because of the overhead of consulting the 6155become slightly slower (because of the overhead of consulting the
6164cache), and the caches will use memory roughly proportional to the 6156cache), and the caches will use memory roughly proportional to the
6165number of newlines and characters whose screen width varies. 6157number of newlines and characters whose screen width varies.
6166 6158
6159Bidirectional editing also requires buffer scans to find paragraph
6160separators. If you have large paragraphs or no paragraph separators
6161at all, these scans may be slow. If `cache-long-scans' is non-nil,
6162results of these scans are cached. This doesn't help too much if
6163paragraphs are of the reasonable (few thousands of characters) size.
6164
6167The caches require no explicit maintenance; their accuracy is 6165The caches require no explicit maintenance; their accuracy is
6168maintained internally by the Emacs primitives. Enabling or disabling 6166maintained internally by the Emacs primitives. Enabling or disabling
6169the cache should not affect the behavior of any of the motion 6167the cache should not affect the behavior of any of the motion