Skip to main content
deleted 3 characters in body; edited title
Source Link
Dan
  • 33.4k
  • 7
  • 106
  • 171

Set a default scrathscratch buffer [SOLVED]

My emacs daemon for ocaml (I use more than one emacs daemon) startstarts in a tuareg scratch buffer, I. I am aware of initial-major-mode but this hasn't work,worked: the scratch is started before (setq initial-major-mode 'tuareg-mode)` is evaluated...

Since I keep the initial-buffer-choiceinitial-buffer-choice to scratch, I just run (tuareg-mode) and my scratch mode is modified as I want. Cool.

But now, when I kill the scratch, new scratchesscratch buffers are not in tuareg mode, so I added a little hack found on stackexchange  :

(defun prepare-scratch-for-kill ()
  (save-excursion
    (set-buffer (get-buffer-create "*scratch*"))
    (tuareg-mode)
    (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer t)))

(defun kill-scratch-buffer ()
  (let (kill-buffer-query-functions)
    (kill-buffer (current-buffer)))
  ;; no way, *scratch* shall live
  (prepare-scratch-for-kill)
  ;; Since we "killed" it, don't let caller try too
  nil)

(prepare-scratch-for-kill)

It works, but now I don't see my magnificientmagnificent initial-scratch-message... Of course II have tried to (setq initial-major-mode 'tuareg-mode), which normally does modifymodifies the scratch major mode,. But it doesn't, even if I start a new scratch.

I would like to do it the proper way, emacs embeded way, but what I have tried doesn't work.

Set a default scrath buffer [SOLVED]

My emacs daemon for ocaml (I more than one emacs daemon) start in a tuareg scratch buffer, I am aware of initial-major-mode but this hasn't work, the scratch is started before (setq initial-major-mode 'tuareg-mode)` is evaluated...

Since I keep the initial-buffer-choice to scratch, I just run (tuareg-mode) and my scratch mode is modified as I want. Cool.

But now, when I kill the scratch, new scratches are not in tuareg mode, so I added a little hack found on stackexchange  :

(defun prepare-scratch-for-kill ()
  (save-excursion
    (set-buffer (get-buffer-create "*scratch*"))
    (tuareg-mode)
    (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer t)))

(defun kill-scratch-buffer ()
  (let (kill-buffer-query-functions)
    (kill-buffer (current-buffer)))
  ;; no way, *scratch* shall live
  (prepare-scratch-for-kill)
  ;; Since we "killed" it, don't let caller try too
  nil)

(prepare-scratch-for-kill)

It works, but now I don't see my magnificient initial-scratch-message... Of course I have tried to (setq initial-major-mode 'tuareg-mode) which normally does modify the scratch major mode, it doesn't, even if I start a new scratch.

I would like to do it the proper way, emacs embeded way, but what I have tried doesn't work.

Set a default scratch buffer

My emacs daemon for ocaml (I use more than one emacs daemon) starts in a tuareg scratch buffer. I am aware of initial-major-mode but this hasn't worked: the scratch is started before (setq initial-major-mode 'tuareg-mode)` is evaluated.

Since I keep the initial-buffer-choice to scratch, I just run (tuareg-mode) and my scratch mode is modified as I want.

But now, when I kill the scratch, new scratch buffers are not in tuareg mode, so I added a little hack found on stackexchange:

(defun prepare-scratch-for-kill ()
  (save-excursion
    (set-buffer (get-buffer-create "*scratch*"))
    (tuareg-mode)
    (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer t)))

(defun kill-scratch-buffer ()
  (let (kill-buffer-query-functions)
    (kill-buffer (current-buffer)))
  ;; no way, *scratch* shall live
  (prepare-scratch-for-kill)
  ;; Since we "killed" it, don't let caller try too
  nil)

(prepare-scratch-for-kill)

It works, but now I don't see my magnificent initial-scratch-message. I have tried to (setq initial-major-mode 'tuareg-mode), which normally modifies the scratch major mode. But it doesn't, even if I start a new scratch.

I would like to do it the proper way, emacs embeded way, but what I have tried doesn't work.

edited title
Link

Set a default scrath buffer [SOLVED]

Source Link

Set a default scrath buffer

My emacs daemon for ocaml (I more than one emacs daemon) start in a tuareg scratch buffer, I am aware of initial-major-mode but this hasn't work, the scratch is started before (setq initial-major-mode 'tuareg-mode)` is evaluated...

Since I keep the initial-buffer-choice to scratch, I just run (tuareg-mode) and my scratch mode is modified as I want. Cool.

But now, when I kill the scratch, new scratches are not in tuareg mode, so I added a little hack found on stackexchange :

(defun prepare-scratch-for-kill ()
  (save-excursion
    (set-buffer (get-buffer-create "*scratch*"))
    (tuareg-mode)
    (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer t)))

(defun kill-scratch-buffer ()
  (let (kill-buffer-query-functions)
    (kill-buffer (current-buffer)))
  ;; no way, *scratch* shall live
  (prepare-scratch-for-kill)
  ;; Since we "killed" it, don't let caller try too
  nil)

(prepare-scratch-for-kill)

It works, but now I don't see my magnificient initial-scratch-message... Of course I have tried to (setq initial-major-mode 'tuareg-mode) which normally does modify the scratch major mode, it doesn't, even if I start a new scratch.

I would like to do it the proper way, emacs embeded way, but what I have tried doesn't work.