Skip to content

Instantly share code, notes, and snippets.

@pi-chan
Created March 17, 2021 08:27
Show Gist options
  • Save pi-chan/765fb620202adaabb735f65bc26700b3 to your computer and use it in GitHub Desktop.
Save pi-chan/765fb620202adaabb735f65bc26700b3 to your computer and use it in GitHub Desktop.
*scratch*を消さないようにする
;; *scratch*を消さないようにする
(defun my-make-scratch (&optional arg)
(interactive)
(progn
;; "*scratch*" を作成して buffer-list に放り込む
(set-buffer (get-buffer-create "*scratch*"))
(funcall initial-major-mode)
(erase-buffer)
(when (and initial-scratch-message (not inhibit-startup-message))
(insert initial-scratch-message))
(or arg (progn (setq arg 0)
(switch-to-buffer "*scratch*")))
(cond ((= arg 0) (message "*scratch* is cleared up."))
((= arg 1) (message "another *scratch* is created")))))
(defun my-buffer-name-list ()
(mapcar (function buffer-name) (buffer-list)))
(add-hook 'kill-buffer-query-functions
;; *scratch* バッファで kill-buffer したら内容を消去するだけにする
(function (lambda ()
(if (string= "*scratch*" (buffer-name))
(progn (my-make-scratch 0) nil)
t))))
(add-hook 'after-save-hook
;; *scratch* バッファの内容を保存したら *scratch* バッファを新しく作る
(function (lambda ()
(unless (member "*scratch*" (my-buffer-name-list))
(my-make-scratch 1)))))
;; scratchを空にする
(setq initial-scratch-message "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment