summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-27 13:42:36 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-27 13:42:36 +0800
commit9a665974c00bec7848e49b2e87a93e21f6cc4241 (patch)
tree949b33ce50c466bd2deb5f74d8e1147ea6c8a6b5
parent8440d42c74f04babdf513d4cdee77f968226f749 (diff)
eshell: expand dots
* eshell-conf.el (durand-eshell-expand-dots): Replace multiple dots by correct syntax. (eshell-expand-input-functions): Add to this variable so that Eshell automatically expands dots.
-rw-r--r--eshell-conf.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/eshell-conf.el b/eshell-conf.el
index ebadfda..f4c8a23 100644
--- a/eshell-conf.el
+++ b/eshell-conf.el
@@ -451,6 +451,39 @@ other value means 1."
(add-to-list 'eshell-expand-input-functions
#'eshell-expand-history-references)
+;;; Expand multiple dots
+
+(defun durand-eshell-expand-dots (beg end)
+ "Expand multiple dots in BEG and END.
+For example, \"...\" expands into \"../..\"."
+ (save-excursion
+ (save-match-data
+ (let ((str (buffer-substring beg end))
+ (start 0))
+ (while (string-match (rx ".." (1+ ".")) str start)
+ (let* ((matched (match-string 0 str))
+ (len (length matched)))
+ (setq
+ str
+ (replace-match
+ (let ((result "..")
+ (index 2))
+ (while (< index len)
+ (setq index (1+ index))
+ (setq
+ result
+ (concat result "/..")))
+ result)
+ nil nil str))
+ (setq start (+ (match-end 0)
+ (lsh (- len 2) 1)))))
+ (goto-char beg)
+ (delete-region beg end)
+ (insert str)))))
+
+(add-to-list 'eshell-expand-input-functions
+ #'durand-eshell-expand-dots)
+
;;; Visual commands
(add-to-list 'eshell-visual-commands