Search code examples
debuggingemacsorg-mode

Emacs : how to load file content in scratch screen


I would like to load "~/todo.org" file content in scratch buffer at startup.

I have tried:

(setq initial-buffer-choice "~/todo.org")

But it opens the file in a new buffer (not scratch).

I have also tried:

(setq initial-scratch-message "~/todo.org")

But it prints the file path in the scratch buffer and i would like it's content.

I also would like to change the mode of the scratch buffer to org-mode.

I have tried:

(setq initial-major-mode org-mode)

But i have an initialisation error

Symbol's value as variable is void: org-mode


Solution

  • Finally, i'll go for this:

    (condition-case err
      (when (get-buffer "*scratch*")
        (with-current-buffer "*scratch*"
          (erase-buffer)
          (insert-file-contents "~/todo.org")
          (org-mode)
        )
      )
    (error (message "%s" error-message-string err)))