diff options
| author | Lars Ingebrigtsen | 2022-06-10 10:51:34 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-06-10 10:53:21 +0200 |
| commit | 07fb8d284f8d08f79bb65e764b39180e2b974761 (patch) | |
| tree | 347d479c3cc020cb7fc0f441bde94fa917aa625f /src | |
| parent | 068ce6411d20646ac5a8a80a79167068b3247554 (diff) | |
| download | emacs-07fb8d284f8d08f79bb65e764b39180e2b974761.tar.gz emacs-07fb8d284f8d08f79bb65e764b39180e2b974761.zip | |
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).
Diffstat (limited to 'src')
| -rw-r--r-- | src/callint.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/callint.c b/src/callint.c index 92bfaf8d397..8283c61da67 100644 --- a/src/callint.c +++ b/src/callint.c | |||
| @@ -170,7 +170,7 @@ check_mark (bool for_region) | |||
| 170 | of VALUES to do its job. */ | 170 | of VALUES to do its job. */ |
| 171 | 171 | ||
| 172 | static void | 172 | static void |
| 173 | fix_command (Lisp_Object input, Lisp_Object values) | 173 | fix_command (Lisp_Object input, Lisp_Object function, Lisp_Object values) |
| 174 | { | 174 | { |
| 175 | /* FIXME: Instead of this ugly hack, we should provide a way for an | 175 | /* FIXME: Instead of this ugly hack, we should provide a way for an |
| 176 | interactive spec to return an expression/function that will re-build the | 176 | interactive spec to return an expression/function that will re-build the |
| @@ -230,6 +230,37 @@ fix_command (Lisp_Object input, Lisp_Object values) | |||
| 230 | } | 230 | } |
| 231 | } | 231 | } |
| 232 | } | 232 | } |
| 233 | |||
| 234 | /* If the list contains a bunch of trailing nil values, and they are | ||
| 235 | optional, remove them from the list. This makes navigating the | ||
| 236 | history less confusing, since it doesn't contain a lot of | ||
| 237 | parameters that aren't used. */ | ||
| 238 | if (CONSP (values)) | ||
| 239 | { | ||
| 240 | Lisp_Object arity = Ffunc_arity (function); | ||
| 241 | /* We don't want to do this simplification if we have an &rest | ||
| 242 | function, because (cl-defun foo (a &optional (b 'zot)) ..) | ||
| 243 | etc. */ | ||
| 244 | if (FIXNUMP (XCAR (arity)) && FIXNUMP (XCDR (arity))) | ||
| 245 | { | ||
| 246 | Lisp_Object final = Qnil; | ||
| 247 | ptrdiff_t final_i = 0, i = 0; | ||
| 248 | for (Lisp_Object tail = values; | ||
| 249 | CONSP (tail); | ||
| 250 | tail = XCDR (tail), ++i) | ||
| 251 | { | ||
| 252 | if (!NILP (XCAR (tail))) | ||
| 253 | { | ||
| 254 | final = tail; | ||
| 255 | final_i = i; | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | /* Chop the trailing optional values. */ | ||
| 260 | if (final_i > 0 && final_i >= XFIXNUM (XCAR (arity)) - 1) | ||
| 261 | XSETCDR (final, Qnil); | ||
| 262 | } | ||
| 263 | } | ||
| 233 | } | 264 | } |
| 234 | 265 | ||
| 235 | /* Helper function to call `read-file-name' from C. */ | 266 | /* Helper function to call `read-file-name' from C. */ |
| @@ -340,7 +371,7 @@ invoke it (via an `interactive' spec that contains, for instance, an | |||
| 340 | Make a copy of the list of values, for the command history, | 371 | Make a copy of the list of values, for the command history, |
| 341 | and turn them into things we can eval. */ | 372 | and turn them into things we can eval. */ |
| 342 | Lisp_Object values = quotify_args (Fcopy_sequence (specs)); | 373 | Lisp_Object values = quotify_args (Fcopy_sequence (specs)); |
| 343 | fix_command (input, values); | 374 | fix_command (input, function, values); |
| 344 | call4 (intern ("add-to-history"), intern ("command-history"), | 375 | call4 (intern ("add-to-history"), intern ("command-history"), |
| 345 | Fcons (function, values), Qnil, Qt); | 376 | Fcons (function, values), Qnil, Qt); |
| 346 | } | 377 | } |