1

The code below creates a new frame with an untitled buffer, how to make this buffer default with org-mode and evil-mode?

(global-set-key (kbd "s-n") 'new-empty-frame)

(defun new-empty-frame ()
  "Create a new frame with a new empty buffer."
  (interactive)
  (let ((buffer (generate-new-buffer "untitled")))
    (set-buffer-major-mode buffer)
    (display-buffer buffer '(display-buffer-pop-up-frame . nil))))
  1. M-x org-mode RET worked, but how to do it with elisp?
  2. M-x evil-mode RET didn't even work.

new frame

The code is from: https://stackoverflow.com/a/25792276/5520270

1 Answer 1

1

All you have to do is replace the set-buffer-major-mode call which sets the buffer to a default mode (fundamental mode in this case) with a couple of calls to set the modes you want.

org-mode is a major mode, so you set it by calling the function that implements it, with no arguments, in the buffer whose mode you want to set:

(set-buffer <some buffer>)
(org-mode)

evil-mode is a global minor mode, which can be enabled or disabled at will, like all minor modes. To enable it, you have to call its function with a positive argument:

(evil-mode 1)

To disable it, you call the function with a negative argument.

All these things and more can be glimpsed by checking the doc string of the functions: C-h f org-mode RET and C-h f evil-mode RET. If a function does not behave the way you expect, you probably have a wrong expectation and you can check that by reading its doc string, so C-h f <function> RET is something you should do often.

Putting it all together, the result is:

(defun new-empty-frame ()
  "Create a new frame with a new empty buffer."
  (interactive)
  (let ((buffer (generate-new-buffer "untitled")))
    (set-buffer buffer)
    (org-mode)
    (evil-mode 1)
    (display-buffer buffer '(display-buffer-pop-up-frame . nil))))

Only partially tested, since I don't have evil-mode installed.

2
  • Awesome! It works pretty well. You explain the solution in detail and provide the guidance to help me in the future. Thank you so much, NickD! :D
    – WillBC
    Commented Jul 15, 2020 at 5:29
  • You are welcome!
    – NickD
    Commented Jul 15, 2020 at 14:29

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.