I use Emacs org-mode for note taking during philosophical dialogs. I make one new file for each idea encountered, using this code:

(defun myfun-create-note-file()
  (find-file (format-time-string "C:/Users/myUser/notes/%Y-%m-%d--%H-%M-%S.txt"))
  (insert "*note :tags: \n\n")                        

(global-set-key "\C-cn" ' myfun-create-note-file)

However, when making several new files during one session, only the last one is visible in the Emacs frame. The rest of the files reside within the Emacs instance, and have to be visited by cycling through the open buffer list.

I would like to open every new file in a separate frame, of small size. How can I modify my code to do this?

  • C-h f find-file-other-frame and refs therein. – NickD Jul 15 '19 at 18:56

Use find-file-other-frame instead of find-file:

find-file-other-frame is an interactive compiled Lisp function in

(find-file-other-frame FILENAME &optional WILDCARDS)

Edit file FILENAME, in another frame.

Like M-x find-file (which see), but creates a new frame or reuses
an existing one.  See the function ‘display-buffer’.

Interactively, the default if you just type RET is the current directory,
but the visited file name is available through the minibuffer history:
type M-n to pull it into the minibuffer.

Interactively, or if WILDCARDS is non-nil in a call from Lisp,
expand wildcards (if any) and visit multiple files.
  • Thanks, that made it :) – myotis Jul 15 '19 at 19:38

You say, "I would like to open every new file in a separate frame, of small size."

  1. To always use a separate frame, by default, set option pop-up-frames to t.

  2. To get frames that fit the buffer content (narrow, for narrow buffer lines, short, for short buffers), use libraries fit-frame.el and auto-fit-frame.el. See Shrink-Wrapping Frames.

If you instead want to always use the same size frame (instead of having the frame fit the buffer content) then customize option special-display-regexps to a value that matches all buffer names, and then customize option special-display-frame-alist to have the size etc. you want.

  • Thanks for valuable info! I will test it out. – myotis Jul 15 '19 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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