[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 07fb8d284f: Don't put trailing optional nil values into `command-
From: |
Lars Ingebrigtsen |
Subject: |
master 07fb8d284f: Don't put trailing optional nil values into `command-history' |
Date: |
Fri, 10 Jun 2022 04:53:27 -0400 (EDT) |
branch: master
commit 07fb8d284f8d08f79bb65e764b39180e2b974761
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Don't put trailing optional nil values into `command-history'
* src/callint.c (fix_command): Don't put trailing optional nil
values into `command-history' (bug#45333).
---
src/callint.c | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/src/callint.c b/src/callint.c
index 92bfaf8d39..8283c61da6 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -170,7 +170,7 @@ check_mark (bool for_region)
of VALUES to do its job. */
static void
-fix_command (Lisp_Object input, Lisp_Object values)
+fix_command (Lisp_Object input, Lisp_Object function, Lisp_Object values)
{
/* FIXME: Instead of this ugly hack, we should provide a way for an
interactive spec to return an expression/function that will re-build the
@@ -230,6 +230,37 @@ fix_command (Lisp_Object input, Lisp_Object values)
}
}
}
+
+ /* If the list contains a bunch of trailing nil values, and they are
+ optional, remove them from the list. This makes navigating the
+ history less confusing, since it doesn't contain a lot of
+ parameters that aren't used. */
+ if (CONSP (values))
+ {
+ Lisp_Object arity = Ffunc_arity (function);
+ /* We don't want to do this simplification if we have an &rest
+ function, because (cl-defun foo (a &optional (b 'zot)) ..)
+ etc. */
+ if (FIXNUMP (XCAR (arity)) && FIXNUMP (XCDR (arity)))
+ {
+ Lisp_Object final = Qnil;
+ ptrdiff_t final_i = 0, i = 0;
+ for (Lisp_Object tail = values;
+ CONSP (tail);
+ tail = XCDR (tail), ++i)
+ {
+ if (!NILP (XCAR (tail)))
+ {
+ final = tail;
+ final_i = i;
+ }
+ }
+
+ /* Chop the trailing optional values. */
+ if (final_i > 0 && final_i >= XFIXNUM (XCAR (arity)) - 1)
+ XSETCDR (final, Qnil);
+ }
+ }
}
/* Helper function to call `read-file-name' from C. */
@@ -340,7 +371,7 @@ invoke it (via an `interactive' spec that contains, for
instance, an
Make a copy of the list of values, for the command history,
and turn them into things we can eval. */
Lisp_Object values = quotify_args (Fcopy_sequence (specs));
- fix_command (input, values);
+ fix_command (input, function, values);
call4 (intern ("add-to-history"), intern ("command-history"),
Fcons (function, values), Qnil, Qt);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 07fb8d284f: Don't put trailing optional nil values into `command-history',
Lars Ingebrigtsen <=