Created
April 12, 2011 17:03
-
-
Save 10sr/915927 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; scratch バッファがいらない気がしたので、下記のコードを削除し、別ファイルのkill scratchを追加した | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; scratch buffer | |
| ;; http://blog.lifeflow.jp/2010/02/emacs-scratch.html | |
| (defun save-scratch-buffer () | |
| "Save scratch buffer. Return nil if buffer is not modified." | |
| (interactive) | |
| (when (get-buffer "*scratch*") | |
| (with-current-buffer (get-buffer "*scratch*") | |
| (if (buffer-modified-p) | |
| (let* ((file (expand-file-name "~/.emacs.d/.scratch")) | |
| (recentf-exclude '("\\.emacs\\.d/\\.scratch$")) | |
| (bf (or (get-file-buffer file) | |
| (find-file-noselect file t)))) | |
| (with-current-buffer bf | |
| (erase-buffer) | |
| (insert-buffer-substring-no-properties "*scratch*") | |
| (save-buffer)) | |
| (kill-buffer bf) | |
| (set-buffer-modified-p nil) | |
| (message "Wrote %s" file)) | |
| (message "(No changes need to be saved)") | |
| nil)))) | |
| (defun read-scratch-buffer () | |
| "Read scratch buffer. | |
| Return nil if file for save is not found." | |
| (let ((file "~/.emacs.d/.scratch")) | |
| (if (file-exists-p file) | |
| (with-current-buffer (get-buffer-create "*scratch*") | |
| (erase-buffer) | |
| (insert-file-contents file) | |
| (set-buffer-modified-p nil)) | |
| nil))) | |
| (defun save-and-initialize-scratch-buffer () | |
| "Initialize scratch buffer." | |
| (interactive) | |
| (when (or (not (interactive-p)) | |
| (yes-or-no-p "Really backup and initialize scratch buffer? ")) | |
| (let ((m (if (save-scratch-buffer) | |
| " backuped and" | |
| ""))) | |
| (with-current-buffer (get-buffer "*scratch*") | |
| (erase-buffer) | |
| (insert initial-scratch-message) | |
| (message "Scratch buffer%s initialized." m)) | |
| nil))) | |
| (add-hook 'lisp-interaction-mode-hook | |
| (lambda () | |
| (define-key lisp-interaction-mode-map "\C-x\C-s" 'save-scratch-buffer) | |
| (define-key lisp-interaction-mode-map "\C-xk" 'save-and-initialize-scratch-buffer))) | |
| (setq initial-major-mode 'lisp-interaction-mode) | |
| (setq initial-scratch-message ";; initial message\n") ; | |
| (add-hook 'after-init-hook | |
| 'read-scratch-buffer) | |
| (add-hook 'kill-emacs-hook | |
| 'save-scratch-buffer) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; kill scratch | |
| (add-hook 'after-init-hook | |
| (lambda () | |
| (kill-buffer "*scratch*"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment