4

I'm managing workspaces by creating new frames, but running C-x 5 C-h couldn't find anything like "run command in new frame", basically what I'd like to do is to run some REPL or shell in new frame. Is it possible?

2
  • Why not just open a new frame and then run the command? If you do it all the time and want to save a step, you could write a command that does both.
    – Dan
    Jan 7, 2015 at 14:36
  • I like to modify source code and create my own custom custom setup; however, most people seem to prefer chaining functions together or using advice. To the extent that you want to create your own function to open a shell, the key ingredient to your display issue is the line of the shell function (defined within the library shell.el) that looks like this: (pop-to-buffer-same-window buffer). For example, you might be interested in something like (swtich-to-buffer-other-frame buffer). There are also those users who prefer to modify the display-buffer-alist.
    – lawlist
    Jan 7, 2015 at 15:12

1 Answer 1

6

If you simply want a programmatic way to run a command in a new frame, just create the frame and run the command:

(defun simple-run-command-in-new-frame (command)
  (select-frame (make-frame))
  (funcall #'command))

If you want an interactive command that queries for the command being run, similar to M-x, then you'll need to take care of details such as handling the prefix argument and querying the user. The following should work in most circumstances:

(defun run-command-in-new-frame (prefixarg command-name)
  (interactive (list current-prefix-arg (read-extended-command)))
  (let ((command (intern-soft command-name)))
    (unless command
      (error "%s is not a valid command name" command-name))
    (select-frame (make-frame))
    (let ((prefix-arg prefixarg))
      (command-execute command))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.