Commit 6b2dde8c08db

Vincent Demeester <vincent@sbr.pm>
2020-08-19 14:48:21
tools/emacs: add scratch
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 3fdd6b8
Changed files (2)
tools
emacs
users
vincent
tools/emacs/config/config-editing.el
@@ -273,5 +273,30 @@ instead.  This command can then be followed by the standard
   :commands (htmlize-paste-it)
   :bind ("C-c e p" . htmlize-paste-it))
 
+(use-package scratch
+  :commands (scratch)
+  :config
+  (defun vde/scratch-buffer-setup ()
+    "Add contents to `scratch' buffer and name it accordingly.
+If region is active, add its contents to the new buffer."
+    (let* ((mode major-mode)
+           (string (format "Scratch buffer for: %s\n\n" mode))
+           (region (with-current-buffer (current-buffer)
+                     (if (region-active-p)
+                         (buffer-substring-no-properties
+                          (region-beginning)
+                          (region-end)))
+                     ""))
+           (text (concat string region)))
+      (when scratch-buffer
+        (save-excursion
+          (insert text)
+          (goto-char (point-min))
+          (comment-region (point-at-bol) (point-at-eol)))
+        (forward-line 2))
+      (rename-buffer (format "*Scratch for %s*" mode) t)))
+  :hook (scratch-create-buffer-hook . vde/scratch-buffer-setup)
+  :bind ("C-c s" . scratch))
+
 (provide 'config-editing)
 ;;; config-editing.el ends here
users/vincent/dev/emacs.nix
@@ -110,6 +110,7 @@ let
     rainbow-mode
     rg
     ripgrep
+    scratch
     smartparens
     symbol-overlay
     try