summaryrefslogtreecommitdiff
path: root/Functions/Zle
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Zle')
-rw-r--r--Functions/Zle/.distfiles3
-rw-r--r--Functions/Zle/expand-absolute-path19
-rw-r--r--Functions/Zle/read-from-minibuffer9
-rw-r--r--Functions/Zle/replace-argument48
-rw-r--r--Functions/Zle/zcalc-auto-insert8
5 files changed, 87 insertions, 0 deletions
diff --git a/Functions/Zle/.distfiles b/Functions/Zle/.distfiles
index 256044fa5..90a07690b 100644
--- a/Functions/Zle/.distfiles
+++ b/Functions/Zle/.distfiles
@@ -10,6 +10,7 @@ delete-whole-word-match
down-case-word-match
down-line-or-beginning-search
edit-command-line
+expand-absolute-path
forward-word-match
history-beginning-search-menu
history-pattern-search
@@ -31,6 +32,7 @@ narrow-to-region-invisible
predict-on
quote-and-complete-word
read-from-minibuffer
+replace-argument
replace-string
replace-string-again
select-word-style
@@ -43,5 +45,6 @@ up-case-word-match
up-line-or-beginning-search
url-quote-magic
which-command
+zcalc-auto-insert
zed-set-file-name
'
diff --git a/Functions/Zle/expand-absolute-path b/Functions/Zle/expand-absolute-path
new file mode 100644
index 000000000..b85757600
--- /dev/null
+++ b/Functions/Zle/expand-absolute-path
@@ -0,0 +1,19 @@
+# expand-absolute-path
+# This is a ZLE widget to expand the absolute path to a file,
+# using directory naming to shorten the path where possible.
+
+emulate -L zsh
+setopt extendedglob cbases
+
+autoload -Uz modify-current-argument
+
+if (( ! ${+functions[glob-expand-absolute-path]} )); then
+ glob-expand-absolute-path() {
+ local -a files
+ files=(${~1}(N:A))
+ (( ${#files} )) || return
+ REPLY=${(D)files[1]}
+ }
+fi
+
+modify-current-argument glob-expand-absolute-path
diff --git a/Functions/Zle/read-from-minibuffer b/Functions/Zle/read-from-minibuffer
index 57e926884..8fec1105e 100644
--- a/Functions/Zle/read-from-minibuffer
+++ b/Functions/Zle/read-from-minibuffer
@@ -20,7 +20,9 @@ done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
local readprompt="$1" lbuf_init="$2" rbuf_init="$3"
+integer changeno=$UNDO_CHANGE_NO
+{
# Use anonymous function to make sure special values get restored,
# even if this function is called as a widget.
# local +h ensures special parameters stay special.
@@ -39,10 +41,17 @@ local readprompt="$1" lbuf_init="$2" rbuf_init="$3"
read -k $keys
stat=$?
else
+ local NUMERIC
+ unset NUMERIC
zle recursive-edit -K main
stat=$?
(( stat )) || REPLY=$BUFFER
fi
}
+} always {
+ # This removes the edits relating to the read from the undo history.
+ # These aren't useful once we get back to the main editing buffer.
+ zle undo $changeno
+}
return $stat
diff --git a/Functions/Zle/replace-argument b/Functions/Zle/replace-argument
new file mode 100644
index 000000000..0ef3de7b5
--- /dev/null
+++ b/Functions/Zle/replace-argument
@@ -0,0 +1,48 @@
+# Replace an argument to a command, delimited by normal shell syntax.
+# Prompts for the replacement.
+# With no numeric argument, replace the current argument.
+# With a numeric argument, replace that argument: 0 = command word,
+# as in history expansion.
+# If editing buffer is empty, use previous history line.
+
+autoload -Uz split-shell-arguments read-from-minibuffer
+
+if (( ${#BUFFER} == 0 )); then
+ (( HISTNO-- ))
+ CURSOR=${#BUFFER}
+fi
+
+local widget=$WIDGET numeric
+integer cursor=CURSOR
+if (( ${+NUMERIC} )); then
+ numeric=$NUMERIC
+fi
+local reply REPLY REPLY2
+integer index
+split-shell-arguments
+
+if [[ -n $numeric ]]; then
+ if (( numeric < 0 )); then
+ (( index = ${#reply} - 1 + 2*(numeric+1) ))
+ else
+ (( index = 2 + 2*numeric ))
+ fi
+else
+ (( index = REPLY & ~1 ))
+fi
+
+local edit
+if [[ $widget = *edit* ]]; then
+ edit=$reply[$index]
+fi
+read-from-minibuffer "Replace $reply[$index] with: " $edit || return 1
+
+integer diff=$(( ${#REPLY} - ${#reply[$index]} ))
+reply[$index]=$REPLY
+
+BUFFER=${(j..)reply}
+if (( cursor > REPLY2 )); then
+ (( CURSOR = cursor + diff ))
+else
+ (( CURSOR = REPLY2 ))
+fi
diff --git a/Functions/Zle/zcalc-auto-insert b/Functions/Zle/zcalc-auto-insert
new file mode 100644
index 000000000..c9a5c8867
--- /dev/null
+++ b/Functions/Zle/zcalc-auto-insert
@@ -0,0 +1,8 @@
+# Bind to a binary operator keystroke for use with zcalc
+
+if [[ -n $ZCALC_ACTIVE ]]; then
+ if [[ $CURSOR -eq 0 || $LBUFFER[-1] = "(" ]]; then
+ LBUFFER+=${ZCALC_AUTO_INSERT_PREFIX:-"ans "}
+ fi
+fi
+zle .self-insert