summary refs log tree commit diff stats
path: root/lisp/+scratch.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/+scratch.el')
-rw-r--r--lisp/+scratch.el77
1 files changed, 0 insertions, 77 deletions
diff --git a/lisp/+scratch.el b/lisp/+scratch.el deleted file mode 100644 index 7fc2bde..0000000 --- a/lisp/+scratch.el +++ /dev/null
@@ -1,77 +0,0 @@
1;;; +scratch.el -*- lexical-binding: t; -*-
2
3;;; Code:
4
5;;(require 'scratch)
6
7(defun +scratch-immortal ()
8 "Bury, don't kill \"*scratch*\" buffer.
9For `kill-buffer-query-functions'."
10 (if (or (eq (current-buffer) (get-buffer "*scratch*"))
11 (eq (current-buffer) (get-buffer "*text*")))
12 (progn (bury-buffer)
13 nil)
14 t))
15
16(defun +scratch-buffer-setup ()
17 "Add comment to `scratch' buffer and name it accordingly."
18 (let* ((mode (format "%s" major-mode))
19 (string (concat "Scratch buffer for:" mode "\n\n")))
20 (when scratch-buffer
21 (save-excursion
22 (insert string)
23 (goto-char (point-min))
24 (comment-region (point-at-bol) (point-at-eol)))
25 (next-line 2))
26 (rename-buffer (concat "*scratch<" mode ">*") t)))
27
28(defun +scratch-fortune ()
29 (let* ((fmt (if (executable-find "fmt")
30 (format "| fmt -%d -s" (- fill-column 2))
31 ""))
32 (s (string-trim
33 (if (executable-find "fortune")
34 (shell-command-to-string (concat "fortune -s" fmt))
35 "ABANDON ALL HOPE YE WHO ENTER HERE"))))
36 (concat (replace-regexp-in-string "^" ";; " s)
37 "\n\n")))
38
39;; [[https://old.reddit.com/r/emacs/comments/ui1q41/weekly_tips_tricks_c_thread/i7ef4xg/][u/bhrgunatha]]
40(defun +scratch-text-scratch ()
41 "Create a \"*text*\" scratch buffer in Text mode."
42 (with-current-buffer (get-buffer-create "*text*")
43 (text-mode)))
44
45(defcustom +scratch-buffers '("*text*" "*scratch*")
46 "Scratch buffers.")
47
48(defvar +scratch-last-non-scratch-buffer nil
49 "Last buffer that wasn't a scratch buffer.")
50
51(defun +scratch-toggle (buffer)
52 "Switch to BUFFER, or to the previous (non-scratch) buffer."
53 (if (or (null +scratch-last-non-scratch-buffer)
54 (not (member (buffer-name (current-buffer)) +scratch-buffers)))
55 ;; Switch to a scratch buffer
56 (progn
57 (setq +scratch-last-non-scratch-buffer (current-buffer))
58 (switch-to-buffer buffer))
59 ;; Switch away from scratch buffer ...
60 (if (equal (get-buffer-create buffer) (current-buffer))
61 ;; to the original buffer
62 (switch-to-buffer +scratch-last-non-scratch-buffer)
63 ;; to another scratch
64 (switch-to-buffer buffer))))
65
66(defun +scratch-switch-to-scratch ()
67 "Switch to scratch buffer."
68 (interactive)
69 (+scratch-toggle "*scratch*"))
70
71(defun +scratch-switch-to-text ()
72 "Switch to text buffer."
73 (interactive)
74 (+scratch-toggle "*text*"))
75
76(provide '+scratch)
77;;; +scratch.el ends here