Question

I'd like to implement a command that types the first few characters into an existing command and lets me type the rest.

For example, a variant of icicle-execute-extended-command that starts with "icicle-" already entered.

I have tried:

  • keyboard macros
    • fail (even on simple things like M-x i c i c l e s) for no apparent reason.
  • functions
    • calling icicle-execute-extended-command block the command sequence

How would I go about doing this in a generalized manner?

Was it helpful?

Solution

Nice question. Here's something generic you can try:

(defun no-mondays ()
  (interactive)
  (minibuffer-with-setup-hook
    (lambda()
      (insert "monday"))
    (call-interactively 'query-replace)))

And here's a refactoring:

(defun with-initial-minibuffer (str fun)
  `(lambda ()
     (interactive)
     (minibuffer-with-setup-hook
         (lambda ()
            (insert ,str))
       (call-interactively ',fun))))

(defalias 'no-weekends
    (with-initial-minibuffer
        "\\(?:satur\\|sun\\)day"
      'query-replace-regexp))

OTHER TIPS

If you are calling completing-read yourself in your command definition, then just pass the text to insert as the INITIAL-INPUT argument. That's what it's for.

If you use icicle-define-command or icicle-define-file-command (so that your command will be a multi-command), then same thing: pass the INITIAL-INPUT arg.

If you use such a macro, be sure to put something like this in the file that defines the command, so the macro definition is available a byte-compilation time:

 (eval-when-compile
  (or (condition-case nil
          (load-library "icicles-mac")   ; Use load-library to ensure latest .elc.
        (error nil))
      (require 'icicles-mac)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top