Fix +evil-resolve-vim-path-a not removing excess backslashes
This commit is contained in:
parent
10623868b8
commit
dbf9c92b48
1 changed files with 60 additions and 70 deletions
|
@ -15,76 +15,66 @@ support for most vim file modifiers, as well as:
|
||||||
|
|
||||||
See http://vimdoc.sourceforge.net/htmldoc/cmdline.html#filename-modifiers for
|
See http://vimdoc.sourceforge.net/htmldoc/cmdline.html#filename-modifiers for
|
||||||
more information on modifiers."
|
more information on modifiers."
|
||||||
(let* (case-fold-search
|
(let (case-fold-search)
|
||||||
(regexp (concat "\\(?:^\\|[^\\\\]\\)"
|
(with-temp-buffer
|
||||||
"\\(\\([#%]\\)"
|
(save-excursion (insert file-name))
|
||||||
"\\(\\(?::\\(?:[PphtreS~.]\\|g?s[^:\t\n ]+\\)\\)*\\)\\)"))
|
(while (re-search-forward "\\(^\\|[^\\\\]\\)\\(\\([%#]\\)\\(:\\([PphtreS~.]\\|g?s\\)\\)*\\)" nil t)
|
||||||
(matches
|
(catch 'continue
|
||||||
(cl-loop with i = 0
|
(unless buffer-file-name
|
||||||
while (and (< i (length file-name))
|
(replace-match (match-string 1) t t nil 2)
|
||||||
(string-match regexp file-name i))
|
(throw 'continue t))
|
||||||
do (setq i (1+ (match-beginning 0)))
|
(let ((beg (match-beginning 2))
|
||||||
and collect
|
(end (match-end 3))
|
||||||
(cl-loop for j to (/ (length (match-data)) 2)
|
(path (pcase (match-string 3)
|
||||||
collect (match-string j file-name)))))
|
("%" (file-relative-name buffer-file-name))
|
||||||
(dolist (match matches)
|
("#" (and (other-buffer)
|
||||||
(let ((flags (split-string (cadddr match) ":" t))
|
(buffer-file-name (other-buffer)))))))
|
||||||
(path (and buffer-file-name
|
(save-match-data
|
||||||
(pcase (caddr match)
|
(goto-char beg)
|
||||||
("%" (file-relative-name buffer-file-name))
|
(while (re-search-forward ":\\([PphtreS~.]\\|g?s\\)" (+ (point) 3) t)
|
||||||
("#" (save-excursion (other-window 1) (file-relative-name buffer-file-name))))))
|
(let* ((modifier (match-string 1))
|
||||||
flag global)
|
(global (string-prefix-p "gs" modifier)))
|
||||||
(if (not path)
|
(when global
|
||||||
(setq path "")
|
(setq modifier (substring modifier 1)))
|
||||||
(while flags
|
(setq end (match-end 1)
|
||||||
(setq flag (pop flags))
|
path
|
||||||
(when (string-suffix-p "\\" flag)
|
(or (when path
|
||||||
(setq flag (concat flag (pop flags))))
|
(pcase (substring modifier 0 1)
|
||||||
(when (string-prefix-p "gs" flag)
|
("p" (expand-file-name path))
|
||||||
(setq global t
|
("~" (concat "~/" (file-relative-name path "~")))
|
||||||
flag (substring flag 1)))
|
("." (file-relative-name path default-directory))
|
||||||
(setq path
|
("t" (file-name-nondirectory (directory-file-name path)))
|
||||||
(or (pcase (substring flag 0 1)
|
("r" (file-name-sans-extension path))
|
||||||
("p" (expand-file-name path))
|
("e" (file-name-extension path))
|
||||||
("~" (concat "~/" (file-relative-name path "~")))
|
("S" (shell-quote-argument path))
|
||||||
("." (file-relative-name path default-directory))
|
("h"
|
||||||
("t" (file-name-nondirectory (directory-file-name path)))
|
(let ((parent (file-name-directory (expand-file-name path))))
|
||||||
("r" (file-name-sans-extension path))
|
(unless (file-equal-p path parent)
|
||||||
("e" (file-name-extension path))
|
(if (file-name-absolute-p path)
|
||||||
("S" (shell-quote-argument path))
|
(directory-file-name parent)
|
||||||
("h"
|
(file-relative-name parent)))))
|
||||||
(let ((parent (file-name-directory (expand-file-name path))))
|
("s"
|
||||||
(unless (equal (file-truename path)
|
(if (featurep 'evil)
|
||||||
(file-truename parent))
|
(when-let (args (evil-delimited-arguments (substring modifier 1) 2))
|
||||||
(if (file-name-absolute-p path)
|
(let ((pattern (evil-transform-vim-style-regexp (car args)))
|
||||||
(directory-file-name parent)
|
(replace (cadr args)))
|
||||||
(file-relative-name parent)))))
|
(replace-regexp-in-string
|
||||||
("s"
|
(if global pattern (concat "\\(" pattern "\\).*\\'"))
|
||||||
(if (featurep 'evil)
|
(evil-transform-vim-style-regexp replace) path t t
|
||||||
(when-let (args (evil-delimited-arguments (substring flag 1) 2))
|
(unless global 1))))
|
||||||
(let ((pattern (evil-transform-vim-style-regexp (car args)))
|
path))
|
||||||
(replace (cadr args)))
|
("P"
|
||||||
(replace-regexp-in-string
|
(let ((project-root (doom-project-root (file-name-directory (expand-file-name path)))))
|
||||||
(if global pattern (concat "\\(" pattern "\\).*\\'"))
|
(unless project-root
|
||||||
(evil-transform-vim-style-regexp replace) path t t
|
(user-error "Not in a project"))
|
||||||
(unless global 1))))
|
(abbreviate-file-name project-root)))))
|
||||||
path))
|
""))
|
||||||
("P"
|
;; strip trailing slash, if applicable
|
||||||
(let ((project-root (doom-project-root (file-name-directory (expand-file-name path)))))
|
(or (string-empty-p path)
|
||||||
(unless project-root
|
(not (equal (substring path -1) "/"))
|
||||||
(user-error "Not in a project"))
|
(setq path (substring path 0 -1))))))
|
||||||
(abbreviate-file-name project-root)))
|
(replace-match path t t nil 2))))
|
||||||
(_ path))
|
(replace-regexp-in-string "\\\\\\([#%]\\)" "\\1" (buffer-string) t))))
|
||||||
"")))
|
|
||||||
;; strip trailing slash, if applicable
|
|
||||||
(when (and (not (string= path "")) (equal (substring path -1) "/"))
|
|
||||||
(setq path (substring path 0 -1))))
|
|
||||||
(setq file-name
|
|
||||||
(replace-regexp-in-string
|
|
||||||
(format "\\(?:^\\|[^\\\\]\\)\\(%s\\)"
|
|
||||||
(regexp-quote (cadr match)))
|
|
||||||
path file-name t t 1))))
|
|
||||||
(replace-regexp-in-string regexp "\\1" file-name t)))
|
|
||||||
|
|
||||||
(defun +evil--insert-newline (&optional above _noextranewline)
|
(defun +evil--insert-newline (&optional above _noextranewline)
|
||||||
(let ((pos (save-excursion (beginning-of-line-text) (point)))
|
(let ((pos (save-excursion (beginning-of-line-text) (point)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue