Combine doom/open-scratch-buffer & doom/open-project-scratch-buffer
These two are now doom/open-scratch-buffer. If you're in a project, a (persistent) scratch buffer is opened. Otherwise, a non-persistent, transient scratch buffer is opened. If ARG (universal argument) is non-nil, then use the current window instead of a new window (or popup, if feature/popup is enabled). Also, the ex command :x[!] is improved. The BANG = open in current window.
This commit is contained in:
parent
d0fa95f9a0
commit
bbb969fa59
2 changed files with 32 additions and 25 deletions
|
@ -7,27 +7,31 @@
|
|||
(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)
|
||||
(defun doom--create-scratch-buffer ()
|
||||
(let* ((project-p (doom-project-p 'nocache))
|
||||
(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)))
|
||||
(project-root (if project-p (doom-project-root 'nocache)))
|
||||
(id (projectile-project-name)))
|
||||
(when (and id (string-empty-p id))
|
||||
(user-error "Invalid id for a scratch buffer (%s)" id))
|
||||
(unless (file-directory-p doom-scratch-files-dir)
|
||||
(mkdir doom-scratch-files-dir t))
|
||||
(make-directory doom-scratch-files-dir t))
|
||||
(with-current-buffer
|
||||
(if project-p
|
||||
(find-file-noselect
|
||||
(expand-file-name (replace-regexp-in-string
|
||||
"\\." "_" (projectile-project-name)
|
||||
"\\." "_" id
|
||||
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)
|
||||
(rename-buffer (format "*doom:scratch (%s)*" id))
|
||||
(setq default-directory project-root))
|
||||
(when (and (not (eq major-mode mode))
|
||||
derived-p
|
||||
(functionp mode))
|
||||
|
@ -37,17 +41,16 @@
|
|||
(current-buffer))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/open-scratch-buffer (&optional in-project-p)
|
||||
"Opens a temporary scratch buffer. It is discarded once it is closed. If a
|
||||
region is active, copy it to the scratch buffer."
|
||||
(defun doom/open-scratch-buffer (&optional arg)
|
||||
"Opens a persistent scratch buffer in the same major-mode, at the current
|
||||
project root. If no project is found, scratch buffer will not be persistent. If
|
||||
a selection is active, copy it to the scratch buffer.
|
||||
|
||||
If ARG (universal argument) is non-nil, display the buffer in the current
|
||||
window. Otherwise, display it in a pop up window.
|
||||
|
||||
Persistent scratch buffers are stored in `doom-scratch-files-dir'."
|
||||
(interactive "P")
|
||||
(pop-to-buffer (doom--create-scratch-buffer in-project-p)))
|
||||
|
||||
;;;###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/open-scratch-buffer 'in-project))
|
||||
(funcall (if arg #'switch-to-buffer #'display-buffer)
|
||||
(doom--create-scratch-buffer)))
|
||||
|
||||
|
|
|
@ -2,10 +2,14 @@
|
|||
|
||||
(defalias 'ex! 'evil-ex-define-cmd)
|
||||
|
||||
(evil-define-command doom:cleanup-session (&optional bang)
|
||||
(evil-define-command doom:cleanup-session (bang)
|
||||
(interactive "<!>")
|
||||
(doom/cleanup-session bang))
|
||||
|
||||
(evil-define-operator doom:open-scratch-buffer (bang)
|
||||
(interactive "<!>")
|
||||
(doom/open-scratch-buffer bang))
|
||||
|
||||
|
||||
;;
|
||||
;; Commands
|
||||
|
@ -38,7 +42,7 @@
|
|||
(ex! "sh[ell]" #'+eshell:run)
|
||||
(ex! "t[mux]" #'+tmux:run) ; send to tmux
|
||||
(ex! "tcd" #'+tmux:cd-here) ; cd to default-directory in tmux
|
||||
(ex! "x" #'doom/open-project-scratch-buffer)
|
||||
(ex! "x" #'doom:open-scratch-buffer)
|
||||
;; GIT
|
||||
(ex! "gist" #'+gist:send) ; send current buffer/region to gist
|
||||
(ex! "gistl" #'+gist:list) ; list gists by user
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue