diff options
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 134 |
1 files changed, 61 insertions, 73 deletions
diff --git a/src/buffer.c b/src/buffer.c index ef04ca7018d..61b685ea5c5 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -154,7 +154,8 @@ CHECK_OVERLAY (Lisp_Object x) | |||
| 154 | CHECK_TYPE (OVERLAYP (x), Qoverlayp, x); | 154 | CHECK_TYPE (OVERLAYP (x), Qoverlayp, x); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | /* These setters are used only in this file, so they can be private. */ | 157 | /* These setters are used only in this file, so they can be private. |
| 158 | The public setters are inline functions defined in buffer.h. */ | ||
| 158 | static void | 159 | static void |
| 159 | bset_abbrev_mode (struct buffer *b, Lisp_Object val) | 160 | bset_abbrev_mode (struct buffer *b, Lisp_Object val) |
| 160 | { | 161 | { |
| @@ -201,11 +202,6 @@ bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val) | |||
| 201 | b->INTERNAL_FIELD (buffer_file_coding_system) = val; | 202 | b->INTERNAL_FIELD (buffer_file_coding_system) = val; |
| 202 | } | 203 | } |
| 203 | static void | 204 | static void |
| 204 | bset_cache_long_scans (struct buffer *b, Lisp_Object val) | ||
| 205 | { | ||
| 206 | b->INTERNAL_FIELD (cache_long_scans) = val; | ||
| 207 | } | ||
| 208 | static void | ||
| 209 | bset_case_fold_search (struct buffer *b, Lisp_Object val) | 205 | bset_case_fold_search (struct buffer *b, Lisp_Object val) |
| 210 | { | 206 | { |
| 211 | b->INTERNAL_FIELD (case_fold_search) = val; | 207 | b->INTERNAL_FIELD (case_fold_search) = val; |
| @@ -1332,15 +1328,54 @@ No argument or nil as argument means use current buffer as BUFFER. */) | |||
| 1332 | return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; | 1328 | return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; |
| 1333 | } | 1329 | } |
| 1334 | 1330 | ||
| 1331 | DEFUN ("force-mode-line-update", Fforce_mode_line_update, | ||
| 1332 | Sforce_mode_line_update, 0, 1, 0, | ||
| 1333 | doc: /* Force redisplay of the current buffer's mode line and header line. | ||
| 1334 | With optional non-nil ALL, force redisplay of all mode lines and | ||
| 1335 | header lines. This function also forces recomputation of the | ||
| 1336 | menu bar menus and the frame title. */) | ||
| 1337 | (Lisp_Object all) | ||
| 1338 | { | ||
| 1339 | if (!NILP (all) || buffer_window_count (current_buffer)) | ||
| 1340 | { | ||
| 1341 | update_mode_lines = 10; | ||
| 1342 | current_buffer->prevent_redisplay_optimizations_p = 1; | ||
| 1343 | } | ||
| 1344 | return all; | ||
| 1345 | } | ||
| 1346 | |||
| 1335 | DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p, | 1347 | DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p, |
| 1336 | 1, 1, 0, | 1348 | 1, 1, 0, |
| 1337 | doc: /* Mark current buffer as modified or unmodified according to FLAG. | 1349 | doc: /* Mark current buffer as modified or unmodified according to FLAG. |
| 1338 | A non-nil FLAG means mark the buffer modified. */) | 1350 | A non-nil FLAG means mark the buffer modified. */) |
| 1339 | (Lisp_Object flag) | 1351 | (Lisp_Object flag) |
| 1340 | { | 1352 | { |
| 1341 | Lisp_Object fn; | 1353 | Frestore_buffer_modified_p (flag); |
| 1354 | |||
| 1355 | /* Set update_mode_lines only if buffer is displayed in some window. | ||
| 1356 | Packages like jit-lock or lazy-lock preserve a buffer's modified | ||
| 1357 | state by recording/restoring the state around blocks of code. | ||
| 1358 | Setting update_mode_lines makes redisplay consider all windows | ||
| 1359 | (on all frames). Stealth fontification of buffers not displayed | ||
| 1360 | would incur additional redisplay costs if we'd set | ||
| 1361 | update_modes_lines unconditionally. | ||
| 1362 | |||
| 1363 | Ideally, I think there should be another mechanism for fontifying | ||
| 1364 | buffers without "modifying" buffers, or redisplay should be | ||
| 1365 | smarter about updating the `*' in mode lines. --gerd */ | ||
| 1366 | return Fforce_mode_line_update (Qnil); | ||
| 1367 | } | ||
| 1342 | 1368 | ||
| 1369 | DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p, | ||
| 1370 | Srestore_buffer_modified_p, 1, 1, 0, | ||
| 1371 | doc: /* Like `set-buffer-modified-p', with a difference concerning redisplay. | ||
| 1372 | It is not ensured that mode lines will be updated to show the modified | ||
| 1373 | state of the current buffer. Use with care. */) | ||
| 1374 | (Lisp_Object flag) | ||
| 1375 | { | ||
| 1343 | #ifdef CLASH_DETECTION | 1376 | #ifdef CLASH_DETECTION |
| 1377 | Lisp_Object fn; | ||
| 1378 | |||
| 1344 | /* If buffer becoming modified, lock the file. | 1379 | /* If buffer becoming modified, lock the file. |
| 1345 | If buffer becoming unmodified, unlock the file. */ | 1380 | If buffer becoming unmodified, unlock the file. */ |
| 1346 | 1381 | ||
| @@ -1380,52 +1415,6 @@ A non-nil FLAG means mark the buffer modified. */) | |||
| 1380 | or increase MODIFF. */ | 1415 | or increase MODIFF. */ |
| 1381 | : MODIFF++); | 1416 | : MODIFF++); |
| 1382 | 1417 | ||
| 1383 | /* Set update_mode_lines only if buffer is displayed in some window. | ||
| 1384 | Packages like jit-lock or lazy-lock preserve a buffer's modified | ||
| 1385 | state by recording/restoring the state around blocks of code. | ||
| 1386 | Setting update_mode_lines makes redisplay consider all windows | ||
| 1387 | (on all frames). Stealth fontification of buffers not displayed | ||
| 1388 | would incur additional redisplay costs if we'd set | ||
| 1389 | update_modes_lines unconditionally. | ||
| 1390 | |||
| 1391 | Ideally, I think there should be another mechanism for fontifying | ||
| 1392 | buffers without "modifying" buffers, or redisplay should be | ||
| 1393 | smarter about updating the `*' in mode lines. --gerd */ | ||
| 1394 | if (buffer_window_count (current_buffer)) | ||
| 1395 | { | ||
| 1396 | ++update_mode_lines; | ||
| 1397 | current_buffer->prevent_redisplay_optimizations_p = 1; | ||
| 1398 | } | ||
| 1399 | |||
| 1400 | return flag; | ||
| 1401 | } | ||
| 1402 | |||
| 1403 | DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p, | ||
| 1404 | Srestore_buffer_modified_p, 1, 1, 0, | ||
| 1405 | doc: /* Like `set-buffer-modified-p', with a difference concerning redisplay. | ||
| 1406 | It is not ensured that mode lines will be updated to show the modified | ||
| 1407 | state of the current buffer. Use with care. */) | ||
| 1408 | (Lisp_Object flag) | ||
| 1409 | { | ||
| 1410 | #ifdef CLASH_DETECTION | ||
| 1411 | Lisp_Object fn; | ||
| 1412 | |||
| 1413 | /* If buffer becoming modified, lock the file. | ||
| 1414 | If buffer becoming unmodified, unlock the file. */ | ||
| 1415 | |||
| 1416 | fn = BVAR (current_buffer, file_truename); | ||
| 1417 | /* Test buffer-file-name so that binding it to nil is effective. */ | ||
| 1418 | if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename))) | ||
| 1419 | { | ||
| 1420 | bool already = SAVE_MODIFF < MODIFF; | ||
| 1421 | if (!already && !NILP (flag)) | ||
| 1422 | lock_file (fn); | ||
| 1423 | else if (already && NILP (flag)) | ||
| 1424 | unlock_file (fn); | ||
| 1425 | } | ||
| 1426 | #endif /* CLASH_DETECTION */ | ||
| 1427 | |||
| 1428 | SAVE_MODIFF = NILP (flag) ? MODIFF : 0; | ||
| 1429 | return flag; | 1418 | return flag; |
| 1430 | } | 1419 | } |
| 1431 | 1420 | ||
| @@ -1513,7 +1502,7 @@ This does not change the name of the visited file (if any). */) | |||
| 1513 | 1502 | ||
| 1514 | /* Catch redisplay's attention. Unless we do this, the mode lines for | 1503 | /* Catch redisplay's attention. Unless we do this, the mode lines for |
| 1515 | any windows displaying current_buffer will stay unchanged. */ | 1504 | any windows displaying current_buffer will stay unchanged. */ |
| 1516 | update_mode_lines++; | 1505 | update_mode_lines = 11; |
| 1517 | 1506 | ||
| 1518 | XSETBUFFER (buf, current_buffer); | 1507 | XSETBUFFER (buf, current_buffer); |
| 1519 | Fsetcar (Frassq (buf, Vbuffer_alist), newname); | 1508 | Fsetcar (Frassq (buf, Vbuffer_alist), newname); |
| @@ -1798,7 +1787,7 @@ cleaning up all windows currently displaying the buffer to be killed. */) | |||
| 1798 | /* Run replace_buffer_in_windows before making another buffer current | 1787 | /* Run replace_buffer_in_windows before making another buffer current |
| 1799 | since set-window-buffer-start-and-point will refuse to make another | 1788 | since set-window-buffer-start-and-point will refuse to make another |
| 1800 | buffer current if the selected window does not show the current | 1789 | buffer current if the selected window does not show the current |
| 1801 | buffer. (Bug#10114) */ | 1790 | buffer (bug#10114). */ |
| 1802 | replace_buffer_in_windows (buffer); | 1791 | replace_buffer_in_windows (buffer); |
| 1803 | 1792 | ||
| 1804 | /* Exit if replacing the buffer in windows has killed our buffer. */ | 1793 | /* Exit if replacing the buffer in windows has killed our buffer. */ |
| @@ -2074,7 +2063,7 @@ the current buffer's major mode. */) | |||
| 2074 | count = SPECPDL_INDEX (); | 2063 | count = SPECPDL_INDEX (); |
| 2075 | 2064 | ||
| 2076 | /* To select a nonfundamental mode, | 2065 | /* To select a nonfundamental mode, |
| 2077 | select the buffer temporarily and then call the mode function. */ | 2066 | select the buffer temporarily and then call the mode function. */ |
| 2078 | 2067 | ||
| 2079 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | 2068 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
| 2080 | 2069 | ||
| @@ -2114,7 +2103,7 @@ set_buffer_internal_1 (register struct buffer *b) | |||
| 2114 | 2103 | ||
| 2115 | old_buf = current_buffer; | 2104 | old_buf = current_buffer; |
| 2116 | current_buffer = b; | 2105 | current_buffer = b; |
| 2117 | last_known_column_point = -1; /* invalidate indentation cache */ | 2106 | last_known_column_point = -1; /* Invalidate indentation cache. */ |
| 2118 | 2107 | ||
| 2119 | if (old_buf) | 2108 | if (old_buf) |
| 2120 | { | 2109 | { |
| @@ -2138,7 +2127,7 @@ set_buffer_internal_1 (register struct buffer *b) | |||
| 2138 | fetch_buffer_markers (b); | 2127 | fetch_buffer_markers (b); |
| 2139 | 2128 | ||
| 2140 | /* Look down buffer's list of local Lisp variables | 2129 | /* Look down buffer's list of local Lisp variables |
| 2141 | to find and update any that forward into C variables. */ | 2130 | to find and update any that forward into C variables. */ |
| 2142 | 2131 | ||
| 2143 | do | 2132 | do |
| 2144 | { | 2133 | { |
| @@ -2705,7 +2694,7 @@ current buffer is cleared. */) | |||
| 2705 | 2694 | ||
| 2706 | /* If buffer is shown in a window, let redisplay consider other windows. */ | 2695 | /* If buffer is shown in a window, let redisplay consider other windows. */ |
| 2707 | if (buffer_window_count (current_buffer)) | 2696 | if (buffer_window_count (current_buffer)) |
| 2708 | ++windows_or_buffers_changed; | 2697 | windows_or_buffers_changed = 10; |
| 2709 | 2698 | ||
| 2710 | /* Copy this buffer's new multibyte status | 2699 | /* Copy this buffer's new multibyte status |
| 2711 | into all of its indirect buffers. */ | 2700 | into all of its indirect buffers. */ |
| @@ -2765,7 +2754,7 @@ the normal hook `change-major-mode-hook'. */) | |||
| 2765 | 2754 | ||
| 2766 | /* Force mode-line redisplay. Useful here because all major mode | 2755 | /* Force mode-line redisplay. Useful here because all major mode |
| 2767 | commands call this function. */ | 2756 | commands call this function. */ |
| 2768 | update_mode_lines++; | 2757 | update_mode_lines = 12; |
| 2769 | 2758 | ||
| 2770 | return Qnil; | 2759 | return Qnil; |
| 2771 | } | 2760 | } |
| @@ -3911,11 +3900,11 @@ modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end) | |||
| 3911 | { | 3900 | { |
| 3912 | /* ... it's visible in other window than selected, */ | 3901 | /* ... it's visible in other window than selected, */ |
| 3913 | if (buf != XBUFFER (XWINDOW (selected_window)->contents)) | 3902 | if (buf != XBUFFER (XWINDOW (selected_window)->contents)) |
| 3914 | windows_or_buffers_changed = 1; | 3903 | windows_or_buffers_changed = 11; |
| 3915 | /* ... or if we modify an overlay at the end of the buffer | 3904 | /* ... or if we modify an overlay at the end of the buffer |
| 3916 | and so we cannot be sure that window end is still valid. */ | 3905 | and so we cannot be sure that window end is still valid. */ |
| 3917 | else if (end >= ZV && start <= ZV) | 3906 | else if (end >= ZV && start <= ZV) |
| 3918 | windows_or_buffers_changed = 1; | 3907 | windows_or_buffers_changed = 12; |
| 3919 | } | 3908 | } |
| 3920 | 3909 | ||
| 3921 | ++BUF_OVERLAY_MODIFF (buf); | 3910 | ++BUF_OVERLAY_MODIFF (buf); |
| @@ -4534,7 +4523,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after, | |||
| 4534 | Lisp_Object *copy = alloca (size * sizeof *copy); | 4523 | Lisp_Object *copy = alloca (size * sizeof *copy); |
| 4535 | ptrdiff_t i; | 4524 | ptrdiff_t i; |
| 4536 | 4525 | ||
| 4537 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->u.contents, | 4526 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, |
| 4538 | size * word_size); | 4527 | size * word_size); |
| 4539 | gcpro1.var = copy; | 4528 | gcpro1.var = copy; |
| 4540 | gcpro1.nvars = size; | 4529 | gcpro1.nvars = size; |
| @@ -5185,7 +5174,7 @@ init_buffer_once (void) | |||
| 5185 | bset_buffer_file_coding_system (&buffer_defaults, Qnil); | 5174 | bset_buffer_file_coding_system (&buffer_defaults, Qnil); |
| 5186 | XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); | 5175 | XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); |
| 5187 | XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); | 5176 | XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); |
| 5188 | bset_cache_long_scans (&buffer_defaults, Qnil); | 5177 | bset_cache_long_scans (&buffer_defaults, Qt); |
| 5189 | bset_file_truename (&buffer_defaults, Qnil); | 5178 | bset_file_truename (&buffer_defaults, Qnil); |
| 5190 | XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); | 5179 | XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); |
| 5191 | XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); | 5180 | XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); |
| @@ -5349,13 +5338,10 @@ init_buffer (void) | |||
| 5349 | len++; | 5338 | len++; |
| 5350 | } | 5339 | } |
| 5351 | 5340 | ||
| 5341 | /* At this moment, we still don't know how to decode the directory | ||
| 5342 | name. So, we keep the bytes in unibyte form so that file I/O | ||
| 5343 | routines correctly get the original bytes. */ | ||
| 5352 | bset_directory (current_buffer, make_unibyte_string (pwd, len)); | 5344 | bset_directory (current_buffer, make_unibyte_string (pwd, len)); |
| 5353 | if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) | ||
| 5354 | /* At this moment, we still don't know how to decode the | ||
| 5355 | directory name. So, we keep the bytes in multibyte form so | ||
| 5356 | that ENCODE_FILE correctly gets the original bytes. */ | ||
| 5357 | bset_directory | ||
| 5358 | (current_buffer, string_to_multibyte (BVAR (current_buffer, directory))); | ||
| 5359 | 5345 | ||
| 5360 | /* Add /: to the front of the name | 5346 | /* Add /: to the front of the name |
| 5361 | if it would otherwise be treated as magic. */ | 5347 | if it would otherwise be treated as magic. */ |
| @@ -5410,12 +5396,12 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring, | |||
| 5410 | 5396 | ||
| 5411 | if (PER_BUFFER_IDX (offset) == 0) | 5397 | if (PER_BUFFER_IDX (offset) == 0) |
| 5412 | /* Did a DEFVAR_PER_BUFFER without initializing the corresponding | 5398 | /* Did a DEFVAR_PER_BUFFER without initializing the corresponding |
| 5413 | slot of buffer_local_flags */ | 5399 | slot of buffer_local_flags. */ |
| 5414 | emacs_abort (); | 5400 | emacs_abort (); |
| 5415 | } | 5401 | } |
| 5416 | 5402 | ||
| 5417 | 5403 | ||
| 5418 | /* initialize the buffer routines */ | 5404 | /* Initialize the buffer routines. */ |
| 5419 | void | 5405 | void |
| 5420 | syms_of_buffer (void) | 5406 | syms_of_buffer (void) |
| 5421 | { | 5407 | { |
| @@ -5805,7 +5791,8 @@ its value may not be a list of functions. */); | |||
| 5805 | 5791 | ||
| 5806 | DEFVAR_PER_BUFFER ("buffer-file-name", &BVAR (current_buffer, filename), | 5792 | DEFVAR_PER_BUFFER ("buffer-file-name", &BVAR (current_buffer, filename), |
| 5807 | Qstringp, | 5793 | Qstringp, |
| 5808 | doc: /* Name of file visited in current buffer, or nil if not visiting a file. */); | 5794 | doc: /* Name of file visited in current buffer, or nil if not visiting a file. |
| 5795 | This should be an absolute file name. */); | ||
| 5809 | 5796 | ||
| 5810 | DEFVAR_PER_BUFFER ("buffer-file-truename", &BVAR (current_buffer, file_truename), | 5797 | DEFVAR_PER_BUFFER ("buffer-file-truename", &BVAR (current_buffer, file_truename), |
| 5811 | Qstringp, | 5798 | Qstringp, |
| @@ -6305,6 +6292,7 @@ and `bury-buffer-internal'. */); | |||
| 6305 | defsubr (&Sbuffer_local_value); | 6292 | defsubr (&Sbuffer_local_value); |
| 6306 | defsubr (&Sbuffer_local_variables); | 6293 | defsubr (&Sbuffer_local_variables); |
| 6307 | defsubr (&Sbuffer_modified_p); | 6294 | defsubr (&Sbuffer_modified_p); |
| 6295 | defsubr (&Sforce_mode_line_update); | ||
| 6308 | defsubr (&Sset_buffer_modified_p); | 6296 | defsubr (&Sset_buffer_modified_p); |
| 6309 | defsubr (&Sbuffer_modified_tick); | 6297 | defsubr (&Sbuffer_modified_tick); |
| 6310 | defsubr (&Sbuffer_chars_modified_tick); | 6298 | defsubr (&Sbuffer_chars_modified_tick); |