From 04a3db3d2b9a67274c2d24abeec68e85c74e8f95 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 27 Sep 2017 01:21:10 +0200 Subject: [PATCH] Move scratch commands to core/autoload/scratch.el --- core/autoload/editor.el | 55 ---------------------------------------- core/autoload/scratch.el | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 55 deletions(-) create mode 100644 core/autoload/scratch.el diff --git a/core/autoload/editor.el b/core/autoload/editor.el index 98a88d1e2..3188c27c9 100644 --- a/core/autoload/editor.el +++ b/core/autoload/editor.el @@ -223,58 +223,3 @@ consistent throughout a selected region, depending on `indent-tab-mode'." "Attaches `delete-trailing-whitespace' to a buffer-local `before-save-hook'." (add-hook 'before-save-hook #'delete-trailing-whitespace nil t)) - -;; -- scratch buffer ---------------------- - -(defvar doom-scratch-files-dir (concat doom-etc-dir "scratch/") - "Where to store project scratch files, created by -`doom/open-project-scratch-buffer'.") - -(defvar doom-scratch-buffer-hook () - "The hooks to run after a scratch buffer is made.") - -(defun doom--create-scratch-buffer (&optional project-p) - (let ((text (and (region-active-p) - (buffer-substring-no-properties - (region-beginning) (region-end)))) - (mode major-mode) - (derived-p (derived-mode-p 'prog-mode 'text-mode)) - (old-project (doom-project-root))) - (unless (file-directory-p doom-scratch-files-dir) - (mkdir doom-scratch-files-dir t)) - (with-current-buffer - (if project-p - (find-file-noselect - (expand-file-name (replace-regexp-in-string - "\\." "_" (projectile-project-name) - t t) - doom-scratch-files-dir) - nil t) - (get-buffer-create "*doom:scratch*")) - (when project-p - (rename-buffer (format "*doom:scratch (%s)*" (projectile-project-name)))) - (setq default-directory old-project) - (when (and (not (eq major-mode mode)) - derived-p - (functionp mode)) - (funcall mode)) - (if text (insert text)) - (run-hooks 'doom-scratch-buffer-hook) - (current-buffer)))) - -;;;###autoload -(defun doom/open-scratch-buffer () - "Opens a temporary scratch buffer in a popup window. It is discarded once it -is closed. If a region is active, copy it to the scratch buffer." - (interactive) - (doom-popup-buffer (doom--create-scratch-buffer) - '(:size 12 :autokill t :static t) t)) - -;;;###autoload -(defun doom/open-project-scratch-buffer () - "Opens a (persistent) scratch buffer associated with the current project in a -popup window. Scratch buffers are stored in `doom-scratch-files-dir'. If a -region is active, copy it to the scratch buffer." - (interactive) - (doom-popup-buffer (doom--create-scratch-buffer t) - '(:size 12 :autokill t :static t) t)) diff --git a/core/autoload/scratch.el b/core/autoload/scratch.el new file mode 100644 index 000000000..b0bd510c5 --- /dev/null +++ b/core/autoload/scratch.el @@ -0,0 +1,53 @@ +;;; core/autoload/scratch.el -*- lexical-binding: t; -*- + +(defvar doom-scratch-files-dir (concat doom-etc-dir "scratch/") + "Where to store project scratch files, created by +`doom/open-project-scratch-buffer'.") + +(defvar doom-scratch-buffer-hook () + "The hooks to run after a scratch buffer is made.") + +(defun doom--create-scratch-buffer (&optional project-p) + (let ((text (and (region-active-p) + (buffer-substring-no-properties + (region-beginning) (region-end)))) + (mode major-mode) + (derived-p (derived-mode-p 'prog-mode 'text-mode)) + (old-project (doom-project-root))) + (unless (file-directory-p doom-scratch-files-dir) + (mkdir doom-scratch-files-dir t)) + (with-current-buffer + (if project-p + (find-file-noselect + (expand-file-name (replace-regexp-in-string + "\\." "_" (projectile-project-name) + t t) + doom-scratch-files-dir) + nil t) + (get-buffer-create "*doom:scratch*")) + (when project-p + (rename-buffer (format "*doom:scratch (%s)*" (projectile-project-name)))) + (setq default-directory old-project) + (when (and (not (eq major-mode mode)) + derived-p + (functionp mode)) + (funcall mode)) + (if text (insert text)) + (run-hooks 'doom-scratch-buffer-hook) + (current-buffer)))) + +;;;###autoload +(defun doom/open-scratch-buffer () + "Opens a temporary scratch buffer in a popup window. It is discarded once it +is closed. If a region is active, copy it to the scratch buffer." + (interactive) + (doom-popup-buffer (doom--create-scratch-buffer))) + +;;;###autoload +(defun doom/open-project-scratch-buffer () + "Opens a (persistent) scratch buffer associated with the current project in a +popup window. Scratch buffers are stored in `doom-scratch-files-dir'. If a +region is active, copy it to the scratch buffer." + (interactive) + (doom-popup-buffer (doom--create-scratch-buffer t))) +