/* Note that the value cell will never directly contain nil
if the symbol is a local variable. */
if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks))
- safe_run_hooks (Qpost_command_hook);
+ safe_run_hooks_maybe_narrowed (Qpost_command_hook,
+ XWINDOW (selected_window));
/* If displaying a message, resize the echo area window to fit
that message's size exactly. */
}
Vthis_command = cmd;
Vreal_this_command = cmd;
- safe_run_hooks (Qpre_command_hook);
+
+ safe_run_hooks_maybe_narrowed (Qpre_command_hook,
+ XWINDOW (selected_window));
already_adjusted = 0;
}
kset_last_prefix_arg (current_kboard, Vcurrent_prefix_arg);
- safe_run_hooks (Qpost_command_hook);
+ safe_run_hooks_maybe_narrowed (Qpost_command_hook,
+ XWINDOW (selected_window));
/* If displaying a message, resize the echo area window to fit
that message's size exactly. Do this only if the echo area
unbind_to (count, Qnil);
}
+void
+safe_run_hooks_maybe_narrowed (Lisp_Object hook, struct window *w)
+{
+ specpdl_ref count = SPECPDL_INDEX ();
+
+ specbind (Qinhibit_quit, Qt);
+
+ if (current_buffer->long_line_optimizations_p)
+ {
+ ptrdiff_t begv = get_narrowed_begv (w, PT);
+ ptrdiff_t zv = get_narrowed_zv (w, PT);
+ if (!begv) begv = BEGV;
+ Fnarrow_to_region (make_fixnum (begv), make_fixnum (zv), Qt);
+ }
+
+ run_hook_with_args (2, ((Lisp_Object []) {hook, hook}), safe_run_hook_funcall);
+ unbind_to (count, Qnil);
+}
+
\f
/* Nonzero means polling for input is temporarily suppressed. */
DEFVAR_LISP ("pre-command-hook", Vpre_command_hook,
doc: /* Normal hook run before each command is executed.
-If an unhandled error happens in running this hook,
-the function in which the error occurred is unconditionally removed, since
-otherwise the error might happen repeatedly and make Emacs nonfunctional.
+
+If an unhandled error happens in running this hook, the function in
+which the error occurred is unconditionally removed, since otherwise
+the error might happen repeatedly and make Emacs nonfunctional.
+
+Note that, when the current buffer contains one or more lines whose
+length is above `long-line-threshold', these hook functions are called
+with the buffer narrowed to a small portion around point, and the
+narrowing is locked (see `narrow-to-region'), so that these hook
+functions cannot use `widen' to gain access to other portions of
+buffer text.
See also `post-command-hook'. */);
Vpre_command_hook = Qnil;
DEFVAR_LISP ("post-command-hook", Vpost_command_hook,
doc: /* Normal hook run after each command is executed.
-If an unhandled error happens in running this hook,
-the function in which the error occurred is unconditionally removed, since
-otherwise the error might happen repeatedly and make Emacs nonfunctional.
+
+If an unhandled error happens in running this hook, the function in
+which the error occurred is unconditionally removed, since otherwise
+the error might happen repeatedly and make Emacs nonfunctional.
It is a bad idea to use this hook for expensive processing. If
unavoidable, wrap your code in `(while-no-input (redisplay) CODE)' to
avoid making Emacs unresponsive while the user types.
+Note that, when the current buffer contains one or more lines whose
+length is above `long-line-threshold', these hook functions are called
+with the buffer narrowed to a small portion around point, and the
+narrowing is locked (see `narrow-to-region'), so that these hook
+functions cannot use `widen' to gain access to other portions of
+buffer text.
+
See also `pre-command-hook'. */);
Vpost_command_hook = Qnil;