From 57b937cf99c7a15ff6109da4a10ec6f7afbd57a6 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 9 Feb 2017 05:09:21 -0500 Subject: [PATCH] feature/evil: split autoload.el into autoload/{evil,files}.el --- .../evil/{autoload.el => autoload/evil.el} | 0 modules/feature/evil/autoload/files.el | 77 +++++++++++++++++++ modules/feature/evil/config.el | 4 +- 3 files changed, 80 insertions(+), 1 deletion(-) rename modules/feature/evil/{autoload.el => autoload/evil.el} (100%) create mode 100644 modules/feature/evil/autoload/files.el diff --git a/modules/feature/evil/autoload.el b/modules/feature/evil/autoload/evil.el similarity index 100% rename from modules/feature/evil/autoload.el rename to modules/feature/evil/autoload/evil.el diff --git a/modules/feature/evil/autoload/files.el b/modules/feature/evil/autoload/files.el new file mode 100644 index 000000000..668951a3c --- /dev/null +++ b/modules/feature/evil/autoload/files.el @@ -0,0 +1,77 @@ +;;; feature/evil/autoload/files.el + +;;;###autoload (autoload '+evil:file-delete "feature/evil/autoload/files" nil t) +(evil-define-command +evil:file-delete (&optional bang filename) + "Delete current buffer's file. If BANG, don't ask for confirmation." + :repeat nil + (interactive "") + (let ((filename (f-canonical (or filename (buffer-file-name)))) + (buf (current-buffer))) + (cond ((not (f-exists-p filename)) + (error "File doesn't exist: %s" filename)) + + ((not (or bang (y-or-n-p (format "Delete %s?" (f-base filename))))) + (message "Aborted")) + + (t + (unwind-protect + (delete-file filename) + (if (f-exists-p filename) + (error "Failed to delete %s" (f-relative filename)) + (doom/previous-real-buffer) + (kill-buffer buf) + (when (bound-and-true-p save-place-mode) + (save-place-forget-unreadable-files)) + (message "Successfully deleted %s" (f-relative filename)))))))) + +(defun doom--save-exit() (save-buffer) (kill-buffer) (remove-hook 'yas-after-exit-snippet-hook '--save-exit)) +;;;###autoload (autoload '+evil:file-create "feature/evil/autoload/files" nil t) +(evil-define-command +evil:file-create (path &optional bang) + "Deploy files (and their associated templates) quickly. Will prompt +you to fill in each snippet field before buffer closes unless BANG is +provided." + :repeat nil + (interactive "") + (let ((dir (f-dirname path)) + (fullpath (f-full path)) + (is-auto t)) + (when (and bang (not (f-exists? dir))) + (mkdir dir)) + (if (f-exists? dir) + (if (f-exists? fullpath) + (error "File already exists: %s" path) + (find-file fullpath) + (add-hook 'yas-after-exit-snippet-hook 'doom--save-exit) + (if bang (doom--save-exit))) + (error "Directory doesn't exist: %s" dir)))) + +;;;###autoload (autoload '+evil:file-move "feature/evil/autoload/files" nil t) +(evil-define-command +evil:file-move (path) + "Move current buffer's file to PATH. Replaces %, # and other variables (see +`evil-ex-replace-special-filenames')" + :repeat nil + (interactive "") + (let* ((old-path (buffer-file-name)) + (new-path (cond ((f-dir? path) + (f-expand (f-filename old-path) path)) + ((f-dir? (f-dirname path)) + (f-full path)) + (t (user-error "Not a valid destination: %s" path)))) + (project-root (doom-project-root))) + ;; Move all attachments if in org-mode + (when (eq major-mode 'org-mode) + (mapc (lambda (file) + (when (and (file-exists-p file) (not (f-same? old-path new-path))) + (rename-file file (f-expand (f-filename old-path) (f-dirname new-path)) t))) + (doom/org-attachments))) + (when (buffer-modified-p) + (save-buffer)) + (rename-file old-path new-path 1) + (rename-buffer (f-filename new-path)) + (set-visited-file-name new-path) + (set-buffer-modified-p nil) + (save-place-forget-unreadable-files) + (setq doom--spaceline-file-path nil) + (message "File '%s' successfully renamed to '%s'" + (f-relative old-path project-root) (f-relative new-path project-root)))) + diff --git a/modules/feature/evil/config.el b/modules/feature/evil/config.el index 61716333f..d72d97221 100644 --- a/modules/feature/evil/config.el +++ b/modules/feature/evil/config.el @@ -127,7 +127,6 @@ :motion mark-whole-buffer :move-point nil (interactive "") (evil-ex-global beg end pattern command invert)) -(evil-ex-define-cmd "g[lobal]" '+evil:global) (evil-define-operator +evil:align (&optional beg end bang pattern) "Ex interface to `align-regexp'. Accepts vim-style regexps." @@ -140,6 +139,9 @@ (evil-transform-vim-style-regexp pattern))) 1 1)) +(evil-ex-define-cmd "g[lobal]" '+evil:global) +(evil-ex-define-cmd "al[ign]" '+evil:align) + ;; ;; Plugins