aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorYuuki Harano2021-11-11 00:39:53 +0900
committerYuuki Harano2021-11-11 00:39:53 +0900
commit4dd1f56f29fc598a8339a345c2f8945250600602 (patch)
treeaf341efedffe027e533b1bcc0dbf270532e48285 /src/buffer.c
parent4c49ec7f865bdad1629d2f125f71f4e506b258f2 (diff)
parent810fa21d26453f898de9747ece7205dfe6de9d08 (diff)
downloademacs-4dd1f56f29fc598a8339a345c2f8945250600602.tar.gz
emacs-4dd1f56f29fc598a8339a345c2f8945250600602.zip
Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c83
1 files changed, 53 insertions, 30 deletions
diff --git a/src/buffer.c b/src/buffer.c
index b177c5eaa7f..9d8892a797a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1434,7 +1434,7 @@ and `buffer-file-truename' are non-nil. */)
1434DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p, 1434DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p,
1435 Srestore_buffer_modified_p, 1, 1, 0, 1435 Srestore_buffer_modified_p, 1, 1, 0,
1436 doc: /* Like `set-buffer-modified-p', but doesn't redisplay buffer's mode line. 1436 doc: /* Like `set-buffer-modified-p', but doesn't redisplay buffer's mode line.
1437This function also locks and unlocks the file visited by the buffer, 1437This function also locks or unlocks the file visited by the buffer,
1438if both `buffer-file-truename' and `buffer-file-name' are non-nil. 1438if both `buffer-file-truename' and `buffer-file-name' are non-nil.
1439 1439
1440It is not ensured that mode lines will be updated to show the modified 1440It is not ensured that mode lines will be updated to show the modified
@@ -1768,6 +1768,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1768 /* Run hooks with the buffer to be killed as the current buffer. */ 1768 /* Run hooks with the buffer to be killed as the current buffer. */
1769 { 1769 {
1770 ptrdiff_t count = SPECPDL_INDEX (); 1770 ptrdiff_t count = SPECPDL_INDEX ();
1771 bool modified;
1771 1772
1772 record_unwind_protect_excursion (); 1773 record_unwind_protect_excursion ();
1773 set_buffer_internal (b); 1774 set_buffer_internal (b);
@@ -1782,9 +1783,12 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1782 return unbind_to (count, Qnil); 1783 return unbind_to (count, Qnil);
1783 } 1784 }
1784 1785
1786 /* Is this a modified buffer that's visiting a file? */
1787 modified = !NILP (BVAR (b, filename))
1788 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b);
1789
1785 /* Query if the buffer is still modified. */ 1790 /* Query if the buffer is still modified. */
1786 if (INTERACTIVE && !NILP (BVAR (b, filename)) 1791 if (INTERACTIVE && modified)
1787 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
1788 { 1792 {
1789 AUTO_STRING (format, "Buffer %s modified; kill anyway? "); 1793 AUTO_STRING (format, "Buffer %s modified; kill anyway? ");
1790 tem = do_yes_or_no_p (CALLN (Fformat, format, BVAR (b, name))); 1794 tem = do_yes_or_no_p (CALLN (Fformat, format, BVAR (b, name)));
@@ -1792,6 +1796,23 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1792 return unbind_to (count, Qnil); 1796 return unbind_to (count, Qnil);
1793 } 1797 }
1794 1798
1799 /* Delete the autosave file, if requested. */
1800 if (modified
1801 && kill_buffer_delete_auto_save_files
1802 && delete_auto_save_files
1803 && !NILP (Frecent_auto_save_p ())
1804 && STRINGP (BVAR (b, auto_save_file_name))
1805 && !NILP (Ffile_exists_p (BVAR (b, auto_save_file_name)))
1806 /* If `auto-save-visited-mode' is on, then we're auto-saving
1807 to the visited file -- don't delete it.. */
1808 && NILP (Fstring_equal (BVAR (b, auto_save_file_name),
1809 BVAR (b, filename))))
1810 {
1811 tem = do_yes_or_no_p (build_string ("Delete auto-save file? "));
1812 if (!NILP (tem))
1813 call0 (intern ("delete-auto-save-file-if-necessary"));
1814 }
1815
1795 /* If the hooks have killed the buffer, exit now. */ 1816 /* If the hooks have killed the buffer, exit now. */
1796 if (!BUFFER_LIVE_P (b)) 1817 if (!BUFFER_LIVE_P (b))
1797 return unbind_to (count, Qt); 1818 return unbind_to (count, Qt);
@@ -1888,24 +1909,6 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1888 replace_buffer_in_windows_safely (buffer); 1909 replace_buffer_in_windows_safely (buffer);
1889 Vinhibit_quit = tem; 1910 Vinhibit_quit = tem;
1890 1911
1891 /* Delete any auto-save file, if we saved it in this session.
1892 But not if the buffer is modified. */
1893 if (STRINGP (BVAR (b, auto_save_file_name))
1894 && BUF_AUTOSAVE_MODIFF (b) != 0
1895 && BUF_SAVE_MODIFF (b) < BUF_AUTOSAVE_MODIFF (b)
1896 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)
1897 && NILP (Fsymbol_value (intern ("auto-save-visited-file-name"))))
1898 {
1899 Lisp_Object delete;
1900 delete = Fsymbol_value (intern ("delete-auto-save-files"));
1901 if (! NILP (delete))
1902 internal_delete_file (BVAR (b, auto_save_file_name));
1903 }
1904
1905 /* Deleting an auto-save file could have killed our buffer. */
1906 if (!BUFFER_LIVE_P (b))
1907 return Qt;
1908
1909 if (b->base_buffer) 1912 if (b->base_buffer)
1910 { 1913 {
1911 INTERVAL i; 1914 INTERVAL i;
@@ -2802,7 +2805,7 @@ current buffer is cleared. */)
2802} 2805}
2803 2806
2804DEFUN ("kill-all-local-variables", Fkill_all_local_variables, 2807DEFUN ("kill-all-local-variables", Fkill_all_local_variables,
2805 Skill_all_local_variables, 0, 0, 0, 2808 Skill_all_local_variables, 0, 1, 0,
2806 doc: /* Switch to Fundamental mode by killing current buffer's local variables. 2809 doc: /* Switch to Fundamental mode by killing current buffer's local variables.
2807Most local variable bindings are eliminated so that the default values 2810Most local variable bindings are eliminated so that the default values
2808become effective once more. Also, the syntax table is set from 2811become effective once more. Also, the syntax table is set from
@@ -2813,18 +2816,20 @@ This function also forces redisplay of the mode line.
2813Every function to select a new major mode starts by 2816Every function to select a new major mode starts by
2814calling this function. 2817calling this function.
2815 2818
2816As a special exception, local variables whose names have 2819As a special exception, local variables whose names have a non-nil
2817a non-nil `permanent-local' property are not eliminated by this function. 2820`permanent-local' property are not eliminated by this function. If
2821the optional KILL-PERMANENT argument is non-nil, clear out these local
2822variables, too.
2818 2823
2819The first thing this function does is run 2824The first thing this function does is run
2820the normal hook `change-major-mode-hook'. */) 2825the normal hook `change-major-mode-hook'. */)
2821 (void) 2826 (Lisp_Object kill_permanent)
2822{ 2827{
2823 run_hook (Qchange_major_mode_hook); 2828 run_hook (Qchange_major_mode_hook);
2824 2829
2825 /* Actually eliminate all local bindings of this buffer. */ 2830 /* Actually eliminate all local bindings of this buffer. */
2826 2831
2827 reset_buffer_local_variables (current_buffer, 0); 2832 reset_buffer_local_variables (current_buffer, !NILP (kill_permanent));
2828 2833
2829 /* Force mode-line redisplay. Useful here because all major mode 2834 /* Force mode-line redisplay. Useful here because all major mode
2830 commands call this function. */ 2835 commands call this function. */
@@ -2995,7 +3000,7 @@ overlays_in (EMACS_INT beg, EMACS_INT end, bool extend,
2995 ptrdiff_t next = ZV; 3000 ptrdiff_t next = ZV;
2996 ptrdiff_t prev = BEGV; 3001 ptrdiff_t prev = BEGV;
2997 bool inhibit_storing = 0; 3002 bool inhibit_storing = 0;
2998 bool end_is_Z = end == Z; 3003 bool end_is_Z = end == ZV;
2999 3004
3000 for (struct Lisp_Overlay *tail = current_buffer->overlays_before; 3005 for (struct Lisp_Overlay *tail = current_buffer->overlays_before;
3001 tail; tail = tail->next) 3006 tail; tail = tail->next)
@@ -3840,7 +3845,9 @@ fix_overlays_before (struct buffer *bp, ptrdiff_t prev, ptrdiff_t pos)
3840 or the found one ends before PREV, 3845 or the found one ends before PREV,
3841 or the found one is the last one in the list, 3846 or the found one is the last one in the list,
3842 we don't have to fix anything. */ 3847 we don't have to fix anything. */
3843 if (!tail || end < prev || !tail->next) 3848 if (!tail)
3849 return;
3850 if (end < prev || !tail->next)
3844 return; 3851 return;
3845 3852
3846 right_pair = parent; 3853 right_pair = parent;
@@ -4268,9 +4275,10 @@ DEFUN ("overlays-in", Foverlays_in, Soverlays_in, 2, 2, 0,
4268 doc: /* Return a list of the overlays that overlap the region BEG ... END. 4275 doc: /* Return a list of the overlays that overlap the region BEG ... END.
4269Overlap means that at least one character is contained within the overlay 4276Overlap means that at least one character is contained within the overlay
4270and also contained within the specified region. 4277and also contained within the specified region.
4278
4271Empty overlays are included in the result if they are located at BEG, 4279Empty overlays are included in the result if they are located at BEG,
4272between BEG and END, or at END provided END denotes the position at the 4280between BEG and END, or at END provided END denotes the position at the
4273end of the buffer. */) 4281end of the accessible part of the buffer. */)
4274 (Lisp_Object beg, Lisp_Object end) 4282 (Lisp_Object beg, Lisp_Object end)
4275{ 4283{
4276 ptrdiff_t len, noverlays; 4284 ptrdiff_t len, noverlays;
@@ -5801,7 +5809,10 @@ Note that this is overridden by the variable
5801`truncate-partial-width-windows' if that variable is non-nil 5809`truncate-partial-width-windows' if that variable is non-nil
5802and this buffer is not full-frame width. 5810and this buffer is not full-frame width.
5803 5811
5804Minibuffers set this variable to nil. */); 5812Minibuffers set this variable to nil.
5813
5814Don't set this to a non-nil value when `visual-line-mode' is
5815turned on, as it could produce confusing results. */);
5805 5816
5806 DEFVAR_PER_BUFFER ("word-wrap", &BVAR (current_buffer, word_wrap), Qnil, 5817 DEFVAR_PER_BUFFER ("word-wrap", &BVAR (current_buffer, word_wrap), Qnil,
5807 doc: /* Non-nil means to use word-wrapping for continuation lines. 5818 doc: /* Non-nil means to use word-wrapping for continuation lines.
@@ -6365,6 +6376,18 @@ nil NORECORD argument since it may lead to infinite recursion. */);
6365 Vbuffer_list_update_hook = Qnil; 6376 Vbuffer_list_update_hook = Qnil;
6366 DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook"); 6377 DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook");
6367 6378
6379 DEFVAR_BOOL ("kill-buffer-delete-auto-save-files",
6380 kill_buffer_delete_auto_save_files,
6381 doc: /* If non-nil, offer to delete any autosave file when killing a buffer.
6382
6383If `delete-auto-save-files' is nil, any autosave deletion is inhibited. */);
6384 kill_buffer_delete_auto_save_files = 0;
6385
6386 DEFVAR_BOOL ("delete-auto-save-files", delete_auto_save_files,
6387 doc: /* Non-nil means delete auto-save file when a buffer is saved.
6388This is the default. If nil, auto-save file deletion is inhibited. */);
6389 delete_auto_save_files = 1;
6390
6368 defsubr (&Sbuffer_live_p); 6391 defsubr (&Sbuffer_live_p);
6369 defsubr (&Sbuffer_list); 6392 defsubr (&Sbuffer_list);
6370 defsubr (&Sget_buffer); 6393 defsubr (&Sget_buffer);