diff options
Diffstat (limited to 'src/keyboard.c')
| -rw-r--r-- | src/keyboard.c | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index 2863058d633..02e02448ff8 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -1295,7 +1295,8 @@ command_loop_1 (void) | |||
| 1295 | /* Note that the value cell will never directly contain nil | 1295 | /* Note that the value cell will never directly contain nil |
| 1296 | if the symbol is a local variable. */ | 1296 | if the symbol is a local variable. */ |
| 1297 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) | 1297 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) |
| 1298 | safe_run_hooks (Qpost_command_hook); | 1298 | safe_run_hooks_maybe_narrowed (Qpost_command_hook, |
| 1299 | XWINDOW (selected_window)); | ||
| 1299 | 1300 | ||
| 1300 | /* If displaying a message, resize the echo area window to fit | 1301 | /* If displaying a message, resize the echo area window to fit |
| 1301 | that message's size exactly. */ | 1302 | that message's size exactly. */ |
| @@ -1461,7 +1462,9 @@ command_loop_1 (void) | |||
| 1461 | } | 1462 | } |
| 1462 | Vthis_command = cmd; | 1463 | Vthis_command = cmd; |
| 1463 | Vreal_this_command = cmd; | 1464 | Vreal_this_command = cmd; |
| 1464 | safe_run_hooks (Qpre_command_hook); | 1465 | |
| 1466 | safe_run_hooks_maybe_narrowed (Qpre_command_hook, | ||
| 1467 | XWINDOW (selected_window)); | ||
| 1465 | 1468 | ||
| 1466 | already_adjusted = 0; | 1469 | already_adjusted = 0; |
| 1467 | 1470 | ||
| @@ -1513,7 +1516,8 @@ command_loop_1 (void) | |||
| 1513 | } | 1516 | } |
| 1514 | kset_last_prefix_arg (current_kboard, Vcurrent_prefix_arg); | 1517 | kset_last_prefix_arg (current_kboard, Vcurrent_prefix_arg); |
| 1515 | 1518 | ||
| 1516 | safe_run_hooks (Qpost_command_hook); | 1519 | safe_run_hooks_maybe_narrowed (Qpost_command_hook, |
| 1520 | XWINDOW (selected_window)); | ||
| 1517 | 1521 | ||
| 1518 | /* If displaying a message, resize the echo area window to fit | 1522 | /* If displaying a message, resize the echo area window to fit |
| 1519 | that message's size exactly. Do this only if the echo area | 1523 | that message's size exactly. Do this only if the echo area |
| @@ -1895,6 +1899,22 @@ safe_run_hooks (Lisp_Object hook) | |||
| 1895 | unbind_to (count, Qnil); | 1899 | unbind_to (count, Qnil); |
| 1896 | } | 1900 | } |
| 1897 | 1901 | ||
| 1902 | void | ||
| 1903 | safe_run_hooks_maybe_narrowed (Lisp_Object hook, struct window *w) | ||
| 1904 | { | ||
| 1905 | specpdl_ref count = SPECPDL_INDEX (); | ||
| 1906 | |||
| 1907 | specbind (Qinhibit_quit, Qt); | ||
| 1908 | |||
| 1909 | if (current_buffer->long_line_optimizations_p) | ||
| 1910 | narrow_to_region_internal (make_fixnum (get_narrowed_begv (w, PT)), | ||
| 1911 | make_fixnum (get_narrowed_zv (w, PT)), | ||
| 1912 | true); | ||
| 1913 | |||
| 1914 | run_hook_with_args (2, ((Lisp_Object []) {hook, hook}), safe_run_hook_funcall); | ||
| 1915 | unbind_to (count, Qnil); | ||
| 1916 | } | ||
| 1917 | |||
| 1898 | 1918 | ||
| 1899 | /* Nonzero means polling for input is temporarily suppressed. */ | 1919 | /* Nonzero means polling for input is temporarily suppressed. */ |
| 1900 | 1920 | ||
| @@ -12622,23 +12642,39 @@ Buffer modification stores t in this variable. */); | |||
| 12622 | 12642 | ||
| 12623 | DEFVAR_LISP ("pre-command-hook", Vpre_command_hook, | 12643 | DEFVAR_LISP ("pre-command-hook", Vpre_command_hook, |
| 12624 | doc: /* Normal hook run before each command is executed. | 12644 | doc: /* Normal hook run before each command is executed. |
| 12625 | If an unhandled error happens in running this hook, | 12645 | |
| 12626 | the function in which the error occurred is unconditionally removed, since | 12646 | If an unhandled error happens in running this hook, the function in |
| 12627 | otherwise the error might happen repeatedly and make Emacs nonfunctional. | 12647 | which the error occurred is unconditionally removed, since otherwise |
| 12648 | the error might happen repeatedly and make Emacs nonfunctional. | ||
| 12649 | |||
| 12650 | Note that, when the current buffer contains one or more lines whose | ||
| 12651 | length is above `long-line-threshold', these hook functions are called | ||
| 12652 | with the buffer narrowed to a small portion around point, and the | ||
| 12653 | narrowing is locked (see `narrow-to-region'), so that these hook | ||
| 12654 | functions cannot use `widen' to gain access to other portions of | ||
| 12655 | buffer text. | ||
| 12628 | 12656 | ||
| 12629 | See also `post-command-hook'. */); | 12657 | See also `post-command-hook'. */); |
| 12630 | Vpre_command_hook = Qnil; | 12658 | Vpre_command_hook = Qnil; |
| 12631 | 12659 | ||
| 12632 | DEFVAR_LISP ("post-command-hook", Vpost_command_hook, | 12660 | DEFVAR_LISP ("post-command-hook", Vpost_command_hook, |
| 12633 | doc: /* Normal hook run after each command is executed. | 12661 | doc: /* Normal hook run after each command is executed. |
| 12634 | If an unhandled error happens in running this hook, | 12662 | |
| 12635 | the function in which the error occurred is unconditionally removed, since | 12663 | If an unhandled error happens in running this hook, the function in |
| 12636 | otherwise the error might happen repeatedly and make Emacs nonfunctional. | 12664 | which the error occurred is unconditionally removed, since otherwise |
| 12665 | the error might happen repeatedly and make Emacs nonfunctional. | ||
| 12637 | 12666 | ||
| 12638 | It is a bad idea to use this hook for expensive processing. If | 12667 | It is a bad idea to use this hook for expensive processing. If |
| 12639 | unavoidable, wrap your code in `(while-no-input (redisplay) CODE)' to | 12668 | unavoidable, wrap your code in `(while-no-input (redisplay) CODE)' to |
| 12640 | avoid making Emacs unresponsive while the user types. | 12669 | avoid making Emacs unresponsive while the user types. |
| 12641 | 12670 | ||
| 12671 | Note that, when the current buffer contains one or more lines whose | ||
| 12672 | length is above `long-line-threshold', these hook functions are called | ||
| 12673 | with the buffer narrowed to a small portion around point, and the | ||
| 12674 | narrowing is locked (see `narrow-to-region'), so that these hook | ||
| 12675 | functions cannot use `widen' to gain access to other portions of | ||
| 12676 | buffer text. | ||
| 12677 | |||
| 12642 | See also `pre-command-hook'. */); | 12678 | See also `pre-command-hook'. */); |
| 12643 | Vpost_command_hook = Qnil; | 12679 | Vpost_command_hook = Qnil; |
| 12644 | 12680 | ||