diff options
author | Po Lu <luangruo@yahoo.com> | 2022-07-11 19:36:01 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-07-11 19:36:12 +0800 |
commit | 6f57fb71a50a8b2ac8163828a2cecb394bb52d06 (patch) | |
tree | 02cbe006bbd8ec919f6bf3ed32a1fbd1d23048ac /src/keyboard.c | |
parent | 2f823ffd28d064fc8c1a3947e74c512b577863c6 (diff) | |
download | emacs-6f57fb71a50a8b2ac8163828a2cecb394bb52d06.tar.gz |
Improve behavior of `lost-selection-mode' with multiple buffers
* etc/NEWS: Announce new hook `post-select-region-hook'.
* lisp/select.el (lost-selection-last-region-buffer): New
variable.
(lost-selection-post-select-region-function): New function.
Deactivate the mark if the buffer changed.
(lost-selection-mode): Add new hook.
* src/keyboard.c (command_loop_1): Run that hook when
appropriate.
(syms_of_keyboard): New hook `post-select-region-hook'.
Diffstat (limited to 'src/keyboard.c')
-rw-r--r-- | src/keyboard.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index 7c13ac96114..1d505c13be3 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1590,9 +1590,12 @@ command_loop_1 (void) { Lisp_Object txt = call1 (Vregion_extract_function, Qnil); + if (XFIXNUM (Flength (txt)) > 0) /* Don't set empty selections. */ call2 (Qgui_set_selection, QPRIMARY, txt); + + CALLN (Frun_hook_with_args, Qpost_select_region_hook, txt); } if (current_buffer != prev_buffer || MODIFF != prev_modiff) @@ -12080,6 +12083,9 @@ syms_of_keyboard (void) DEFSYM (Qpre_command_hook, "pre-command-hook"); DEFSYM (Qpost_command_hook, "post-command-hook"); + /* Hook run after the region is selected. */ + DEFSYM (Qpost_select_region_hook, "post-select-region-hook"); + DEFSYM (Qundo_auto__add_boundary, "undo-auto--add-boundary"); DEFSYM (Qundo_auto__undoably_changed_buffers, "undo-auto--undoably-changed-buffers"); @@ -13028,6 +13034,12 @@ not recorded. The non-nil value countermands `inhibit--record-char', which see. */); record_all_keys = false; + DEFVAR_LISP ("post-select-region-hook", Vpost_select_region_hook, + doc: /* Abnormal hook run after the region is selected. +This usually happens as a result of `select-active-regions'. The hook +is called with one argument, the string that was selected. */);; + Vpost_select_region_hook = Qnil; + pdumper_do_now_and_after_load (syms_of_keyboard_for_pdumper); } |