commit 6b2dde8c08db2f9764d3869b5e7254a7f1dabf79 parent 3fdd6b873927aad921a9665753e19b23892bbeb0 Author: Vincent Demeester <vincent@sbr.pm> Date: Wed, 19 Aug 2020 14:48:21 +0200 tools/emacs: add scratch Signed-off-by: Vincent Demeester <vincent@sbr.pm> Diffstat:
M | tools/emacs/config/config-editing.el | | | 25 | +++++++++++++++++++++++++ |
M | users/vincent/dev/emacs.nix | | | 1 | + |
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/tools/emacs/config/config-editing.el b/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 diff --git a/users/vincent/dev/emacs.nix b/users/vincent/dev/emacs.nix @@ -110,6 +110,7 @@ let rainbow-mode rg ripgrep + scratch smartparens symbol-overlay try