aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2019-03-30 12:01:58 +0300
committerEli Zaretskii2019-03-30 12:01:58 +0300
commit9c0fa1172fd987a8f23b115145270383a11c12fc (patch)
tree251e79c78ada59224c8a9743e4b13dd9c86df6e5 /src
parent273d7b3ee0f4841c7f3f112aeb2e29db51a642e7 (diff)
downloademacs-9c0fa1172fd987a8f23b115145270383a11c12fc.tar.gz
emacs-9c0fa1172fd987a8f23b115145270383a11c12fc.zip
Don't run buffer-related hooks in " *code conversion work*" buffers
Note: portions of this change were mistakenly pushed as part of an unrelated commit a35a1f6a9. * src/buffer.c (Fget_buffer_create): Set inhibit_buffer_hooks non-zero for temporary buffers created by coding.c. Don't run buffer-list-update-hook for such buffers. (Frename_buffer, Fkill_buffer, record_buffer) (Fbury_buffer_internal): Don't run hooks for buffers whose inhibit_buffer_hooks flag is set. * src/buffer.h (struct buffer): New member inhibit_buffer_hooks. * src/pdumper.c (dump_buffer): Dump the new field. Update the hash value in HASH_buffer_XXX. * src/coding.c (make_conversion_work_buffer): Function deleted; code moved to code_conversion_save. (code_conversion_save): Insert code from make_conversion_work_buffer, but arrange for unwind-protecting the current buffer before switching to the work buffer. This avoids leaving reused_workbuf_in_use set if user presses C-g during encoding/decoding. (Vcode_conversion_workbuf_name): Now external variable. * src/coding.h (Vcode_conversion_reused_workbuf): Declare.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c24
-rw-r--r--src/buffer.h7
-rw-r--r--src/coding.c26
-rw-r--r--src/coding.h2
-rw-r--r--src/pdumper.c3
5 files changed, 31 insertions, 31 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 5fabbc253c8..8bdc30300ba 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -37,6 +37,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
37#include "window.h" 37#include "window.h"
38#include "commands.h" 38#include "commands.h"
39#include "character.h" 39#include "character.h"
40#include "coding.h"
40#include "buffer.h" 41#include "buffer.h"
41#include "region-cache.h" 42#include "region-cache.h"
42#include "indent.h" 43#include "indent.h"
@@ -583,6 +584,11 @@ even if it is dead. The return value is never nil. */)
583 set_string_intervals (name, NULL); 584 set_string_intervals (name, NULL);
584 bset_name (b, name); 585 bset_name (b, name);
585 586
587 if (STRINGP (Vcode_conversion_workbuf_name)
588 && strncmp (SSDATA (name), SSDATA (Vcode_conversion_workbuf_name),
589 SBYTES (Vcode_conversion_workbuf_name)) == 0)
590 b->inhibit_buffer_hooks = true;
591
586 bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt); 592 bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt);
587 593
588 reset_buffer (b); 594 reset_buffer (b);
@@ -595,7 +601,7 @@ even if it is dead. The return value is never nil. */)
595 XSETBUFFER (buffer, b); 601 XSETBUFFER (buffer, b);
596 Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buffer))); 602 Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buffer)));
597 /* And run buffer-list-update-hook. */ 603 /* And run buffer-list-update-hook. */
598 if (!NILP (Vrun_hooks)) 604 if (!NILP (Vrun_hooks) && !b->inhibit_buffer_hooks)
599 call1 (Vrun_hooks, Qbuffer_list_update_hook); 605 call1 (Vrun_hooks, Qbuffer_list_update_hook);
600 606
601 return buffer; 607 return buffer;
@@ -1493,7 +1499,7 @@ This does not change the name of the visited file (if any). */)
1493 call0 (intern ("rename-auto-save-file")); 1499 call0 (intern ("rename-auto-save-file"));
1494 1500
1495 /* Run buffer-list-update-hook. */ 1501 /* Run buffer-list-update-hook. */
1496 if (!NILP (Vrun_hooks)) 1502 if (!NILP (Vrun_hooks) && !current_buffer->inhibit_buffer_hooks)
1497 call1 (Vrun_hooks, Qbuffer_list_update_hook); 1503 call1 (Vrun_hooks, Qbuffer_list_update_hook);
1498 1504
1499 /* Refetch since that last call may have done GC. */ 1505 /* Refetch since that last call may have done GC. */
@@ -1706,8 +1712,9 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1706 1712
1707 /* First run the query functions; if any query is answered no, 1713 /* First run the query functions; if any query is answered no,
1708 don't kill the buffer. */ 1714 don't kill the buffer. */
1709 tem = CALLN (Frun_hook_with_args_until_failure, 1715 if (!b->inhibit_buffer_hooks)
1710 Qkill_buffer_query_functions); 1716 tem = CALLN (Frun_hook_with_args_until_failure,
1717 Qkill_buffer_query_functions);
1711 if (NILP (tem)) 1718 if (NILP (tem))
1712 return unbind_to (count, Qnil); 1719 return unbind_to (count, Qnil);
1713 1720
@@ -1726,7 +1733,8 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1726 return unbind_to (count, Qt); 1733 return unbind_to (count, Qt);
1727 1734
1728 /* Then run the hooks. */ 1735 /* Then run the hooks. */
1729 run_hook (Qkill_buffer_hook); 1736 if (!b->inhibit_buffer_hooks)
1737 run_hook (Qkill_buffer_hook);
1730 unbind_to (count, Qnil); 1738 unbind_to (count, Qnil);
1731 } 1739 }
1732 1740
@@ -1928,7 +1936,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1928 bset_undo_list (b, Qnil); 1936 bset_undo_list (b, Qnil);
1929 1937
1930 /* Run buffer-list-update-hook. */ 1938 /* Run buffer-list-update-hook. */
1931 if (!NILP (Vrun_hooks)) 1939 if (!NILP (Vrun_hooks) && !b->inhibit_buffer_hooks)
1932 call1 (Vrun_hooks, Qbuffer_list_update_hook); 1940 call1 (Vrun_hooks, Qbuffer_list_update_hook);
1933 1941
1934 return Qt; 1942 return Qt;
@@ -1970,7 +1978,7 @@ record_buffer (Lisp_Object buffer)
1970 fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list)); 1978 fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list));
1971 1979
1972 /* Run buffer-list-update-hook. */ 1980 /* Run buffer-list-update-hook. */
1973 if (!NILP (Vrun_hooks)) 1981 if (!NILP (Vrun_hooks) && !XBUFFER (buffer)->inhibit_buffer_hooks)
1974 call1 (Vrun_hooks, Qbuffer_list_update_hook); 1982 call1 (Vrun_hooks, Qbuffer_list_update_hook);
1975} 1983}
1976 1984
@@ -2009,7 +2017,7 @@ DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal,
2009 (f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list))); 2017 (f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list)));
2010 2018
2011 /* Run buffer-list-update-hook. */ 2019 /* Run buffer-list-update-hook. */
2012 if (!NILP (Vrun_hooks)) 2020 if (!NILP (Vrun_hooks) && !XBUFFER (buffer)->inhibit_buffer_hooks)
2013 call1 (Vrun_hooks, Qbuffer_list_update_hook); 2021 call1 (Vrun_hooks, Qbuffer_list_update_hook);
2014 2022
2015 return Qnil; 2023 return Qnil;
diff --git a/src/buffer.h b/src/buffer.h
index d3528ac50e9..63b162161c6 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -855,6 +855,13 @@ struct buffer
855 /* Non-zero whenever the narrowing is changed in this buffer. */ 855 /* Non-zero whenever the narrowing is changed in this buffer. */
856 bool_bf clip_changed : 1; 856 bool_bf clip_changed : 1;
857 857
858 /* Non-zero for internally used temporary buffers that don't need to
859 run hooks kill-buffer-hook, buffer-list-update-hook, and
860 kill-buffer-query-functions. This is used in coding.c to avoid
861 slowing down en/decoding when there are a lot of these hooks
862 defined. */
863 bool_bf inhibit_buffer_hooks : 1;
864
858 /* List of overlays that end at or before the current center, 865 /* List of overlays that end at or before the current center,
859 in order of end-position. */ 866 in order of end-position. */
860 struct Lisp_Overlay *overlays_before; 867 struct Lisp_Overlay *overlays_before;
diff --git a/src/coding.c b/src/coding.c
index c6d96436770..e351cc72fab 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -7785,7 +7785,7 @@ encode_coding (struct coding_system *coding)
7785 7785
7786 7786
7787/* Name (or base name) of work buffer for code conversion. */ 7787/* Name (or base name) of work buffer for code conversion. */
7788static Lisp_Object Vcode_conversion_workbuf_name; 7788Lisp_Object Vcode_conversion_workbuf_name;
7789 7789
7790/* A working buffer used by the top level conversion. Once it is 7790/* A working buffer used by the top level conversion. Once it is
7791 created, it is never destroyed. It has the name 7791 created, it is never destroyed. It has the name
@@ -7797,7 +7797,6 @@ static Lisp_Object Vcode_conversion_reused_workbuf;
7797/* True iff Vcode_conversion_reused_workbuf is already in use. */ 7797/* True iff Vcode_conversion_reused_workbuf is already in use. */
7798static bool reused_workbuf_in_use; 7798static bool reused_workbuf_in_use;
7799 7799
7800
7801static void 7800static void
7802code_conversion_restore (Lisp_Object arg) 7801code_conversion_restore (Lisp_Object arg)
7803{ 7802{
@@ -7810,12 +7809,7 @@ code_conversion_restore (Lisp_Object arg)
7810 if (EQ (workbuf, Vcode_conversion_reused_workbuf)) 7809 if (EQ (workbuf, Vcode_conversion_reused_workbuf))
7811 reused_workbuf_in_use = 0; 7810 reused_workbuf_in_use = 0;
7812 else 7811 else
7813 { 7812 Fkill_buffer (workbuf);
7814 ptrdiff_t count = SPECPDL_INDEX ();
7815 specbind (Qbuffer_list_update_hook, Qnil);
7816 Fkill_buffer (workbuf);
7817 unbind_to (count, Qnil);
7818 }
7819 } 7813 }
7820 set_buffer_internal (XBUFFER (current)); 7814 set_buffer_internal (XBUFFER (current));
7821} 7815}
@@ -7827,24 +7821,17 @@ code_conversion_save (bool with_work_buf, bool multibyte)
7827 7821
7828 if (with_work_buf) 7822 if (with_work_buf)
7829 { 7823 {
7830 ptrdiff_t count = SPECPDL_INDEX ();
7831 if (reused_workbuf_in_use) 7824 if (reused_workbuf_in_use)
7832 { 7825 {
7833 Lisp_Object name 7826 Lisp_Object name
7834 = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); 7827 = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil);
7835 specbind (Qbuffer_list_update_hook, Qnil);
7836 workbuf = Fget_buffer_create (name); 7828 workbuf = Fget_buffer_create (name);
7837 unbind_to (count, Qnil);
7838 } 7829 }
7839 else 7830 else
7840 { 7831 {
7841 if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf))) 7832 if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf)))
7842 { 7833 Vcode_conversion_reused_workbuf
7843 specbind (Qbuffer_list_update_hook, Qnil); 7834 = Fget_buffer_create (Vcode_conversion_workbuf_name);
7844 Vcode_conversion_reused_workbuf
7845 = Fget_buffer_create (Vcode_conversion_workbuf_name);
7846 unbind_to (count, Qnil);
7847 }
7848 workbuf = Vcode_conversion_reused_workbuf; 7835 workbuf = Vcode_conversion_reused_workbuf;
7849 } 7836 }
7850 } 7837 }
@@ -7863,11 +7850,6 @@ code_conversion_save (bool with_work_buf, bool multibyte)
7863 bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil); 7850 bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil);
7864 if (EQ (workbuf, Vcode_conversion_reused_workbuf)) 7851 if (EQ (workbuf, Vcode_conversion_reused_workbuf))
7865 reused_workbuf_in_use = 1; 7852 reused_workbuf_in_use = 1;
7866 else
7867 {
7868 Fset (Fmake_local_variable (Qkill_buffer_query_functions), Qnil);
7869 Fset (Fmake_local_variable (Qkill_buffer_hook), Qnil);
7870 }
7871 set_buffer_internal (current); 7853 set_buffer_internal (current);
7872 } 7854 }
7873 7855
diff --git a/src/coding.h b/src/coding.h
index e38c0ee3968..0c03d1a44ed 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -97,6 +97,8 @@ enum define_coding_undecided_arg_index
97 97
98extern Lisp_Object Vcoding_system_hash_table; 98extern Lisp_Object Vcoding_system_hash_table;
99 99
100/* Name (or base name) of work buffer for code conversion. */
101extern Lisp_Object Vcode_conversion_workbuf_name;
100 102
101/* Enumeration of index to an attribute vector of a coding system. */ 103/* Enumeration of index to an attribute vector of a coding system. */
102 104
diff --git a/src/pdumper.c b/src/pdumper.c
index 8116c75ae8e..a9b3732a2d4 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2761,7 +2761,7 @@ dump_hash_table (struct dump_context *ctx,
2761static dump_off 2761static dump_off
2762dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer) 2762dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer)
2763{ 2763{
2764#if CHECK_STRUCTS && !defined HASH_buffer_AE2C8CE357 2764#if CHECK_STRUCTS && !defined HASH_buffer_2CEE653E74
2765# error "buffer changed. See CHECK_STRUCTS comment." 2765# error "buffer changed. See CHECK_STRUCTS comment."
2766#endif 2766#endif
2767 struct buffer munged_buffer = *in_buffer; 2767 struct buffer munged_buffer = *in_buffer;
@@ -2873,6 +2873,7 @@ dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer)
2873 2873
2874 DUMP_FIELD_COPY (out, buffer, prevent_redisplay_optimizations_p); 2874 DUMP_FIELD_COPY (out, buffer, prevent_redisplay_optimizations_p);
2875 DUMP_FIELD_COPY (out, buffer, clip_changed); 2875 DUMP_FIELD_COPY (out, buffer, clip_changed);
2876 DUMP_FIELD_COPY (out, buffer, inhibit_buffer_hooks);
2876 2877
2877 dump_field_lv_rawptr (ctx, out, buffer, &buffer->overlays_before, 2878 dump_field_lv_rawptr (ctx, out, buffer, &buffer->overlays_before,
2878 Lisp_Vectorlike, WEIGHT_NORMAL); 2879 Lisp_Vectorlike, WEIGHT_NORMAL);