emacsevent-loopicicles

Programatically insert text into command that normally blocks event loop


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:

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


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))