diff options
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 141 |
1 files changed, 44 insertions, 97 deletions
diff --git a/src/buffer.c b/src/buffer.c index d2c7729d1c2..80791a1fdb1 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -1134,10 +1134,7 @@ BUFFER defaults to the current buffer. | |||
| 1134 | Return nil if BUFFER has been killed. */) | 1134 | Return nil if BUFFER has been killed. */) |
| 1135 | (register Lisp_Object buffer) | 1135 | (register Lisp_Object buffer) |
| 1136 | { | 1136 | { |
| 1137 | if (NILP (buffer)) | 1137 | return BVAR (decode_buffer (buffer), name); |
| 1138 | return BVAR (current_buffer, name); | ||
| 1139 | CHECK_BUFFER (buffer); | ||
| 1140 | return BVAR (XBUFFER (buffer), name); | ||
| 1141 | } | 1138 | } |
| 1142 | 1139 | ||
| 1143 | DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0, | 1140 | DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0, |
| @@ -1145,10 +1142,7 @@ DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0, | |||
| 1145 | No argument or nil as argument means use the current buffer. */) | 1142 | No argument or nil as argument means use the current buffer. */) |
| 1146 | (register Lisp_Object buffer) | 1143 | (register Lisp_Object buffer) |
| 1147 | { | 1144 | { |
| 1148 | if (NILP (buffer)) | 1145 | return BVAR (decode_buffer (buffer), filename); |
| 1149 | return BVAR (current_buffer, filename); | ||
| 1150 | CHECK_BUFFER (buffer); | ||
| 1151 | return BVAR (XBUFFER (buffer), filename); | ||
| 1152 | } | 1146 | } |
| 1153 | 1147 | ||
| 1154 | DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, Sbuffer_base_buffer, | 1148 | DEFUN ("buffer-base-buffer", Fbuffer_base_buffer, Sbuffer_base_buffer, |
| @@ -1158,21 +1152,8 @@ If BUFFER is not indirect, return nil. | |||
| 1158 | BUFFER defaults to the current buffer. */) | 1152 | BUFFER defaults to the current buffer. */) |
| 1159 | (register Lisp_Object buffer) | 1153 | (register Lisp_Object buffer) |
| 1160 | { | 1154 | { |
| 1161 | struct buffer *base; | 1155 | struct buffer *base = decode_buffer (buffer)->base_buffer; |
| 1162 | Lisp_Object base_buffer; | 1156 | return base ? (XSETBUFFER (buffer, base), buffer) : Qnil; |
| 1163 | |||
| 1164 | if (NILP (buffer)) | ||
| 1165 | base = current_buffer->base_buffer; | ||
| 1166 | else | ||
| 1167 | { | ||
| 1168 | CHECK_BUFFER (buffer); | ||
| 1169 | base = XBUFFER (buffer)->base_buffer; | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | if (! base) | ||
| 1173 | return Qnil; | ||
| 1174 | XSETBUFFER (base_buffer, base); | ||
| 1175 | return base_buffer; | ||
| 1176 | } | 1157 | } |
| 1177 | 1158 | ||
| 1178 | DEFUN ("buffer-local-value", Fbuffer_local_value, | 1159 | DEFUN ("buffer-local-value", Fbuffer_local_value, |
| @@ -1295,20 +1276,10 @@ Most elements look like (SYMBOL . VALUE), describing one variable. | |||
| 1295 | For a symbol that is locally unbound, just the symbol appears in the value. | 1276 | For a symbol that is locally unbound, just the symbol appears in the value. |
| 1296 | Note that storing new VALUEs in these elements doesn't change the variables. | 1277 | Note that storing new VALUEs in these elements doesn't change the variables. |
| 1297 | No argument or nil as argument means use current buffer as BUFFER. */) | 1278 | No argument or nil as argument means use current buffer as BUFFER. */) |
| 1298 | (register Lisp_Object buffer) | 1279 | (Lisp_Object buffer) |
| 1299 | { | 1280 | { |
| 1300 | register struct buffer *buf; | 1281 | struct buffer *buf = decode_buffer (buffer); |
| 1301 | register Lisp_Object result; | 1282 | Lisp_Object result = buffer_lisp_local_variables (buf, 0); |
| 1302 | |||
| 1303 | if (NILP (buffer)) | ||
| 1304 | buf = current_buffer; | ||
| 1305 | else | ||
| 1306 | { | ||
| 1307 | CHECK_BUFFER (buffer); | ||
| 1308 | buf = XBUFFER (buffer); | ||
| 1309 | } | ||
| 1310 | |||
| 1311 | result = buffer_lisp_local_variables (buf, 0); | ||
| 1312 | 1283 | ||
| 1313 | /* Add on all the variables stored in special slots. */ | 1284 | /* Add on all the variables stored in special slots. */ |
| 1314 | { | 1285 | { |
| @@ -1335,17 +1306,9 @@ DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, | |||
| 1335 | 0, 1, 0, | 1306 | 0, 1, 0, |
| 1336 | doc: /* Return t if BUFFER was modified since its file was last read or saved. | 1307 | doc: /* Return t if BUFFER was modified since its file was last read or saved. |
| 1337 | No argument or nil as argument means use current buffer as BUFFER. */) | 1308 | No argument or nil as argument means use current buffer as BUFFER. */) |
| 1338 | (register Lisp_Object buffer) | 1309 | (Lisp_Object buffer) |
| 1339 | { | 1310 | { |
| 1340 | register struct buffer *buf; | 1311 | struct buffer *buf = decode_buffer (buffer); |
| 1341 | if (NILP (buffer)) | ||
| 1342 | buf = current_buffer; | ||
| 1343 | else | ||
| 1344 | { | ||
| 1345 | CHECK_BUFFER (buffer); | ||
| 1346 | buf = XBUFFER (buffer); | ||
| 1347 | } | ||
| 1348 | |||
| 1349 | return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; | 1312 | return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; |
| 1350 | } | 1313 | } |
| 1351 | 1314 | ||
| @@ -1451,16 +1414,7 @@ text in that buffer is changed. It wraps around occasionally. | |||
| 1451 | No argument or nil as argument means use current buffer as BUFFER. */) | 1414 | No argument or nil as argument means use current buffer as BUFFER. */) |
| 1452 | (register Lisp_Object buffer) | 1415 | (register Lisp_Object buffer) |
| 1453 | { | 1416 | { |
| 1454 | register struct buffer *buf; | 1417 | return make_number (BUF_MODIFF (decode_buffer (buffer))); |
| 1455 | if (NILP (buffer)) | ||
| 1456 | buf = current_buffer; | ||
| 1457 | else | ||
| 1458 | { | ||
| 1459 | CHECK_BUFFER (buffer); | ||
| 1460 | buf = XBUFFER (buffer); | ||
| 1461 | } | ||
| 1462 | |||
| 1463 | return make_number (BUF_MODIFF (buf)); | ||
| 1464 | } | 1418 | } |
| 1465 | 1419 | ||
| 1466 | DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick, | 1420 | DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick, |
| @@ -1475,16 +1429,7 @@ between these calls. No argument or nil as argument means use current | |||
| 1475 | buffer as BUFFER. */) | 1429 | buffer as BUFFER. */) |
| 1476 | (register Lisp_Object buffer) | 1430 | (register Lisp_Object buffer) |
| 1477 | { | 1431 | { |
| 1478 | register struct buffer *buf; | 1432 | return make_number (BUF_CHARS_MODIFF (decode_buffer (buffer))); |
| 1479 | if (NILP (buffer)) | ||
| 1480 | buf = current_buffer; | ||
| 1481 | else | ||
| 1482 | { | ||
| 1483 | CHECK_BUFFER (buffer); | ||
| 1484 | buf = XBUFFER (buffer); | ||
| 1485 | } | ||
| 1486 | |||
| 1487 | return make_number (BUF_CHARS_MODIFF (buf)); | ||
| 1488 | } | 1433 | } |
| 1489 | 1434 | ||
| 1490 | DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2, | 1435 | DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2, |
| @@ -1564,7 +1509,7 @@ frame's buffer list. | |||
| 1564 | The buffer is found by scanning the selected or specified frame's buffer | 1509 | The buffer is found by scanning the selected or specified frame's buffer |
| 1565 | list first, followed by the list of all buffers. If no other buffer | 1510 | list first, followed by the list of all buffers. If no other buffer |
| 1566 | exists, return the buffer `*scratch*' (creating it if necessary). */) | 1511 | exists, return the buffer `*scratch*' (creating it if necessary). */) |
| 1567 | (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame) | 1512 | (Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame) |
| 1568 | { | 1513 | { |
| 1569 | struct frame *f = decode_any_frame (frame); | 1514 | struct frame *f = decode_any_frame (frame); |
| 1570 | Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate; | 1515 | Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate; |
| @@ -1607,10 +1552,11 @@ exists, return the buffer `*scratch*' (creating it if necessary). */) | |||
| 1607 | return notsogood; | 1552 | return notsogood; |
| 1608 | else | 1553 | else |
| 1609 | { | 1554 | { |
| 1610 | buf = Fget_buffer (build_string ("*scratch*")); | 1555 | AUTO_STRING (scratch, "*scratch*"); |
| 1556 | buf = Fget_buffer (scratch); | ||
| 1611 | if (NILP (buf)) | 1557 | if (NILP (buf)) |
| 1612 | { | 1558 | { |
| 1613 | buf = Fget_buffer_create (build_string ("*scratch*")); | 1559 | buf = Fget_buffer_create (scratch); |
| 1614 | Fset_buffer_major_mode (buf); | 1560 | Fset_buffer_major_mode (buf); |
| 1615 | } | 1561 | } |
| 1616 | return buf; | 1562 | return buf; |
| @@ -1630,10 +1576,11 @@ other_buffer_safely (Lisp_Object buffer) | |||
| 1630 | if (candidate_buffer (buf, buffer)) | 1576 | if (candidate_buffer (buf, buffer)) |
| 1631 | return buf; | 1577 | return buf; |
| 1632 | 1578 | ||
| 1633 | buf = Fget_buffer (build_string ("*scratch*")); | 1579 | AUTO_STRING (scratch, "*scratch*"); |
| 1580 | buf = Fget_buffer (scratch); | ||
| 1634 | if (NILP (buf)) | 1581 | if (NILP (buf)) |
| 1635 | { | 1582 | { |
| 1636 | buf = Fget_buffer_create (build_string ("*scratch*")); | 1583 | buf = Fget_buffer_create (scratch); |
| 1637 | Fset_buffer_major_mode (buf); | 1584 | Fset_buffer_major_mode (buf); |
| 1638 | } | 1585 | } |
| 1639 | 1586 | ||
| @@ -3108,13 +3055,15 @@ mouse_face_overlay_overlaps (Lisp_Object overlay) | |||
| 3108 | ptrdiff_t end = OVERLAY_POSITION (OVERLAY_END (overlay)); | 3055 | ptrdiff_t end = OVERLAY_POSITION (OVERLAY_END (overlay)); |
| 3109 | ptrdiff_t n, i, size; | 3056 | ptrdiff_t n, i, size; |
| 3110 | Lisp_Object *v, tem; | 3057 | Lisp_Object *v, tem; |
| 3058 | Lisp_Object vbuf[10]; | ||
| 3059 | USE_SAFE_ALLOCA; | ||
| 3111 | 3060 | ||
| 3112 | size = 10; | 3061 | size = ARRAYELTS (vbuf); |
| 3113 | v = alloca (size * sizeof *v); | 3062 | v = vbuf; |
| 3114 | n = overlays_in (start, end, 0, &v, &size, NULL, NULL); | 3063 | n = overlays_in (start, end, 0, &v, &size, NULL, NULL); |
| 3115 | if (n > size) | 3064 | if (n > size) |
| 3116 | { | 3065 | { |
| 3117 | v = alloca (n * sizeof *v); | 3066 | SAFE_NALLOCA (v, 1, n); |
| 3118 | overlays_in (start, end, 0, &v, &n, NULL, NULL); | 3067 | overlays_in (start, end, 0, &v, &n, NULL, NULL); |
| 3119 | } | 3068 | } |
| 3120 | 3069 | ||
| @@ -3124,6 +3073,7 @@ mouse_face_overlay_overlaps (Lisp_Object overlay) | |||
| 3124 | !NILP (tem))) | 3073 | !NILP (tem))) |
| 3125 | break; | 3074 | break; |
| 3126 | 3075 | ||
| 3076 | SAFE_FREE (); | ||
| 3127 | return i < n; | 3077 | return i < n; |
| 3128 | } | 3078 | } |
| 3129 | 3079 | ||
| @@ -4137,17 +4087,7 @@ BUFFER omitted or nil means delete all overlays of the current | |||
| 4137 | buffer. */) | 4087 | buffer. */) |
| 4138 | (Lisp_Object buffer) | 4088 | (Lisp_Object buffer) |
| 4139 | { | 4089 | { |
| 4140 | register struct buffer *buf; | 4090 | delete_all_overlays (decode_buffer (buffer)); |
| 4141 | |||
| 4142 | if (NILP (buffer)) | ||
| 4143 | buf = current_buffer; | ||
| 4144 | else | ||
| 4145 | { | ||
| 4146 | CHECK_BUFFER (buffer); | ||
| 4147 | buf = XBUFFER (buffer); | ||
| 4148 | } | ||
| 4149 | |||
| 4150 | delete_all_overlays (buf); | ||
| 4151 | return Qnil; | 4091 | return Qnil; |
| 4152 | } | 4092 | } |
| 4153 | 4093 | ||
| @@ -4582,13 +4522,13 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after, | |||
| 4582 | First copy the vector contents, in case some of these hooks | 4522 | First copy the vector contents, in case some of these hooks |
| 4583 | do subsequent modification of the buffer. */ | 4523 | do subsequent modification of the buffer. */ |
| 4584 | ptrdiff_t size = last_overlay_modification_hooks_used; | 4524 | ptrdiff_t size = last_overlay_modification_hooks_used; |
| 4585 | Lisp_Object *copy = alloca (size * sizeof *copy); | 4525 | Lisp_Object *copy; |
| 4586 | ptrdiff_t i; | 4526 | ptrdiff_t i; |
| 4587 | 4527 | ||
| 4528 | USE_SAFE_ALLOCA; | ||
| 4529 | SAFE_ALLOCA_LISP (copy, size); | ||
| 4588 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, | 4530 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, |
| 4589 | size * word_size); | 4531 | size * word_size); |
| 4590 | gcpro1.var = copy; | ||
| 4591 | gcpro1.nvars = size; | ||
| 4592 | 4532 | ||
| 4593 | for (i = 0; i < size;) | 4533 | for (i = 0; i < size;) |
| 4594 | { | 4534 | { |
| @@ -4597,6 +4537,8 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after, | |||
| 4597 | overlay_i = copy[i++]; | 4537 | overlay_i = copy[i++]; |
| 4598 | call_overlay_mod_hooks (prop_i, overlay_i, after, arg1, arg2, arg3); | 4538 | call_overlay_mod_hooks (prop_i, overlay_i, after, arg1, arg2, arg3); |
| 4599 | } | 4539 | } |
| 4540 | |||
| 4541 | SAFE_FREE (); | ||
| 4600 | } | 4542 | } |
| 4601 | UNGCPRO; | 4543 | UNGCPRO; |
| 4602 | } | 4544 | } |
| @@ -5346,10 +5288,11 @@ init_buffer (int initialized) | |||
| 5346 | } | 5288 | } |
| 5347 | #else /* not USE_MMAP_FOR_BUFFERS */ | 5289 | #else /* not USE_MMAP_FOR_BUFFERS */ |
| 5348 | /* Avoid compiler warnings. */ | 5290 | /* Avoid compiler warnings. */ |
| 5349 | initialized = initialized; | 5291 | (void) initialized; |
| 5350 | #endif /* USE_MMAP_FOR_BUFFERS */ | 5292 | #endif /* USE_MMAP_FOR_BUFFERS */ |
| 5351 | 5293 | ||
| 5352 | Fset_buffer (Fget_buffer_create (build_string ("*scratch*"))); | 5294 | AUTO_STRING (scratch, "*scratch*"); |
| 5295 | Fset_buffer (Fget_buffer_create (scratch)); | ||
| 5353 | if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) | 5296 | if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) |
| 5354 | Fset_buffer_multibyte (Qnil); | 5297 | Fset_buffer_multibyte (Qnil); |
| 5355 | 5298 | ||
| @@ -5386,9 +5329,12 @@ init_buffer (int initialized) | |||
| 5386 | However, it is not necessary to turn / into /:/. | 5329 | However, it is not necessary to turn / into /:/. |
| 5387 | So avoid doing that. */ | 5330 | So avoid doing that. */ |
| 5388 | && strcmp ("/", SSDATA (BVAR (current_buffer, directory)))) | 5331 | && strcmp ("/", SSDATA (BVAR (current_buffer, directory)))) |
| 5389 | bset_directory | 5332 | { |
| 5390 | (current_buffer, | 5333 | AUTO_STRING (slash_colon, "/:"); |
| 5391 | concat2 (build_string ("/:"), BVAR (current_buffer, directory))); | 5334 | bset_directory (current_buffer, |
| 5335 | concat2 (slash_colon, | ||
| 5336 | BVAR (current_buffer, directory))); | ||
| 5337 | } | ||
| 5392 | 5338 | ||
| 5393 | temp = get_minibuffer (0); | 5339 | temp = get_minibuffer (0); |
| 5394 | bset_directory (XBUFFER (temp), BVAR (current_buffer, directory)); | 5340 | bset_directory (XBUFFER (temp), BVAR (current_buffer, directory)); |
| @@ -5451,6 +5397,7 @@ syms_of_buffer (void) | |||
| 5451 | staticpro (&Qpermanent_local); | 5397 | staticpro (&Qpermanent_local); |
| 5452 | staticpro (&Qkill_buffer_hook); | 5398 | staticpro (&Qkill_buffer_hook); |
| 5453 | 5399 | ||
| 5400 | DEFSYM (Qchoice, "choice"); | ||
| 5454 | DEFSYM (Qleft, "left"); | 5401 | DEFSYM (Qleft, "left"); |
| 5455 | DEFSYM (Qright, "right"); | 5402 | DEFSYM (Qright, "right"); |
| 5456 | DEFSYM (Qrange, "range"); | 5403 | DEFSYM (Qrange, "range"); |
| @@ -5978,13 +5925,13 @@ in a window. To make the change take effect, call `set-window-buffer'. */); | |||
| 5978 | 5925 | ||
| 5979 | DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer, scroll_bar_width), | 5926 | DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer, scroll_bar_width), |
| 5980 | Qintegerp, | 5927 | Qintegerp, |
| 5981 | doc: /* Width of this buffer's scroll bars in pixels. | 5928 | doc: /* Width of this buffer's vertical scroll bars in pixels. |
| 5982 | A value of nil means to use the scroll bar width from the window's frame. */); | 5929 | A value of nil means to use the scroll bar width from the window's frame. */); |
| 5983 | 5930 | ||
| 5984 | DEFVAR_PER_BUFFER ("scroll-bar-height", &BVAR (current_buffer, scroll_bar_height), | 5931 | DEFVAR_PER_BUFFER ("scroll-bar-height", &BVAR (current_buffer, scroll_bar_height), |
| 5985 | Qintegerp, | 5932 | Qintegerp, |
| 5986 | doc: /* Height of this buffer's scroll bars in pixels. | 5933 | doc: /* Height of this buffer's horizontal scroll bars in pixels. |
| 5987 | A value of nil means to use the scroll bar heiht from the window's frame. */); | 5934 | A value of nil means to use the scroll bar height from the window's frame. */); |
| 5988 | 5935 | ||
| 5989 | DEFVAR_PER_BUFFER ("vertical-scroll-bar", &BVAR (current_buffer, vertical_scroll_bar_type), | 5936 | DEFVAR_PER_BUFFER ("vertical-scroll-bar", &BVAR (current_buffer, vertical_scroll_bar_type), |
| 5990 | Qvertical_scroll_bar, | 5937 | Qvertical_scroll_bar, |
| @@ -6003,7 +5950,7 @@ The value takes effect whenever you tell a window to display this buffer; | |||
| 6003 | for instance, with `set-window-buffer' or when `display-buffer' displays it. | 5950 | for instance, with `set-window-buffer' or when `display-buffer' displays it. |
| 6004 | 5951 | ||
| 6005 | A value of `bottom' means put the horizontal scroll bar at the bottom of | 5952 | A value of `bottom' means put the horizontal scroll bar at the bottom of |
| 6006 | the window; a value of nil means don't show any horizonal scroll bars. | 5953 | the window; a value of nil means don't show any horizontal scroll bars. |
| 6007 | A value of t (the default) means do whatever the window's frame | 5954 | A value of t (the default) means do whatever the window's frame |
| 6008 | specifies. */); | 5955 | specifies. */); |
| 6009 | 5956 | ||