2021-12-06 04:37:41 +00:00
|
|
|
|
;;; +scratch.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2021-12-18 00:31:24 +00:00
|
|
|
|
;;(require 'scratch)
|
2021-12-06 04:37:41 +00:00
|
|
|
|
|
|
|
|
|
(defun +scratch-immortal ()
|
2022-01-31 23:27:21 +00:00
|
|
|
|
"Bury, don't kill \"*scratch*\" buffer.
|
2021-12-06 04:37:41 +00:00
|
|
|
|
For `kill-buffer-query-functions'."
|
2022-05-10 01:36:32 +00:00
|
|
|
|
(if (or (eq (current-buffer) (get-buffer "*scratch*"))
|
|
|
|
|
(eq (current-buffer) (get-buffer "*text*")))
|
2021-12-06 04:37:41 +00:00
|
|
|
|
(progn (bury-buffer)
|
|
|
|
|
nil)
|
|
|
|
|
t))
|
|
|
|
|
|
|
|
|
|
(defun +scratch-buffer-setup ()
|
|
|
|
|
"Add comment to `scratch' buffer and name it accordingly."
|
|
|
|
|
(let* ((mode (format "%s" major-mode))
|
|
|
|
|
(string (concat "Scratch buffer for:" mode "\n\n")))
|
|
|
|
|
(when scratch-buffer
|
|
|
|
|
(save-excursion
|
|
|
|
|
(insert string)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(comment-region (point-at-bol) (point-at-eol)))
|
|
|
|
|
(next-line 2))
|
|
|
|
|
(rename-buffer (concat "*scratch<" mode ">*") t)))
|
|
|
|
|
|
2022-04-27 13:35:22 +00:00
|
|
|
|
(defun +scratch-fortune ()
|
|
|
|
|
(let* ((fmt (if (executable-find "fmt")
|
|
|
|
|
(format "| fmt -%d -s" (- fill-column 2))
|
|
|
|
|
""))
|
|
|
|
|
(s (string-trim
|
|
|
|
|
(if (executable-find "fortune")
|
|
|
|
|
(shell-command-to-string (concat "fortune -s" fmt))
|
|
|
|
|
"ABANDON ALL HOPE YE WHO ENTER HERE"))))
|
|
|
|
|
(concat (replace-regexp-in-string "^" ";; " s)
|
|
|
|
|
"\n\n")))
|
2022-05-24 01:12:53 +00:00
|
|
|
|
|
2022-05-10 01:36:32 +00:00
|
|
|
|
;; [[https://old.reddit.com/r/emacs/comments/ui1q41/weekly_tips_tricks_c_thread/i7ef4xg/][u/bhrgunatha]]
|
|
|
|
|
(defun +scratch-text-scratch ()
|
|
|
|
|
"Create a \"*text*\" scratch buffer in Text mode."
|
|
|
|
|
(with-current-buffer (get-buffer-create "*text*")
|
|
|
|
|
(text-mode)))
|
|
|
|
|
|
2022-05-24 01:12:53 +00:00
|
|
|
|
(defcustom +scratch-buffers '("*text*" "*scratch*")
|
|
|
|
|
"Scratch buffers.")
|
|
|
|
|
|
|
|
|
|
(defvar +scratch-last-non-scratch-buffer nil
|
|
|
|
|
"Last buffer that wasn't a scratch buffer.")
|
|
|
|
|
|
2022-05-10 01:36:32 +00:00
|
|
|
|
(defun +scratch-toggle (buffer)
|
2022-05-24 01:12:53 +00:00
|
|
|
|
"Switch to BUFFER, or to the previous (non-scratch) buffer."
|
|
|
|
|
(if (or (null +scratch-last-non-scratch-buffer)
|
|
|
|
|
(not (member (buffer-name (current-buffer)) +scratch-buffers)))
|
|
|
|
|
;; Switch to a scratch buffer
|
|
|
|
|
(progn
|
|
|
|
|
(setq +scratch-last-non-scratch-buffer (current-buffer))
|
|
|
|
|
(switch-to-buffer buffer))
|
|
|
|
|
;; Switch away from scratch buffer ...
|
|
|
|
|
(if (equal (get-buffer-create buffer) (current-buffer))
|
|
|
|
|
;; to the original buffer
|
|
|
|
|
(switch-to-buffer +scratch-last-non-scratch-buffer)
|
|
|
|
|
;; to another scratch
|
|
|
|
|
(switch-to-buffer buffer))))
|
2022-05-10 01:36:32 +00:00
|
|
|
|
|
|
|
|
|
(defun +scratch-switch-to-scratch ()
|
|
|
|
|
"Switch to scratch buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(+scratch-toggle "*scratch*"))
|
|
|
|
|
|
|
|
|
|
(defun +scratch-switch-to-text ()
|
|
|
|
|
"Switch to text buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(+scratch-toggle "*text*"))
|
|
|
|
|
|
2021-12-06 04:37:41 +00:00
|
|
|
|
(provide '+scratch)
|
|
|
|
|
;;; +scratch.el ends here
|