New commands: doom/open-{,project-}scratch-buffer
This commit is contained in:
parent
bc1d2480b0
commit
1685076202
2 changed files with 41 additions and 18 deletions
|
@ -225,32 +225,57 @@ for function signatures or notes. Run again to clear the header line."
|
||||||
content)))))
|
content)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/scratch-buffer (&optional arg)
|
(defun doom|enable-delete-trailing-whitespace ()
|
||||||
"Opens the scratch buffer in a popup window.
|
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
|
||||||
|
|
||||||
If ARG (universal argument) is non-nil, open it in the current window instead of
|
|
||||||
a popup.
|
|
||||||
|
|
||||||
If a region is active, copy it into the scratch buffer."
|
;; -- scratch buffer ----------------------
|
||||||
(interactive "P")
|
|
||||||
|
(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)
|
(let ((text (and (region-active-p)
|
||||||
(buffer-substring-no-properties
|
(buffer-substring-no-properties
|
||||||
(region-beginning) (region-end))))
|
(region-beginning) (region-end))))
|
||||||
(mode major-mode)
|
(mode major-mode)
|
||||||
(derived-p (derived-mode-p 'prog-mode 'text-mode))
|
(derived-p (derived-mode-p 'prog-mode 'text-mode))
|
||||||
(old-project (doom-project-root))
|
(old-project (doom-project-root)))
|
||||||
(new-buf (get-buffer-create "*doom:scratch*")))
|
(unless (file-directory-p doom-scratch-files-dir)
|
||||||
(if arg
|
(mkdir doom-scratch-files-dir t))
|
||||||
(switch-to-buffer new-buf)
|
(with-current-buffer
|
||||||
(doom-popup-buffer new-buf))
|
(if project-p
|
||||||
(with-current-buffer new-buf
|
(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)
|
(setq default-directory old-project)
|
||||||
(when (and (not (eq major-mode mode))
|
(when (and (not (eq major-mode mode))
|
||||||
derived-p
|
derived-p
|
||||||
(functionp mode))
|
(functionp mode))
|
||||||
(funcall mode))
|
(funcall mode))
|
||||||
(if text (insert text)))))
|
(if text (insert text))
|
||||||
|
(run-hooks 'doom-scratch-buffer-hook)
|
||||||
|
(current-buffer))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom|enable-delete-trailing-whitespace ()
|
(defun doom/open-scratch-buffer (arg)
|
||||||
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
|
"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 10 :autokill t :noesc nil) 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)))
|
||||||
|
|
|
@ -28,9 +28,7 @@
|
||||||
(ex! "sh[ell]" #'+eshell:run)
|
(ex! "sh[ell]" #'+eshell:run)
|
||||||
(ex! "t[mux]" #'+tmux:run) ; send to tmux
|
(ex! "t[mux]" #'+tmux:run) ; send to tmux
|
||||||
(ex! "tcd" #'+tmux:cd-here) ; cd to default-directory in tmux
|
(ex! "tcd" #'+tmux:cd-here) ; cd to default-directory in tmux
|
||||||
|
(ex! "x" #'doom/open-project-scratch-buffer)
|
||||||
(evil-set-command-properties #'doom/scratch-buffer :ex-bang t)
|
|
||||||
(ex! "x" #'doom/scratch-buffer)
|
|
||||||
|
|
||||||
;; GIT
|
;; GIT
|
||||||
(ex! "gist" #'+gist:send) ; send current buffer/region to gist
|
(ex! "gist" #'+gist:send) ; send current buffer/region to gist
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue