From 9a665974c00bec7848e49b2e87a93e21f6cc4241 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Thu, 27 Jan 2022 13:42:36 +0800 Subject: 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. --- eshell-conf.el | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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 -- cgit v1.2.3-18-g5258