aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c246
1 files changed, 117 insertions, 129 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 671b6418757..3e25c28f5b4 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -266,17 +266,18 @@ assoc_ignore_text_properties (key, list)
266} 266}
267 267
268DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0, 268DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0,
269 doc: /* Return the buffer named NAME (a string). 269 doc: /* Return the buffer named BUFFER-OR-NAME.
270If there is no live buffer named NAME, return nil. 270BUFFER-OR-NAME must be either a string or a buffer. If BUFFER-OR-NAME
271NAME may also be a buffer; if so, the value is that buffer. */) 271is a string and there is no buffer with that name, return nil. If
272 (name) 272BUFFER-OR-NAME is a buffer, return it as given. */)
273 register Lisp_Object name; 273 (buffer_or_name)
274 register Lisp_Object buffer_or_name;
274{ 275{
275 if (BUFFERP (name)) 276 if (BUFFERP (buffer_or_name))
276 return name; 277 return buffer_or_name;
277 CHECK_STRING (name); 278 CHECK_STRING (buffer_or_name);
278 279
279 return Fcdr (assoc_ignore_text_properties (name, Vbuffer_alist)); 280 return Fcdr (assoc_ignore_text_properties (buffer_or_name, Vbuffer_alist));
280} 281}
281 282
282DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0, 283DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0,
@@ -1382,38 +1383,39 @@ Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1382The buffer being killed will be current while the hook is running.\n\ 1383The buffer being killed will be current while the hook is running.\n\
1383See `kill-buffer'." 1384See `kill-buffer'."
1384 */ 1385 */
1385DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ", 1386DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ",
1386 doc: /* Kill the buffer BUFFER. 1387 doc: /* Kill buffer BUFFER-OR-NAME.
1387The argument may be a buffer or the name of a buffer. 1388The argument may be a buffer or the name of an existing buffer.
1388With a nil argument, kill the current buffer. 1389Argument nil or omitted means kill the current buffer. Return t if the
1389 1390buffer is actually killed, nil otherwise.
1390Value is t if the buffer is actually killed, nil otherwise. 1391
1391 1392This function calls `replace-buffer-in-windows' for cleaning up all
1392The functions in `kill-buffer-query-functions' are called with BUFFER as 1393windows currently displaying the buffer to be killed. The functions in
1393the current buffer. If any of them returns nil, the buffer is not killed. 1394`kill-buffer-query-functions' are called with the buffer to be killed as
1394 1395the current buffer. If any of them returns nil, the buffer is not
1395The hook `kill-buffer-hook' is run before the buffer is actually killed. 1396killed. The hook `kill-buffer-hook' is run before the buffer is
1396The buffer being killed will be current while the hook is running. 1397actually killed. The buffer being killed will be current while the hook
1398is running.
1397 1399
1398Any processes that have this buffer as the `process-buffer' are killed 1400Any processes that have this buffer as the `process-buffer' are killed
1399with SIGHUP. */) 1401with SIGHUP. */)
1400 (buffer) 1402 (buffer_or_name)
1401 Lisp_Object buffer; 1403 Lisp_Object buffer_or_name;
1402{ 1404{
1403 Lisp_Object buf; 1405 Lisp_Object buffer;
1404 register struct buffer *b; 1406 register struct buffer *b;
1405 register Lisp_Object tem; 1407 register Lisp_Object tem;
1406 register struct Lisp_Marker *m; 1408 register struct Lisp_Marker *m;
1407 struct gcpro gcpro1; 1409 struct gcpro gcpro1;
1408 1410
1409 if (NILP (buffer)) 1411 if (NILP (buffer_or_name))
1410 buf = Fcurrent_buffer (); 1412 buffer = Fcurrent_buffer ();
1411 else 1413 else
1412 buf = Fget_buffer (buffer); 1414 buffer = Fget_buffer (buffer_or_name);
1413 if (NILP (buf)) 1415 if (NILP (buffer))
1414 nsberror (buffer); 1416 nsberror (buffer_or_name);
1415 1417
1416 b = XBUFFER (buf); 1418 b = XBUFFER (buffer);
1417 1419
1418 /* Avoid trouble for buffer already dead. */ 1420 /* Avoid trouble for buffer already dead. */
1419 if (NILP (b->name)) 1421 if (NILP (b->name))
@@ -1423,7 +1425,7 @@ with SIGHUP. */)
1423 if (INTERACTIVE && !NILP (b->filename) 1425 if (INTERACTIVE && !NILP (b->filename)
1424 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) 1426 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
1425 { 1427 {
1426 GCPRO1 (buf); 1428 GCPRO1 (buffer);
1427 tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ", 1429 tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
1428 b->name, make_number (0))); 1430 b->name, make_number (0)));
1429 UNGCPRO; 1431 UNGCPRO;
@@ -1456,7 +1458,7 @@ with SIGHUP. */)
1456 since anything can happen within do_yes_or_no_p. */ 1458 since anything can happen within do_yes_or_no_p. */
1457 1459
1458 /* Don't kill the minibuffer now current. */ 1460 /* Don't kill the minibuffer now current. */
1459 if (EQ (buf, XWINDOW (minibuf_window)->buffer)) 1461 if (EQ (buffer, XWINDOW (minibuf_window)->buffer))
1460 return Qnil; 1462 return Qnil;
1461 1463
1462 if (NILP (b->name)) 1464 if (NILP (b->name))
@@ -1469,16 +1471,16 @@ with SIGHUP. */)
1469 { 1471 {
1470 struct buffer *other; 1472 struct buffer *other;
1471 1473
1472 GCPRO1 (buf); 1474 GCPRO1 (buffer);
1473 1475
1474 for (other = all_buffers; other; other = other->next) 1476 for (other = all_buffers; other; other = other->next)
1475 /* all_buffers contains dead buffers too; 1477 /* all_buffers contains dead buffers too;
1476 don't re-kill them. */ 1478 don't re-kill them. */
1477 if (other->base_buffer == b && !NILP (other->name)) 1479 if (other->base_buffer == b && !NILP (other->name))
1478 { 1480 {
1479 Lisp_Object buf; 1481 Lisp_Object buffer;
1480 XSETBUFFER (buf, other); 1482 XSETBUFFER (buffer, other);
1481 Fkill_buffer (buf); 1483 Fkill_buffer (buffer);
1482 } 1484 }
1483 1485
1484 UNGCPRO; 1486 UNGCPRO;
@@ -1489,7 +1491,7 @@ with SIGHUP. */)
1489 and give up if so. */ 1491 and give up if so. */
1490 if (b == current_buffer) 1492 if (b == current_buffer)
1491 { 1493 {
1492 tem = Fother_buffer (buf, Qnil, Qnil); 1494 tem = Fother_buffer (buffer, Qnil, Qnil);
1493 Fset_buffer (tem); 1495 Fset_buffer (tem);
1494 if (b == current_buffer) 1496 if (b == current_buffer)
1495 return Qnil; 1497 return Qnil;
@@ -1500,8 +1502,8 @@ with SIGHUP. */)
1500 XSETBUFFER (tem, current_buffer); 1502 XSETBUFFER (tem, current_buffer);
1501 if (EQ (tem, XWINDOW (minibuf_window)->buffer)) 1503 if (EQ (tem, XWINDOW (minibuf_window)->buffer))
1502 { 1504 {
1503 tem = Fother_buffer (buf, Qnil, Qnil); 1505 tem = Fother_buffer (buffer, Qnil, Qnil);
1504 if (EQ (buf, tem)) 1506 if (EQ (buffer, tem))
1505 return Qnil; 1507 return Qnil;
1506 } 1508 }
1507 1509
@@ -1512,8 +1514,8 @@ with SIGHUP. */)
1512 unlock_buffer (b); 1514 unlock_buffer (b);
1513#endif /* CLASH_DETECTION */ 1515#endif /* CLASH_DETECTION */
1514 1516
1515 GCPRO1 (buf); 1517 GCPRO1 (buffer);
1516 kill_buffer_processes (buf); 1518 kill_buffer_processes (buffer);
1517 UNGCPRO; 1519 UNGCPRO;
1518 1520
1519 /* Killing buffer processes may run sentinels which may 1521 /* Killing buffer processes may run sentinels which may
@@ -1526,9 +1528,9 @@ with SIGHUP. */)
1526 1528
1527 tem = Vinhibit_quit; 1529 tem = Vinhibit_quit;
1528 Vinhibit_quit = Qt; 1530 Vinhibit_quit = Qt;
1529 replace_buffer_in_all_windows (buf); 1531 replace_buffer_in_all_windows (buffer);
1530 Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist); 1532 Vbuffer_alist = Fdelq (Frassq (buffer, Vbuffer_alist), Vbuffer_alist);
1531 frames_discard_buffer (buf); 1533 frames_discard_buffer (buffer);
1532 Vinhibit_quit = tem; 1534 Vinhibit_quit = tem;
1533 1535
1534 /* Delete any auto-save file, if we saved it in this session. 1536 /* Delete any auto-save file, if we saved it in this session.
@@ -1723,96 +1725,82 @@ the current buffer's major mode. */)
1723 return unbind_to (count, Qnil); 1725 return unbind_to (count, Qnil);
1724} 1726}
1725 1727
1726/* If switching buffers in WINDOW would be an error, return
1727 a C string saying what the error would be. */
1728
1729char *
1730no_switch_window (window)
1731 Lisp_Object window;
1732{
1733 Lisp_Object tem;
1734 if (EQ (minibuf_window, window))
1735 return "Cannot switch buffers in minibuffer window";
1736 tem = Fwindow_dedicated_p (window);
1737 if (EQ (tem, Qt))
1738 return "Cannot switch buffers in a dedicated window";
1739 return NULL;
1740}
1741
1742/* Switch to buffer BUFFER in the selected window. 1728/* Switch to buffer BUFFER in the selected window.
1743 If NORECORD is non-nil, don't call record_buffer. */ 1729 If NORECORD is non-nil, don't call record_buffer. */
1744 1730
1745Lisp_Object 1731Lisp_Object
1746switch_to_buffer_1 (buffer, norecord) 1732switch_to_buffer_1 (buffer_or_name, norecord)
1747 Lisp_Object buffer, norecord; 1733 Lisp_Object buffer_or_name, norecord;
1748{ 1734{
1749 register Lisp_Object buf; 1735 register Lisp_Object buffer;
1750 1736
1751 if (NILP (buffer)) 1737 if (NILP (buffer_or_name))
1752 buf = Fother_buffer (Fcurrent_buffer (), Qnil, Qnil); 1738 buffer = Fother_buffer (Fcurrent_buffer (), Qnil, Qnil);
1753 else 1739 else
1754 { 1740 {
1755 buf = Fget_buffer (buffer); 1741 buffer = Fget_buffer (buffer_or_name);
1756 if (NILP (buf)) 1742 if (NILP (buffer))
1757 { 1743 {
1758 buf = Fget_buffer_create (buffer); 1744 buffer = Fget_buffer_create (buffer_or_name);
1759 Fset_buffer_major_mode (buf); 1745 Fset_buffer_major_mode (buffer);
1760 } 1746 }
1761 } 1747 }
1762 Fset_buffer (buf); 1748 Fset_buffer (buffer);
1763 if (NILP (norecord)) 1749 if (NILP (norecord))
1764 record_buffer (buf); 1750 record_buffer (buffer);
1765 1751
1766 Fset_window_buffer (EQ (selected_window, minibuf_window) 1752 Fset_window_buffer (EQ (selected_window, minibuf_window)
1767 ? Fnext_window (minibuf_window, Qnil, Qnil) 1753 ? Fnext_window (minibuf_window, Qnil, Qnil)
1768 : selected_window, 1754 : selected_window,
1769 buf, Qnil); 1755 buffer, Qnil);
1770 1756
1771 return buf; 1757 return buffer;
1772} 1758}
1773 1759
1774DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, 1760DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2,
1775 "(list (read-buffer-to-switch \"Switch to buffer: \"))", 1761 "(list (read-buffer-to-switch \"Switch to buffer: \"))",
1776 doc: /* Select buffer BUFFER in the current window. 1762 doc: /* Make BUFFER-OR-NAME current and display it in the selected window.
1777If BUFFER does not identify an existing buffer, 1763BUFFER-OR-NAME may be a buffer, a string, or nil. If BUFFER-OR-NAME is
1764nil, then this function chooses a buffer using `other-buffer'. If
1765BUFFER-OR-NAME is a string and does not identify an existing buffer,
1778then this function creates a buffer with that name. 1766then this function creates a buffer with that name.
1779 1767
1780When called from Lisp, BUFFER may be a buffer, a string \(a buffer name), 1768Optional second arg NORECORD non-nil means do not put this buffer at the
1781or nil. If BUFFER is nil, then this function chooses a buffer 1769front of the list of recently selected ones. This function returns the
1782using `other-buffer'. 1770buffer it switched to as a Lisp object.
1783Optional second arg NORECORD non-nil means 1771
1784do not put this buffer at the front of the list of recently selected ones. 1772If the selected window is the minibuffer window or dedicated to its
1785This function returns the buffer it switched to. 1773buffer, use `pop-to-buffer' for displaying the buffer.
1786 1774
1787WARNING: This is NOT the way to work on another buffer temporarily 1775WARNING: This is NOT the way to work on another buffer temporarily
1788within a Lisp program! Use `set-buffer' instead. That avoids messing with 1776within a Lisp program! Use `set-buffer' instead. That avoids messing
1789the window-buffer correspondences. */) 1777with the window-buffer correspondences. */)
1790 (buffer, norecord) 1778 (buffer_or_name, norecord)
1791 Lisp_Object buffer, norecord; 1779 Lisp_Object buffer_or_name, norecord;
1792{ 1780{
1793 char *err; 1781 char *err;
1794 1782
1795 if (EQ (buffer, Fwindow_buffer (selected_window))) 1783 if (EQ (buffer_or_name, Fwindow_buffer (selected_window)))
1796 { 1784 {
1797 /* Basically a NOP. Avoid signalling an error in the case where 1785 /* Basically a NOP. Avoid signalling an error in the case where
1798 the selected window is dedicated, or a minibuffer. */ 1786 the selected window is dedicated, or a minibuffer. */
1799 1787
1800 /* But do put this buffer at the front of the buffer list, 1788 /* But do put this buffer at the front of the buffer list, unless
1801 unless that has been inhibited. Note that even if 1789 that has been inhibited. Note that even if BUFFER-OR-NAME is
1802 BUFFER is at the front of the main buffer-list already, 1790 at the front of the main buffer-list already, we still want to
1803 we still want to move it to the front of the frame's buffer list. */ 1791 move it to the front of the frame's buffer list. */
1804 if (NILP (norecord)) 1792 if (NILP (norecord))
1805 record_buffer (buffer); 1793 record_buffer (buffer_or_name);
1806 return Fset_buffer (buffer); 1794 return Fset_buffer (buffer_or_name);
1807 } 1795 }
1808 1796
1809 err = no_switch_window (selected_window); 1797 if (EQ (minibuf_window, selected_window)
1810 if (err) 1798 || !NILP (Fwindow_dedicated_p (selected_window)))
1811 /* If can't display in current window, let pop-to-buffer 1799 /* We can't use the selected window so let `pop-to-buffer' try some
1812 try some other window. */ 1800 other window. */
1813 return call3 (intern ("pop-to-buffer"), buffer, Qnil, norecord); 1801 return call3 (intern ("pop-to-buffer"), buffer_or_name, Qnil, norecord);
1814 1802 else
1815 return switch_to_buffer_1 (buffer, norecord); 1803 return switch_to_buffer_1 (buffer_or_name, norecord);
1816} 1804}
1817 1805
1818DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0, 1806DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,
@@ -2010,23 +1998,23 @@ set_buffer_temp (b)
2010} 1998}
2011 1999
2012DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0, 2000DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,
2013 doc: /* Make the buffer BUFFER current for editing operations. 2001 doc: /* Make buffer BUFFER-OR-NAME current for editing operations.
2014BUFFER may be a buffer or the name of an existing buffer. 2002BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See
2015See also `save-excursion' when you want to make a buffer current temporarily. 2003also `save-excursion' when you want to make a buffer current
2016This function does not display the buffer, so its effect ends 2004temporarily. This function does not display the buffer, so its effect
2017when the current command terminates. 2005ends when the current command terminates. Use `switch-to-buffer' or
2018Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently. */) 2006`pop-to-buffer' to switch buffers permanently. */)
2019 (buffer) 2007 (buffer_or_name)
2020 register Lisp_Object buffer; 2008 register Lisp_Object buffer_or_name;
2021{ 2009{
2022 register Lisp_Object buf; 2010 register Lisp_Object buffer;
2023 buf = Fget_buffer (buffer); 2011 buffer = Fget_buffer (buffer_or_name);
2024 if (NILP (buf)) 2012 if (NILP (buffer))
2025 nsberror (buffer); 2013 nsberror (buffer_or_name);
2026 if (NILP (XBUFFER (buf)->name)) 2014 if (NILP (XBUFFER (buffer)->name))
2027 error ("Selecting deleted buffer"); 2015 error ("Selecting deleted buffer");
2028 set_buffer_internal (XBUFFER (buf)); 2016 set_buffer_internal (XBUFFER (buffer));
2029 return buf; 2017 return buffer;
2030} 2018}
2031 2019
2032/* Set the current buffer to BUFFER provided it is alive. */ 2020/* Set the current buffer to BUFFER provided it is alive. */
@@ -2052,18 +2040,21 @@ DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only,
2052} 2040}
2053 2041
2054DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "", 2042DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",
2055 doc: /* Put BUFFER at the end of the list of all buffers. 2043 doc: /* Put BUFFER-OR-NAME at the end of the list of all buffers.
2056There it is the least likely candidate for `other-buffer' to return; 2044There it is the least likely candidate for `other-buffer' to return;
2057thus, the least likely buffer for \\[switch-to-buffer] to select by default. 2045thus, the least likely buffer for \\[switch-to-buffer] to select by
2058You can specify a buffer name as BUFFER, or an actual buffer object. 2046default.
2059If BUFFER is nil or omitted, bury the current buffer. 2047
2060Also, if BUFFER is nil or omitted, remove the current buffer from the 2048The argument may be a buffer name or an actual buffer object. If
2061selected window if it is displayed there. */) 2049BUFFER-OR-NAME is nil or omitted, bury the current buffer and remove it
2062 (buffer) 2050from the selected window if it is displayed there. */)
2063 register Lisp_Object buffer; 2051 (buffer_or_name)
2052 register Lisp_Object buffer_or_name;
2064{ 2053{
2054 Lisp_Object buffer;
2055
2065 /* Figure out what buffer we're going to bury. */ 2056 /* Figure out what buffer we're going to bury. */
2066 if (NILP (buffer)) 2057 if (NILP (buffer_or_name))
2067 { 2058 {
2068 Lisp_Object tem; 2059 Lisp_Object tem;
2069 XSETBUFFER (buffer, current_buffer); 2060 XSETBUFFER (buffer, current_buffer);
@@ -2082,12 +2073,9 @@ selected window if it is displayed there. */)
2082 } 2073 }
2083 else 2074 else
2084 { 2075 {
2085 Lisp_Object buf1; 2076 buffer = Fget_buffer (buffer_or_name);
2086 2077 if (NILP (buffer))
2087 buf1 = Fget_buffer (buffer); 2078 nsberror (buffer_or_name);
2088 if (NILP (buf1))
2089 nsberror (buffer);
2090 buffer = buf1;
2091 } 2079 }
2092 2080
2093 /* Move buffer to the end of the buffer list. Do nothing if the 2081 /* Move buffer to the end of the buffer list. Do nothing if the