doomemacs/modules/ui/doom/autoload/evil.el

24 lines
934 B
EmacsLisp
Raw Normal View History

;;; ui/doom/autoload/evil.el -*- lexical-binding: t; -*-
2017-01-31 05:09:20 -05:00
2017-02-19 18:52:26 -05:00
;;;###autoload (autoload '+doom:scratch-buffer "ui/doom/autoload/evil" nil t)
2017-01-31 05:09:20 -05:00
(evil-define-operator +doom:scratch-buffer (&optional beg end bang)
"Opens the scratch buffer in a popup window and, optionally, send the selected
region to it. If BANG, use current window instead of a popup."
2017-02-19 18:52:26 -05:00
:move-point nil :type inclusive
2017-01-31 05:09:20 -05:00
(interactive "<r><!>")
(let ((text (when (and (not (evil-normal-state-p)) beg end)
2017-01-31 05:09:20 -05:00
(buffer-substring beg end)))
(mode major-mode)
(old-project (doom-project-root))
(new-buf (get-buffer-create "*doom:scratch*")))
(if bang
(switch-to-buffer new-buf)
(doom-popup-buffer new-buf))
2017-01-31 05:09:20 -05:00
(with-current-buffer new-buf
(setq default-directory old-project)
2017-01-31 05:09:20 -05:00
(when (and (not (eq major-mode mode))
(functionp mode))
(funcall mode))
(if text (insert text)))))
2017-01-31 05:09:20 -05:00