aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c98
1 files changed, 51 insertions, 47 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 0e2e50d9f51..b020edb9962 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -26,7 +26,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include <sys/param.h> 26#include <sys/param.h>
27#include <errno.h> 27#include <errno.h>
28#include <stdio.h> 28#include <stdio.h>
29#include <setjmp.h>
30#include <unistd.h> 29#include <unistd.h>
31 30
32#include <verify.h> 31#include <verify.h>
@@ -44,7 +43,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
44#include "keymap.h" 43#include "keymap.h"
45#include "frame.h" 44#include "frame.h"
46 45
47struct buffer *current_buffer; /* the current buffer */ 46struct buffer *current_buffer; /* The current buffer. */
48 47
49/* First buffer in chain of all buffers (in reverse order of creation). 48/* First buffer in chain of all buffers (in reverse order of creation).
50 Threaded through ->header.next.buffer. */ 49 Threaded through ->header.next.buffer. */
@@ -60,10 +59,6 @@ struct buffer *all_buffers;
60 59
61struct buffer alignas (GCALIGNMENT) buffer_defaults; 60struct buffer alignas (GCALIGNMENT) buffer_defaults;
62 61
63/* A Lisp_Object pointer to the above, used for staticpro */
64
65static Lisp_Object Vbuffer_defaults;
66
67/* This structure marks which slots in a buffer have corresponding 62/* This structure marks which slots in a buffer have corresponding
68 default values in buffer_defaults. 63 default values in buffer_defaults.
69 Each such slot has a nonzero value in this structure. 64 Each such slot has a nonzero value in this structure.
@@ -78,18 +73,15 @@ static Lisp_Object Vbuffer_defaults;
78 and the corresponding slot in buffer_defaults is not used. 73 and the corresponding slot in buffer_defaults is not used.
79 74
80 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is 75 If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
81 zero, that is a bug */ 76 zero, that is a bug. */
82 77
83struct buffer buffer_local_flags; 78struct buffer buffer_local_flags;
84 79
85/* This structure holds the names of symbols whose values may be 80/* This structure holds the names of symbols whose values may be
86 buffer-local. It is indexed and accessed in the same way as the above. */ 81 buffer-local. It is indexed and accessed in the same way as the above. */
87 82
88struct buffer alignas (GCALIGNMENT) buffer_local_symbols; 83struct buffer alignas (GCALIGNMENT) buffer_local_symbols;
89 84
90/* A Lisp_Object pointer to the above, used for staticpro */
91static Lisp_Object Vbuffer_local_symbols;
92
93/* Return the symbol of the per-buffer variable at offset OFFSET in 85/* Return the symbol of the per-buffer variable at offset OFFSET in
94 the buffer structure. */ 86 the buffer structure. */
95 87
@@ -115,7 +107,7 @@ static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
115static void swap_out_buffer_local_variables (struct buffer *b); 107static void swap_out_buffer_local_variables (struct buffer *b);
116static void reset_buffer_local_variables (struct buffer *, bool); 108static void reset_buffer_local_variables (struct buffer *, bool);
117 109
118/* Alist of all buffer names vs the buffers. */ 110/* Alist of all buffer names vs the buffers. */
119/* This used to be a variable, but is no longer, 111/* This used to be a variable, but is no longer,
120 to prevent lossage due to user rplac'ing this alist or its elements. */ 112 to prevent lossage due to user rplac'ing this alist or its elements. */
121Lisp_Object Vbuffer_alist; 113Lisp_Object Vbuffer_alist;
@@ -134,7 +126,7 @@ static Lisp_Object Qpermanent_local_hook;
134 126
135static Lisp_Object Qprotected_field; 127static Lisp_Object Qprotected_field;
136 128
137static Lisp_Object QSFundamental; /* A string "Fundamental" */ 129static Lisp_Object QSFundamental; /* A string "Fundamental". */
138 130
139static Lisp_Object Qkill_buffer_hook; 131static Lisp_Object Qkill_buffer_hook;
140static Lisp_Object Qbuffer_list_update_hook; 132static Lisp_Object Qbuffer_list_update_hook;
@@ -395,7 +387,7 @@ DEFUN ("buffer-live-p", Fbuffer_live_p, Sbuffer_live_p, 1, 1, 0,
395Value is nil if OBJECT is not a buffer or if it has been killed. */) 387Value is nil if OBJECT is not a buffer or if it has been killed. */)
396 (Lisp_Object object) 388 (Lisp_Object object)
397{ 389{
398 return ((BUFFERP (object) && ! NILP (BVAR (XBUFFER (object), name))) 390 return ((BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)))
399 ? Qt : Qnil); 391 ? Qt : Qnil);
400} 392}
401 393
@@ -595,10 +587,6 @@ even if it is dead. The return value is never nil. */)
595 bset_width_table (b, Qnil); 587 bset_width_table (b, Qnil);
596 b->prevent_redisplay_optimizations_p = 1; 588 b->prevent_redisplay_optimizations_p = 1;
597 589
598 /* Put this on the chain of all buffers including killed ones. */
599 b->header.next.buffer = all_buffers;
600 all_buffers = b;
601
602 /* An ordinary buffer normally doesn't need markers 590 /* An ordinary buffer normally doesn't need markers
603 to handle BEGV and ZV. */ 591 to handle BEGV and ZV. */
604 bset_pt_marker (b, Qnil); 592 bset_pt_marker (b, Qnil);
@@ -787,7 +775,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
787 base_buffer = Fget_buffer (base_buffer); 775 base_buffer = Fget_buffer (base_buffer);
788 if (NILP (base_buffer)) 776 if (NILP (base_buffer))
789 error ("No such buffer: `%s'", SDATA (tem)); 777 error ("No such buffer: `%s'", SDATA (tem));
790 if (NILP (BVAR (XBUFFER (base_buffer), name))) 778 if (!BUFFER_LIVE_P (XBUFFER (base_buffer)))
791 error ("Base buffer has been killed"); 779 error ("Base buffer has been killed");
792 780
793 if (SCHARS (name) == 0) 781 if (SCHARS (name) == 0)
@@ -819,10 +807,6 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
819 b->width_run_cache = 0; 807 b->width_run_cache = 0;
820 bset_width_table (b, Qnil); 808 bset_width_table (b, Qnil);
821 809
822 /* Put this on the chain of all buffers including killed ones. */
823 b->header.next.buffer = all_buffers;
824 all_buffers = b;
825
826 name = Fcopy_sequence (name); 810 name = Fcopy_sequence (name);
827 set_string_intervals (name, NULL); 811 set_string_intervals (name, NULL);
828 bset_name (b, name); 812 bset_name (b, name);
@@ -1242,7 +1226,7 @@ buffer_local_value_1 (Lisp_Object variable, Lisp_Object buffer)
1242 result = Fdefault_value (variable); 1226 result = Fdefault_value (variable);
1243 break; 1227 break;
1244 } 1228 }
1245 default: abort (); 1229 default: emacs_abort ();
1246 } 1230 }
1247 1231
1248 return result; 1232 return result;
@@ -1568,7 +1552,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1568 { 1552 {
1569 buf = XCAR (tail); 1553 buf = XCAR (tail);
1570 if (BUFFERP (buf) && !EQ (buf, buffer) 1554 if (BUFFERP (buf) && !EQ (buf, buffer)
1571 && !NILP (BVAR (XBUFFER (buf), name)) 1555 && BUFFER_LIVE_P (XBUFFER (buf))
1572 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ') 1556 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
1573 /* If the frame has a buffer_predicate, disregard buffers that 1557 /* If the frame has a buffer_predicate, disregard buffers that
1574 don't fit the predicate. */ 1558 don't fit the predicate. */
@@ -1588,7 +1572,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1588 { 1572 {
1589 buf = Fcdr (XCAR (tail)); 1573 buf = Fcdr (XCAR (tail));
1590 if (BUFFERP (buf) && !EQ (buf, buffer) 1574 if (BUFFERP (buf) && !EQ (buf, buffer)
1591 && !NILP (BVAR (XBUFFER (buf), name)) 1575 && BUFFER_LIVE_P (XBUFFER (buf))
1592 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ') 1576 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')
1593 /* If the frame has a buffer_predicate, disregard buffers that 1577 /* If the frame has a buffer_predicate, disregard buffers that
1594 don't fit the predicate. */ 1578 don't fit the predicate. */
@@ -1630,7 +1614,7 @@ other_buffer_safely (Lisp_Object buffer)
1630 { 1614 {
1631 buf = Fcdr (XCAR (tail)); 1615 buf = Fcdr (XCAR (tail));
1632 if (BUFFERP (buf) && !EQ (buf, buffer) 1616 if (BUFFERP (buf) && !EQ (buf, buffer)
1633 && !NILP (BVAR (XBUFFER (buf), name)) 1617 && BUFFER_LIVE_P (XBUFFER (buf))
1634 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')) 1618 && (SREF (BVAR (XBUFFER (buf), name), 0) != ' '))
1635 return buf; 1619 return buf;
1636 } 1620 }
@@ -1749,7 +1733,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1749 b = XBUFFER (buffer); 1733 b = XBUFFER (buffer);
1750 1734
1751 /* Avoid trouble for buffer already dead. */ 1735 /* Avoid trouble for buffer already dead. */
1752 if (NILP (BVAR (b, name))) 1736 if (!BUFFER_LIVE_P (b))
1753 return Qnil; 1737 return Qnil;
1754 1738
1755 /* Query if the buffer is still modified. */ 1739 /* Query if the buffer is still modified. */
@@ -1785,7 +1769,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1785 } 1769 }
1786 1770
1787 /* If the hooks have killed the buffer, exit now. */ 1771 /* If the hooks have killed the buffer, exit now. */
1788 if (NILP (BVAR (b, name))) 1772 if (!BUFFER_LIVE_P (b))
1789 return Qt; 1773 return Qt;
1790 1774
1791 /* We have no more questions to ask. Verify that it is valid 1775 /* We have no more questions to ask. Verify that it is valid
@@ -1817,7 +1801,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1817 UNGCPRO; 1801 UNGCPRO;
1818 1802
1819 /* Exit if we now have killed the base buffer (Bug#11665). */ 1803 /* Exit if we now have killed the base buffer (Bug#11665). */
1820 if (NILP (BVAR (b, name))) 1804 if (!BUFFER_LIVE_P (b))
1821 return Qt; 1805 return Qt;
1822 } 1806 }
1823 1807
@@ -1828,7 +1812,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1828 replace_buffer_in_windows (buffer); 1812 replace_buffer_in_windows (buffer);
1829 1813
1830 /* Exit if replacing the buffer in windows has killed our buffer. */ 1814 /* Exit if replacing the buffer in windows has killed our buffer. */
1831 if (NILP (BVAR (b, name))) 1815 if (!BUFFER_LIVE_P (b))
1832 return Qt; 1816 return Qt;
1833 1817
1834 /* Make this buffer not be current. Exit if it is the sole visible 1818 /* Make this buffer not be current. Exit if it is the sole visible
@@ -1861,7 +1845,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1861 1845
1862 /* Killing buffer processes may run sentinels which may have killed 1846 /* Killing buffer processes may run sentinels which may have killed
1863 our buffer. */ 1847 our buffer. */
1864 if (NILP (BVAR (b, name))) 1848 if (!BUFFER_LIVE_P (b))
1865 return Qt; 1849 return Qt;
1866 1850
1867 /* These may run Lisp code and into infinite loops (if someone 1851 /* These may run Lisp code and into infinite loops (if someone
@@ -1893,7 +1877,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1893 } 1877 }
1894 1878
1895 /* Deleting an auto-save file could have killed our buffer. */ 1879 /* Deleting an auto-save file could have killed our buffer. */
1896 if (NILP (BVAR (b, name))) 1880 if (!BUFFER_LIVE_P (b))
1897 return Qt; 1881 return Qt;
1898 1882
1899 if (b->base_buffer) 1883 if (b->base_buffer)
@@ -2062,7 +2046,7 @@ the current buffer's major mode. */)
2062 2046
2063 CHECK_BUFFER (buffer); 2047 CHECK_BUFFER (buffer);
2064 2048
2065 if (NILP (BVAR (XBUFFER (buffer), name))) 2049 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
2066 error ("Attempt to set major mode for a dead buffer"); 2050 error ("Attempt to set major mode for a dead buffer");
2067 2051
2068 if (strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0) 2052 if (strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0)
@@ -2198,7 +2182,7 @@ ends when the current command terminates. Use `switch-to-buffer' or
2198 buffer = Fget_buffer (buffer_or_name); 2182 buffer = Fget_buffer (buffer_or_name);
2199 if (NILP (buffer)) 2183 if (NILP (buffer))
2200 nsberror (buffer_or_name); 2184 nsberror (buffer_or_name);
2201 if (NILP (BVAR (XBUFFER (buffer), name))) 2185 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
2202 error ("Selecting deleted buffer"); 2186 error ("Selecting deleted buffer");
2203 set_buffer_internal (XBUFFER (buffer)); 2187 set_buffer_internal (XBUFFER (buffer));
2204 return buffer; 2188 return buffer;
@@ -2209,7 +2193,7 @@ ends when the current command terminates. Use `switch-to-buffer' or
2209Lisp_Object 2193Lisp_Object
2210set_buffer_if_live (Lisp_Object buffer) 2194set_buffer_if_live (Lisp_Object buffer)
2211{ 2195{
2212 if (! NILP (BVAR (XBUFFER (buffer), name))) 2196 if (BUFFER_LIVE_P (XBUFFER (buffer)))
2213 set_buffer_internal (XBUFFER (buffer)); 2197 set_buffer_internal (XBUFFER (buffer));
2214 return Qnil; 2198 return Qnil;
2215} 2199}
@@ -2304,7 +2288,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2304 CHECK_BUFFER (buffer); 2288 CHECK_BUFFER (buffer);
2305 other_buffer = XBUFFER (buffer); 2289 other_buffer = XBUFFER (buffer);
2306 2290
2307 if (NILP (BVAR (other_buffer, name))) 2291 if (!BUFFER_LIVE_P (other_buffer))
2308 error ("Cannot swap a dead buffer's text"); 2292 error ("Cannot swap a dead buffer's text");
2309 2293
2310 /* Actually, it probably works just fine. 2294 /* Actually, it probably works just fine.
@@ -2671,7 +2655,7 @@ current buffer is cleared. */)
2671 /* Make sure no markers were put on the chain 2655 /* Make sure no markers were put on the chain
2672 while the chain value was incorrect. */ 2656 while the chain value was incorrect. */
2673 if (BUF_MARKERS (current_buffer)) 2657 if (BUF_MARKERS (current_buffer))
2674 abort (); 2658 emacs_abort ();
2675 2659
2676 BUF_MARKERS (current_buffer) = markers; 2660 BUF_MARKERS (current_buffer) = markers;
2677 2661
@@ -2700,7 +2684,7 @@ current buffer is cleared. */)
2700 /* Copy this buffer's new multibyte status 2684 /* Copy this buffer's new multibyte status
2701 into all of its indirect buffers. */ 2685 into all of its indirect buffers. */
2702 FOR_EACH_BUFFER (other) 2686 FOR_EACH_BUFFER (other)
2703 if (other->base_buffer == current_buffer && !NILP (BVAR (other, name))) 2687 if (other->base_buffer == current_buffer && BUFFER_LIVE_P (other))
2704 { 2688 {
2705 BVAR (other, enable_multibyte_characters) 2689 BVAR (other, enable_multibyte_characters)
2706 = BVAR (current_buffer, enable_multibyte_characters); 2690 = BVAR (current_buffer, enable_multibyte_characters);
@@ -3413,7 +3397,7 @@ overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr)
3413 } 3397 }
3414 } 3398 }
3415 if (p != overlay_str_buf + total) 3399 if (p != overlay_str_buf + total)
3416 abort (); 3400 emacs_abort ();
3417 if (pstr) 3401 if (pstr)
3418 *pstr = overlay_str_buf; 3402 *pstr = overlay_str_buf;
3419 return total; 3403 return total;
@@ -4073,6 +4057,26 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
4073 4057
4074 return unbind_to (count, Qnil); 4058 return unbind_to (count, Qnil);
4075} 4059}
4060
4061DEFUN ("delete-all-overlays", Fdelete_all_overlays, Sdelete_all_overlays, 0, 1, 0,
4062 doc: /* Delete all overlays of BUFFER.
4063BUFFER omitted or nil means delete all overlays of the current
4064buffer. */)
4065 (Lisp_Object buffer)
4066{
4067 register struct buffer *buf;
4068
4069 if (NILP (buffer))
4070 buf = current_buffer;
4071 else
4072 {
4073 CHECK_BUFFER (buffer);
4074 buf = XBUFFER (buffer);
4075 }
4076
4077 delete_all_overlays (buf);
4078 return Qnil;
4079}
4076 4080
4077/* Overlay dissection functions. */ 4081/* Overlay dissection functions. */
4078 4082
@@ -4576,7 +4580,7 @@ buffer_slot_type_mismatch (Lisp_Object newval, int type)
4576 case_Lisp_Int: predicate = Qintegerp; break; 4580 case_Lisp_Int: predicate = Qintegerp; break;
4577 case Lisp_String: predicate = Qstringp; break; 4581 case Lisp_String: predicate = Qstringp; break;
4578 case Lisp_Symbol: predicate = Qsymbolp; break; 4582 case Lisp_Symbol: predicate = Qsymbolp; break;
4579 default: abort (); 4583 default: emacs_abort ();
4580 } 4584 }
4581 4585
4582 wrong_type_argument (predicate, newval); 4586 wrong_type_argument (predicate, newval);
@@ -5125,10 +5129,11 @@ init_buffer_once (void)
5125 buffer_local_symbols.indirections = 0; 5129 buffer_local_symbols.indirections = 0;
5126 set_buffer_intervals (&buffer_defaults, NULL); 5130 set_buffer_intervals (&buffer_defaults, NULL);
5127 set_buffer_intervals (&buffer_local_symbols, NULL); 5131 set_buffer_intervals (&buffer_local_symbols, NULL);
5132 /* This is not strictly necessary, but let's make them initialized. */
5133 bset_name (&buffer_defaults, build_pure_c_string (" *buffer-defaults*"));
5134 bset_name (&buffer_local_symbols, build_pure_c_string (" *buffer-local-symbols*"));
5128 XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize); 5135 XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize);
5129 XSETBUFFER (Vbuffer_defaults, &buffer_defaults);
5130 XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize); 5136 XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize);
5131 XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols);
5132 5137
5133 /* Set up the default values of various buffer slots. */ 5138 /* Set up the default values of various buffer slots. */
5134 /* Must do these before making the first buffer! */ 5139 /* Must do these before making the first buffer! */
@@ -5257,7 +5262,7 @@ init_buffer_once (void)
5257 5262
5258 /* Need more room? */ 5263 /* Need more room? */
5259 if (idx >= MAX_PER_BUFFER_VARS) 5264 if (idx >= MAX_PER_BUFFER_VARS)
5260 abort (); 5265 emacs_abort ();
5261 last_per_buffer_idx = idx; 5266 last_per_buffer_idx = idx;
5262 5267
5263 Vbuffer_alist = Qnil; 5268 Vbuffer_alist = Qnil;
@@ -5398,7 +5403,7 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring,
5398 if (PER_BUFFER_IDX (offset) == 0) 5403 if (PER_BUFFER_IDX (offset) == 0)
5399 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding 5404 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
5400 slot of buffer_local_flags */ 5405 slot of buffer_local_flags */
5401 abort (); 5406 emacs_abort ();
5402} 5407}
5403 5408
5404 5409
@@ -5410,8 +5415,6 @@ syms_of_buffer (void)
5410 last_overlay_modification_hooks 5415 last_overlay_modification_hooks
5411 = Fmake_vector (make_number (10), Qnil); 5416 = Fmake_vector (make_number (10), Qnil);
5412 5417
5413 staticpro (&Vbuffer_defaults);
5414 staticpro (&Vbuffer_local_symbols);
5415 staticpro (&Qfundamental_mode); 5418 staticpro (&Qfundamental_mode);
5416 staticpro (&Qmode_class); 5419 staticpro (&Qmode_class);
5417 staticpro (&QSFundamental); 5420 staticpro (&QSFundamental);
@@ -6286,6 +6289,7 @@ and `bury-buffer-internal'. */);
6286 defsubr (&Soverlayp); 6289 defsubr (&Soverlayp);
6287 defsubr (&Smake_overlay); 6290 defsubr (&Smake_overlay);
6288 defsubr (&Sdelete_overlay); 6291 defsubr (&Sdelete_overlay);
6292 defsubr (&Sdelete_all_overlays);
6289 defsubr (&Smove_overlay); 6293 defsubr (&Smove_overlay);
6290 defsubr (&Soverlay_start); 6294 defsubr (&Soverlay_start);
6291 defsubr (&Soverlay_end); 6295 defsubr (&Soverlay_end);