Skip to content

Instantly share code, notes, and snippets.

@doitian
Created September 23, 2012 03:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doitian/3768772 to your computer and use it in GitHub Desktop.
Save doitian/3768772 to your computer and use it in GitHub Desktop.
Open file in dedicated Emacs frame
#!/bin/sh
for file; do
emacsclient -e "(find-file-in-dedicated-frame \"${file/\"/\\\"}\" \"Finder\" 'focus)"
done
(defun get-frame-create (frame-or-name)
"Return the frame specified by FRAME-OR-NAME, creating a new one if needed.
If FRAME-OR-NAME is a string and a live frame with that name exists,
return that frame. If no such frame exists, create a new frame with
that name and return it.
If FRAME-OR-NAME is a frame instead of a string, return it as given,
even if it is dead.
"
(if (framep frame-or-name)
frame-or-name
(or
(cdr-safe (assoc frame-or-name (mapcar
(lambda (frame)
(cons (frame-parameter frame 'name) frame))
(frame-list))))
(let ((frame (make-frame)))
(set-frame-parameter frame 'name frame-or-name)
frame))))
(defun find-file-in-dedicated-frame (file frame-or-name &optional focus)
"Find FILE in dedicated frame specified by FRAME-OR-NAME. Create the frame if needed.
Optional argument FOCUS means to whether focus the frame, or just open the file in background.
"
(let ((remember-frame (selected-frame))
(frame (get-frame-create frame-or-name)))
(if focus (select-frame-set-input-focus frame)
(select-frame frame))
(find-file file)
(unless focus (select-frame-set-input-focus remember-frame))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment