Take the 2-minute tour ×
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It's 100% free, no registration required.

While working on a document in emacs I often find myself opening a new buffer, doing something in org-mode, copying the org-mode content, and pasting it into my document. I used to create a new org-mode document every time I needed to do this. Now I have a file ~/.scratch.org where I keep my this work.

Would it be possible to create an *org-scratch* buffer that behaved analogously to the *scratch* buffer?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

The initial major-mode for the *Scratch* buffer is controlled by the variable initial-major-mode -- the value needs to be a symbol (which in layman's terms means put a single quote in front of the major-mode name): http://www.gnu.org/software/emacs/manual/html_node/elisp/Auto-Major-Mode.html

(setq initial-major-mode 'org-mode)

EDIT: Based on a comment of the original poster, here is a sample function to create non-file-visiting buffers in sequential order with the major-mode of org-mode:

(defun my-scratch-buffer ()
"Create a new scratch buffer -- \*hello-world\*"
(interactive)
  (let* (
      bufname
      buffer
      (n 0) )
    (catch 'done
      (while t
        (setq bufname (concat "*hello-world"
          (if (= n 0) "" (int-to-string n))
            "*"))
        (setq n (1+ n))
        (when (not (get-buffer bufname))
          (setq buffer (get-buffer-create bufname))
          (with-current-buffer buffer
            (org-mode))
          ;; When called non-interactively, the `t` targets the other window (if it exists).
          (throw 'done (display-buffer buffer t))) ))))
share|improve this answer
    
So would it be possible to have two *Scratch* buffers then? –  Brian Fitzpatrick yesterday
    
I added a sample function that creates new non-file-visiting buffers in numerical order, and I included an org-mode designation. The name can be changed from hello-world to anything the user desires that is recognized by the operating system -- e.g., Windows doesn't like astrisks. –  lawlist yesterday
    
Very cool. Thanks for looking at this! –  Brian Fitzpatrick yesterday
    
I am happy to have been able to help. I decided to throw the result and display the buffer in one fell swoop -- the functionality is the same, but the function looks a little more compact this way. :) –  lawlist yesterday

There's an extension called scratch, which allows creating mode-specific scratch buffers. It is available from MELPA, so you should be able to install it easily.

With this package installed, when you are in an org-mode buffer, you can run M-xscratch to get a scratch buffer in org-mode.

If you give a prefix argument, you get the opportunity to choose the mode (instead of selecting the currently active major mode).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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