summaryrefslogtreecommitdiff
path: root/src/keyboard.c
diff options
context:
space:
mode:
authorGregory Heytings <gregory@heytings.org>2022-10-30 17:00:35 +0100
committerGregory Heytings <gregory@heytings.org>2022-10-30 17:00:35 +0100
commitaef803d6c3d61004f15d0bc82fa7bf9952302312 (patch)
tree087c444f788cda27006ddc066ad430f62f5ac02a /src/keyboard.c
parent3bf19c417fd39766ee9c7a793c9faadd3bd88478 (diff)
parent3fa4cca3d244f51e471e7779c934278731fc21e9 (diff)
downloademacs-aef803d6c3d61004f15d0bc82fa7bf9952302312.tar.gz
Merge master into feature/improved-locked-narrowing.
Diffstat (limited to 'src/keyboard.c')
-rw-r--r--src/keyboard.c101
1 files changed, 42 insertions, 59 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index 4948ea40e40..d8796569cd2 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -499,27 +499,18 @@ echo_add_key (Lisp_Object c)
STRING_MULTIBYTE (name), 1);
}
+ Lisp_Object new_string = make_string (buffer, ptr - buffer);
if ((NILP (echo_string) || SCHARS (echo_string) == 0)
&& help_char_p (c))
{
- static const char text[] = " (Type ? for further options)";
- int len = sizeof text - 1;
-
- if (size - (ptr - buffer) < len)
- {
- ptrdiff_t offset = ptr - buffer;
- size += len;
- buffer = SAFE_ALLOCA (size);
- ptr = buffer + offset;
- }
-
- memcpy (ptr, text, len);
- ptr += len;
+ AUTO_STRING (str, " (Type ? for further options)");
+ AUTO_LIST2 (props, Qface, Qhelp_key_binding);
+ Fadd_text_properties (make_fixnum (7), make_fixnum (8), props, str);
+ new_string = concat2 (new_string, str);
}
- kset_echo_string
- (current_kboard,
- concat2 (echo_string, make_string (buffer, ptr - buffer)));
+ kset_echo_string (current_kboard,
+ concat2 (echo_string, new_string));
SAFE_FREE ();
}
@@ -1277,7 +1268,6 @@ command_loop_1 (void)
{
modiff_count prev_modiff = 0;
struct buffer *prev_buffer = NULL;
- bool already_adjusted = 0;
kset_prefix_arg (current_kboard, Qnil);
kset_last_prefix_arg (current_kboard, Qnil);
@@ -1467,8 +1457,6 @@ command_loop_1 (void)
safe_run_hooks_maybe_narrowed (Qpre_command_hook,
XWINDOW (selected_window));
- already_adjusted = 0;
-
if (NILP (Vthis_command))
/* nil means key is undefined. */
call0 (Qundefined);
@@ -1624,9 +1612,8 @@ command_loop_1 (void)
the automatic composition, we must update the
display. */
windows_or_buffers_changed = 21;
- if (!already_adjusted)
- adjust_point_for_property (last_point_position,
- MODIFF != prev_modiff);
+ adjust_point_for_property (last_point_position,
+ MODIFF != prev_modiff);
}
else if (PT > BEGV && PT < ZV
&& (composition_adjust_point (last_point_position, PT)
@@ -1708,8 +1695,8 @@ adjust_point_for_property (ptrdiff_t last_pt, bool modified)
&& display_prop_intangible_p (val, overlay, PT, PT_BYTE)
&& (!OVERLAYP (overlay)
? get_property_and_range (PT, Qdisplay, &val, &beg, &end, Qnil)
- : (beg = OVERLAY_POSITION (OVERLAY_START (overlay)),
- end = OVERLAY_POSITION (OVERLAY_END (overlay))))
+ : (beg = OVERLAY_START (overlay),
+ end = OVERLAY_END (overlay)))
&& (beg < PT /* && end > PT <- It's always the case. */
|| (beg <= PT && STRINGP (val) && SCHARS (val) == 0)))
{
@@ -1827,21 +1814,15 @@ adjust_point_for_property (ptrdiff_t last_pt, bool modified)
}
}
-/* Subroutine for safe_run_hooks: run the hook, which is ARGS[1]. */
+/* Subroutine for safe_run_hooks: run the hook's function.
+ ARGS[0] holds the name of the hook, which we don't need here (we only use
+ it in the failure case of the internal_condition_case_n). */
static Lisp_Object
safe_run_hooks_1 (ptrdiff_t nargs, Lisp_Object *args)
{
- eassert (nargs >= 2 && nargs <= 4);
- switch (nargs)
- {
- case 2:
- return call0 (args[1]);
- case 3:
- return call1 (args[1], args[2]);
- default:
- return call2 (args[1], args[2], args[3]);
- }
+ eassert (nargs >= 2);
+ return Ffuncall (nargs - 1, args + 1);
}
/* Subroutine for safe_run_hooks: handle an error by clearing out the function
@@ -1850,7 +1831,7 @@ safe_run_hooks_1 (ptrdiff_t nargs, Lisp_Object *args)
static Lisp_Object
safe_run_hooks_error (Lisp_Object error, ptrdiff_t nargs, Lisp_Object *args)
{
- eassert (nargs >= 2 && nargs <= 4);
+ eassert (nargs >= 2);
AUTO_STRING (format, "Error in %s (%S): %S");
Lisp_Object hook = args[0];
Lisp_Object fun = args[1];
@@ -1886,27 +1867,22 @@ safe_run_hooks_error (Lisp_Object error, ptrdiff_t nargs, Lisp_Object *args)
static Lisp_Object
safe_run_hook_funcall (ptrdiff_t nargs, Lisp_Object *args)
{
- eassert (nargs >= 2 && nargs <= 4);
- /* Yes, run_hook_with_args works with args in the other order. */
- switch (nargs)
- {
- case 2:
- internal_condition_case_n (safe_run_hooks_1,
- 2, ((Lisp_Object []) {args[1], args[0]}),
- Qt, safe_run_hooks_error);
- break;
- case 3:
- internal_condition_case_n (safe_run_hooks_1,
- 3, ((Lisp_Object []) {args[1], args[0], args[2]}),
- Qt, safe_run_hooks_error);
- break;
- default:
- internal_condition_case_n (safe_run_hooks_1,
- 4, ((Lisp_Object [])
- {args[1], args[0], args[2], args[3]}),
- Qt, safe_run_hooks_error);
- break;
- }
+ /* We need to swap args[0] and args[1] here or in `safe_run_hooks_1`.
+ It's more convenient to do it here. */
+ eassert (nargs >= 2);
+ Lisp_Object fun = args[0], hook = args[1];
+ /* The `nargs` array cannot be mutated safely here because it is
+ reused by our caller `run_hook_with_args`.
+ We could arguably change it temporarily if we set it back
+ to its original state before returning, but it's too ugly. */
+ USE_SAFE_ALLOCA;
+ Lisp_Object *newargs;
+ SAFE_ALLOCA_LISP (newargs, nargs);
+ newargs[0] = hook, newargs[1] = fun;
+ memcpy (newargs + 2, args + 2, (nargs - 2) * word_size);
+ internal_condition_case_n (safe_run_hooks_1, nargs, newargs,
+ Qt, safe_run_hooks_error);
+ SAFE_FREE ();
return Qnil;
}
@@ -1920,7 +1896,8 @@ safe_run_hooks (Lisp_Object hook)
specpdl_ref count = SPECPDL_INDEX ();
specbind (Qinhibit_quit, Qt);
- run_hook_with_args (2, ((Lisp_Object []) {hook, hook}), safe_run_hook_funcall);
+ run_hook_with_args (2, ((Lisp_Object []) {hook, hook}),
+ safe_run_hook_funcall);
unbind_to (count, Qnil);
}
@@ -1936,7 +1913,8 @@ safe_run_hooks_maybe_narrowed (Lisp_Object hook, struct window *w)
make_fixnum (get_narrowed_zv (w, PT)),
hook);
- run_hook_with_args (2, ((Lisp_Object []) {hook, hook}), safe_run_hook_funcall);
+ run_hook_with_args (2, ((Lisp_Object []) {hook, hook}),
+ safe_run_hook_funcall);
unbind_to (count, Qnil);
}
@@ -11806,6 +11784,9 @@ DEFUN ("posn-at-point", Fposn_at_point, Sposn_at_point, 0, 2, 0,
doc: /* Return position information for buffer position POS in WINDOW.
POS defaults to point in WINDOW; WINDOW defaults to the selected window.
+If POS is in invisible text or is hidden by `display' properties,
+this function may report on buffer positions before or after POS.
+
Return nil if POS is not visible in WINDOW. Otherwise,
the return value is similar to that returned by `event-start' for
a mouse click at the upper left corner of the glyph corresponding
@@ -12258,6 +12239,8 @@ syms_of_keyboard (void)
DEFSYM (Qhelp_form_show, "help-form-show");
+ DEFSYM (Qhelp_key_binding, "help-key-binding");
+
DEFSYM (Qecho_keystrokes, "echo-keystrokes");
Fset (Qinput_method_exit_on_first_char, Qnil);