Subject: bug#66394: 29.1; Make register-read-with-preview more useful

From: Michael Heerdegen <[email-masked]>
Date: Wed, 25 Oct 2023 06:10:24 +0200

Thierry Volpiatto <[email-masked]> writes:

> A possible solution for this is adding two vars, insert-register-types
> and jump-to-register-types and define register-type like this (named
> register--type here):
>
> (defun register--type (register)
>   ;; Call register/type against the register value.
>   (register/type (if (consp (cdr register))
>                      (cadr register)
>                    (cdr register))))
>
> (cl-defgeneric register/type (regval))
>
> (cl-defmethod register/type ((regval string)) 'string)
> (cl-defmethod register/type ((regval number)) 'number)
> (cl-defmethod register/type ((regval marker)) 'marker)
> (cl-defmethod register/type ((regval window-configuration)) 'window)
> (cl-deftype frame-register () '(satisfies frameset-register-p))
> (cl-defmethod register/type :extra "frame-register" (regval) 'frame)
>
> ;; set a new register and check its type like this:
> (register--type (car register-alist))

This looks promising.

But I'm not sure whether the detour via type names (instead of an
approach using only generics) is the best solution.  Why not define just
a new generic (register-eligible-for-command-p REG COMMAND) and use that
as predicate in the interactive specs of the commands (providing
`this-command' as second arg)?  Seems simpler to me and still more
extensible and controllable.

Michael.