Update modules/feature/evil
This commit is contained in:
parent
8122c9f653
commit
2f87987803
4 changed files with 185 additions and 109 deletions
|
@ -1,14 +1,30 @@
|
|||
;;; feature/evil/packages.el
|
||||
|
||||
;;;###autoload
|
||||
(defun +evil/visual-indent ()
|
||||
"vnoremap < <gv"
|
||||
(interactive)
|
||||
(evil-shift-right (region-beginning) (region-end))
|
||||
(evil-normal-state)
|
||||
(evil-visual-restore))
|
||||
|
||||
;;;###autoload
|
||||
(defun +evil/visual-dedent ()
|
||||
"vnoremap > >gv"
|
||||
(interactive)
|
||||
(evil-shift-left (region-beginning) (region-end))
|
||||
(evil-normal-state)
|
||||
(evil-visual-restore))
|
||||
|
||||
;;;###autoload
|
||||
(defun +evil*ex-replace-special-filenames (file-name)
|
||||
"Replace special symbols in FILE-NAME. Modified to include other substitution
|
||||
flags."
|
||||
;; TODO Generalize this so I can offer it upstream
|
||||
(let ((regexp (concat "\\(?:^\\|[^\\\\]\\)"
|
||||
"\\([#%@]\\)"
|
||||
"\\(\\(?::\\(?:[phtreS~.]\\|g?s[^: $]+\\)\\)*\\)"))
|
||||
case-fold-search)
|
||||
;; TODO Remove s.el dependency so I can offer it upstream
|
||||
(dolist (match (s-match-strings-all regexp file-name))
|
||||
(let ((flags (split-string (cl-caddr match) ":" t))
|
||||
(path (file-relative-name
|
||||
|
@ -47,7 +63,7 @@ flags."
|
|||
"")))
|
||||
(setq file-name
|
||||
(replace-regexp-in-string (format "\\(?:^\\|[^\\\\]\\)\\(%s\\)"
|
||||
(s-trim-left (car match)))
|
||||
(string-trim-left (car match)))
|
||||
path file-name t t 1)))))
|
||||
(setq file-name (replace-regexp-in-string regexp "\\1" file-name t))))
|
||||
|
||||
|
@ -141,7 +157,25 @@ evil-window-move-* (e.g. `evil-window-move-far-left')"
|
|||
(switch-to-buffer this-buffer))
|
||||
(select-window that-window))))
|
||||
|
||||
;;;###autoload (autoload '+evil:macro-on-all-lines "feature/evil/autoload" nil t)
|
||||
;;;###autoload
|
||||
(defun +evil/window-move-left () "`+evil-window-move'" (interactive) (evil-window-move 'left))
|
||||
;;;###autoload
|
||||
(defun +evil/window-move-right () "`+evil-window-move'" (interactive) (evil-window-move 'right))
|
||||
;;;###autoload
|
||||
(defun +evil/window-move-up () "`+evil-window-move'" (interactive) (evil-window-move 'up))
|
||||
;;;###autoload
|
||||
(defun +evil/window-move-down () "`+evil-window-move'" (interactive) (evil-window-move 'down))
|
||||
|
||||
;;;###autoload
|
||||
(defun +evil/matchit-or-toggle-fold ()
|
||||
"If on a fold-able element, toggle the fold (`hs-toggle-hiding'). Otherwise,
|
||||
if on a delimiter, jump to the matching one (`evilmi-jump-items')."
|
||||
(interactive)
|
||||
(if (ignore-errors (hs-already-hidden-p))
|
||||
(hs-toggle-hiding)
|
||||
(call-interactively 'evilmi-jump-items)))
|
||||
|
||||
;;;###autoload (autoload '+evil:macro-on-all-lines "feature/evil/autoload/evil" nil t)
|
||||
(evil-define-operator +evil:macro-on-all-lines (beg end &optional macro)
|
||||
"Apply macro to each line."
|
||||
:motion nil
|
||||
|
@ -154,3 +188,33 @@ evil-window-move-* (e.g. `evil-window-move-far-left')"
|
|||
(concat "@"
|
||||
(single-key-description
|
||||
(or macro (read-char "@-"))))))
|
||||
|
||||
;;;###autoload (autoload '+evil:open-folds-recursively "feature/evil/autoload/evil" nil t)
|
||||
(evil-define-command +evil:open-folds-recursively (level)
|
||||
"Opens all folds recursively, up to LEVEL."
|
||||
(interactive "<c>")
|
||||
(unless (bound-and-true-p hs-minor-mode)
|
||||
(hs-minor-mode 1))
|
||||
(if level (hs-hide-level level) (evil-open-folds)))
|
||||
|
||||
;;;###autoload (autoload '+evil:close-folds-recursively "feature/evil/autoload/evil" nil t)
|
||||
(evil-define-command +evil:close-folds-recursively (level)
|
||||
"Closes all folds recursively, up to LEVEL."
|
||||
(interactive "<c>")
|
||||
(unless (bound-and-true-p hs-minor-mode)
|
||||
(hs-minor-mode 1))
|
||||
(if level (hs-hide-level level) (evil-close-folds)))
|
||||
|
||||
;;;###autoload (autoload '+evil:retab "feature/evil/autoload/evil" nil t)
|
||||
(evil-define-operator +evil:retab (&optional beg end)
|
||||
"Wrapper around `doom/retab'."
|
||||
:motion nil :move-point nil :type line
|
||||
(interactive "<r>")
|
||||
(doom/retab beg end))
|
||||
|
||||
;;;###autoload (autoload '+evil:narrow-buffer "feature/evil/autoload/evil" nil t)
|
||||
(evil-define-command +evil:narrow-buffer (beg end &optional bang)
|
||||
"Wrapper around `doom-narrow-buffer'."
|
||||
:move-point nil
|
||||
(interactive "<r><!>")
|
||||
(doom-narrow-buffer beg end bang))
|
||||
|
|
|
@ -4,25 +4,27 @@
|
|||
(evil-define-command +evil:file-delete (&optional bang filename)
|
||||
"Delete current buffer's file. If BANG, don't ask for confirmation."
|
||||
:repeat nil
|
||||
;; TODO Test me
|
||||
(interactive "<!><f>")
|
||||
(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))
|
||||
(let* ((fname (file-truename (or fname (buffer-file-name))))
|
||||
(fbase (file-name-sans-extension (file-name-nondirectory fname)))
|
||||
(buf (current-buffer)))
|
||||
(cond ((not (file-exists-p fname))
|
||||
(error "File doesn't exist: %s" fname))
|
||||
|
||||
((not (or bang (y-or-n-p (format "Delete %s?" (f-base filename)))))
|
||||
((not (or bang (y-or-n-p (format "Delete %s?" fbase))))
|
||||
(message "Aborted"))
|
||||
|
||||
(t
|
||||
(unwind-protect
|
||||
(delete-file filename)
|
||||
(if (f-exists-p filename)
|
||||
(error "Failed to delete %s" (f-relative filename))
|
||||
(delete-file fname)
|
||||
(if (file-exists-p fname)
|
||||
(error "Failed to delete %s" (file-relative-name fname))
|
||||
(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))))))))
|
||||
(message "Successfully deleted %s" (file-relative-name fname))))))))
|
||||
|
||||
(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)
|
||||
|
@ -31,14 +33,15 @@
|
|||
you to fill in each snippet field before buffer closes unless BANG is
|
||||
provided."
|
||||
:repeat nil
|
||||
;; TODO Test me
|
||||
(interactive "<f><!>")
|
||||
(let ((dir (f-dirname path))
|
||||
(fullpath (f-full path))
|
||||
(is-auto t))
|
||||
(when (and bang (not (f-exists? dir)))
|
||||
(let* ((fullpath (expand-file-name path))
|
||||
(dir (file-name-directory fullpath))
|
||||
(is-auto t))
|
||||
(when (and bang (not (file-exists-p dir)))
|
||||
(mkdir dir))
|
||||
(if (f-exists? dir)
|
||||
(if (f-exists? fullpath)
|
||||
(if (file-exists-p dir)
|
||||
(if (file-exists-p fullpath)
|
||||
(error "File already exists: %s" path)
|
||||
(find-file fullpath)
|
||||
(add-hook 'yas-after-exit-snippet-hook 'doom--save-exit)
|
||||
|
@ -46,32 +49,32 @@ provided."
|
|||
(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)
|
||||
(evil-define-command +evil:file-move (bang dest-path)
|
||||
"Move current buffer's file to PATH. Replaces %, # and other variables (see
|
||||
`evil-ex-replace-special-filenames')"
|
||||
:repeat nil
|
||||
(interactive "<f>")
|
||||
(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))))
|
||||
;; TODO Test me
|
||||
(interactive "<!><f>")
|
||||
(let* ((dest-path (expand-file-name dest-path))
|
||||
(old-path (file-truename (buffer-file-name)))
|
||||
(new-path (cond ((file-directory-p dest-path)
|
||||
(expand-file-name (file-name-nondirectory old-path) dest-path))
|
||||
((file-directory-p (file-name-directory dest-path))
|
||||
(expand-file-name dest-path))
|
||||
(t (user-error "Not a valid destination: %s" dest-path))))
|
||||
(project-root (doom-project-root))
|
||||
(short-old-path (file-relative-name old-path project-root))
|
||||
(short-new-path (file-relative-name new-path project-root)))
|
||||
(when (y-or-n-p (format "Renaming %s to %s, proceed?"
|
||||
short-old-path short-dest-path))
|
||||
(when (buffer-modified-p)
|
||||
(save-buffer))
|
||||
(rename-file old-path new-path 1)
|
||||
(rename-buffer (file-name-nondirectory 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'"
|
||||
short-old-path short-new-path))))
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
(neotree-hide)
|
||||
(let ((project-root (doom-project-root)))
|
||||
(unless (and (neo-global--window-exists-p)
|
||||
(f-same? (neo-global--with-buffer neo-buffer--start-node) project-root))
|
||||
(equal (file-truename (neo-global--with-buffer neo-buffer--start-node))
|
||||
(file-truename project-root)))
|
||||
(neotree-dir project-root))
|
||||
(neotree-find path project-root)))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue