-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsublima.el
54 lines (40 loc) · 1.64 KB
/
sublima.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(require 'recentf)
(add-to-list 'recentf-exclude (expand-file-name "~/.emacs.d/sublima"))
(make-directory (expand-file-name "~/.emacs.d/sublima") t)
;; Create Sublima Scratch Buffer
(defun sublima-scratch()
(interactive)
(let ((scratch-file (make-temp-file (expand-file-name "~/.emacs.d/sublima/scratch-"))))
(find-file scratch-file)))
;; Auto Delete File on buffer Kill
(defun sublima-delete-associated-file ()
(if (string-prefix-p (expand-file-name "~/.emacs.d/sublima") (buffer-file-name))
(delete-file (buffer-file-name))))
(add-hook 'kill-buffer-hook #'sublima-delete-associated-file)
;; Save Scratch Buffer as File
(defun sublima-save-as-buffer (filename)
(interactive "F")
(save-buffer)
(write-region (point-min) (point-max) filename)
(kill-buffer)
(find-file filename))
;; Delete empty buffers
(defun delete-empty-scratches ()
(eshell-command "find ~/.emacs.d/sublima -size 0 -delete"))
(add-hook 'emacs-startup-hook #'delete-empty-scratches)
(add-hook 'kill-emacs-hook #'delete-empty-scratches)
;; Open Sublima buffer on emacs startup
(let ((scratch-file (make-temp-file (expand-file-name "~/.emacs.d/sublima/scratch-"))))
(setq initial-buffer-choice scratch-file))
;; Open scratch buffers on startup
(find-file "~/.emacs.d/sublima/*" t)
;; Auto Save Scratch buffers on focus lost
(defun sublima-save-all-buffers ()
(interactive)
(dolist (curr-buff (buffer-list))
(with-current-buffer curr-buff
(when (and (string-prefix-p (expand-file-name "~/.emacs.d/sublima") (buffer-file-name))
(buffer-modified-p))
(save-buffer))
)))
(add-function :after after-focus-change-function 'sublima-save-all-buffers)