Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: correct A04redirect.ztst so that it works on VSCode



On Thu, Nov 30, 2023 at 2:29 AM Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
>
> > On 29/11/2023 17:45 GMT Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > could we just do this?
> >
> > bad_fd_msg="${$( { exec 9>&-; echo >&9 } 2>&1)##*:}"
>
> Don't see why not.

Patch.
diff --git a/Completion/Unix/Command/_ant b/Completion/Unix/Command/_ant
index 36c7c0e89..91428b854 100644
--- a/Completion/Unix/Command/_ant
+++ b/Completion/Unix/Command/_ant
@@ -122,13 +122,13 @@ case $state in
                         read default_target junk
                     fi
                     # Output target again indicating its the default one.
-                    print -n "'${default_target}:(Default target) ' "
+                    print -rn -- "${(qq):-${default_target}:(Default target)} "
                 ;;
                 (Searching:*|Main:targets:|Subtargets:|BUILD:SUCCESSFUL|Total:time:*)
                 ;;
                 (*)
                     # Return target and description
-                    print -n "'$ln' "
+                    print -rn -- "${(qq)ln} "
                 ;;
             esac
           done
diff --git a/Functions/Misc/sticky-note b/Functions/Misc/sticky-note
index efe5ec1eb..80ff22619 100644
--- a/Functions/Misc/sticky-note
+++ b/Functions/Misc/sticky-note
@@ -21,42 +21,97 @@
 # as an editor history.  Two quick taps on the return/enter key finish
 # the note, or you can use ^X^W as usual (ZZ in vicmd mode).
 
-# The application is configured by three zstyles, all using the context
-# ":sticky-note".  The first two styles are "notefile" and "maxnotes"
-# to name the file in which notes are stored and the maximum number of
-# notes to retain:
+# The application is configured by several zstyles, all using the context
+# ":sticky-note".  The complete list of styles is and their types is:
+#   notefile       string (filename)
+#   maxnotes       number
+#   history-opts   array
+#   vared-options  array
+#   theme          associative array
+#   display        associative array
+#   list-display   boolean (string true|yes|on|1 or not set for false)
+
+# The first two styles are "notefile" and "maxnotes" to name the file in
+# which notes are stored and the maximum number of notes to retain:
 #   zstyle :sticky-note notefile ~/.zsticky
 #   zstyle :sticky-note maxnotes 1000
 
+# For backwards compatibility with an earlier version, the notefile may
+# also be named by the STICKYFILE variable (defaults to $HOME/.zsticky).
+# The number of notes stored may be given by STICKYSIZE (1000).
+
+# The "history-opts" style gives a list of setopt names, passed to
+# "setopt localoptions ...".  Note that this means you must use the "no"
+# prefix to disable an option.  The extendedhistory option is always used
+# regardless of the setting of this style, to record note timestamps.
+# Otherwise, the default is equivalent to
+#   zstyle :sticky-note history-opts \
+#     noappendhistory nobanghist histignoredups
+# Values that do not contain the substring "hist" are ignored, along with:
+#   histlexwords histnofunctions histnostore incappendhistory sharehistory
+# Useful values include:
+#   histexpiredupsfirst histfindnodups histignorealldups histsavenodups
+# Other setopts not related to history are reset via "emulate -R zsh".
+
+# The "vared-options" style lists options passed to vared when a note
+# is edited. The vared options -A, -a, -c, -M, and -m are ignored.  The
+# useful options are -i, -f, -e, -p, -r, and in unusual cases -t.  The
+# options -p and -r should use the same syntax as the "prompt" value of
+# the "theme" style, described below, and the -r option should.  As a
+# special case, to make the note history unavailable when editing,
+# include +h in the vared-options style.  Example:
+#   zstyle :sticky-note vared-options +h -e -r %T
+
 # The "theme" style may be set to control the appearance of the notes.
 # The style is an associative array; the current set of values (defaults
 # in parens) are:
-#   bg    => name or ANSI escape for background color (yellow)
-#   fg    => name or ANSI escape for foreground color (black)
-#   color => ANSI escape for color scheme ($theme[bg]$theme[fg])
-#   reset => ANSI escape to restore "normal" colors
+#   bg     => name or ANSI escape for background color (yellow)
+#   fg     => name or ANSI escape for foreground color (black)
+#   color  => ANSI escape for color scheme ($theme[bg]$theme[fg])
+#   reset  => ANSI escape to restore "normal" colors
+#   prompt => Passed to vared.  May refer to %{${theme[bg]}%} et al.
 # Values given as names are looked up in the $bg and $fg arrays from the
 # "colors" function.  If a "color" field is set, the "bg" and "fg" fields
-# are not used.  Example:
+# are not used unless referenced in "prompt".  The prompt value should
+# be single-quoted and must use appropriate %{...%} wrappers around
+# zero-width outputs such as color changes.  Example:
 #   zstyle :sticky-note theme \
 #     bg red \
-#     fg $fg_bold[yellow]
+#     fg $fg_bold[yellow] \
+#     prompt '%{$theme[bg]$fg_bold[white]%}POST-IT:%{$theme[reset]%}'
+# NOTE:  You must define either color or both fg and bg, but the values
+# $theme[color] and $theme[reset] are always generated if omitted.
 
-# For backwards compatibility with an earlier version, the notefile may
-# also be named by the STICKYFILE variable (defaults to $HOME/.zsticky).
-# The number of notes stored may be given by STICKYSIZE (1000).
+# The "display" style is an associative array mapping custom display
+# attribute names to the ANSI codes to enable them.  The style must use
+# "%s" at the position where the note should appear, and must end with
+# ANSI codes to discontinue the style.  An empty value turns off the
+# display formatting.  For example:
+#   zstyle :sticky-note display \
+#     none "" \
+#     blink "$(echoti blink)%s$(echoti sgr0)" \
+#     reverse $'\e[07m%s\e[00m'
+# If you use this style, a file named $STICKYFILE.display is created
+# to preserve the display attributes of the notes in $STICKYFILE.
+# NOTE: Changing the display zstyle does not change the display of
+# previously created notes.  There is no default display style.
+
+# To set the display for a note, type ctrl-x question-mark (^X?) to
+# run the widget "_sticky-display".  When a "display" style is set, this
+# replaces the _complete_help binding from the default keymap.  The
+# keymap named "sticky" may be modified to customize this, after running
+# "sticky-note -b" to initialize.
+
+# By default the display style is only applied when "posting" notes to
+# the top of the screen via the ZLE widget, but can be applied to the
+# output of "sticky-note -l" by setting the "list-display" style:
+#   zstyle :sticky-note list-display true
 
 # I encourage all you creative people to contribute enhancements ...
 
 emulate -LR zsh
-setopt nobanghist extendedhistory histignoredups
-
-local STICKYFILE=${STICKYFILE:-$HOME/.zsticky}
-local STICKYSIZE=${STICKYSIZE:-1000}
-local sticky stickyfile stickysize
 
-zstyle -s :sticky-note notefile stickyfile || stickyfile=$STICKYFILE
-zstyle -s :sticky-note maxnotes stickysize || stickysize=$STICKYSIZE
+typeset -gA .zsticky.display
 
 # Set up keybindings (adapted from "zed")
 if ! bindkey -M sticky >& /dev/null
@@ -71,9 +126,95 @@ then
   bindkey -N sticky-vicmd vicmd
   bindkey -M sticky-vicmd ZZ accept-line
 fi
+if ! functions _sticky-display >& /dev/null &&
+     zstyle -m :sticky-note display '*'
+then
+  function _sticky-display {
+    if [[ -z $compstate[vared] ]]
+    then
+      local save_buffer=$BUFFER save_cursor=$CURSOR
+      BUFFER=
+      zle -U $'\t'
+      zle recursive-edit -K sticky-display
+      .zsticky.display[last]=$BUFFER
+      PREDISPLAY="[ $BUFFER ] "
+      BUFFER=$save_buffer CURSOR=$save_cursor
+      zle reset-prompt
+    else
+      zstyle -a :sticky-note display sticky_displays
+      compadd -x "Press TAB to choose display mode, ENTER to set:" \
+	      -V nosort ${.zsticky.display[last]} \
+	      ${${(ok)sticky_displays}:#${.zsticky.display[last]}}
+      compstate[insert]=menu
+    fi
+  }
+  zle -N _sticky-display
+  bindkey -M sticky '^X?' _sticky-display
+  zle -C sticky-display-choices menu-complete _sticky-display
+  bindkey -N sticky-display
+  bindkey -M sticky-display $'\t' sticky-display-choices
+  bindkey -M sticky-display ^M accept-line
+fi
 
 [[ "$1" == -b ]] && return 0
 
+setopt noflowcontrol nobanghist extendedhistory histignoredups
+setopt noappendhistory nosharehistory noincappendhistory
+unsetopt histlexwords histnofunctions histnostore
+zmodload -i zsh/datetime
+
+local STICKYFILE=${STICKYFILE:-$HOME/.zsticky}
+local STICKYSIZE=${STICKYSIZE:-1000}
+local PREDISPLAY sticky stickyfile stickysize
+local -A sticky_displays vared_options
+
+zstyle -s :sticky-note notefile stickyfile || stickyfile=$STICKYFILE
+zstyle -s :sticky-note maxnotes stickysize || stickysize=$STICKYSIZE
+
+# Populate custom history setopts
+() {
+  local -a h0
+  if zstyle -a :sticky-note history-opts h0
+  then
+    h0=( ${(M)h0:#*hist*} )
+    h0=( ${h0:#*(extended|lexwords|nofunctions|nostore|incappend|share)*} )
+    setopt $h0
+  fi
+}
+
+# Populate options to vared
+() {
+  local -a v0
+  if zstyle -a :sticky-note vared-options v0
+  then
+    v0[${v0[(i)-a]}]=()
+    v0[${v0[(i)-A]}]=()
+    v0[${v0[(i)-c]}]=()
+    if (( ${v0[(I)+h]} ))
+    then
+      v0[${v0[(i)-h]}]=()
+      v0[${v0[(i)+h]}]=()
+    else
+      v0+=(-h '')
+    fi
+    if (( ${v0[(I)-g]} ))
+    then
+      v0[${v0[(i)-g]}]=(-g '')
+    fi
+    if (( ${v0[(I)-e]} ))
+    then
+      v0[${v0[(i)-e]}]=(-e '')
+    fi
+  vared_options=( "$v0[@]" )
+  else
+    vared_options=(-h '')
+  fi
+}
+: ${vared_options[-i]:=undefined-key}
+: ${vared_options[-f]:=undefined-key}
+: ${vared_options[-M]::=sticky}
+: ${vared_options[-m]::=sticky-vicmd}
+
 # Look up color theme
 local -A theme
 (($+bg && $+fg)) || { autoload -Uz colors; colors }
@@ -85,6 +226,32 @@ zstyle -a :sticky-note theme theme
 (( ${+fg[$theme[fg]]} )) && theme[fg]=$fg[$theme[fg]]
 (( ${+theme[color]} )) || theme[color]=$theme[bg]$theme[fg]
 (( ${+theme[reset]} )) || theme[reset]=$reset_color
+(( ${+theme[prompt]} )) || theme[prompt]=$vared_options[-p]
+
+theme[prompt]="${(e)theme[prompt]}%{${theme[color]}%}"
+vared_options[-p]=$theme[prompt]
+
+# Load per-note display settings
+if [[ -z ${.zsticky.display} && -r $stickyfile.display ]]
+then
+  source $stickyfile.display
+  # Clean up notes expired from the STICKYFILE.
+  () {
+    local -a display_keys=(last) d0
+    while IFS=': ' read -A d0
+    do
+      display_keys+=( $d0[2] )
+    done < $stickyfile
+    d0=( ${(k).zsticky.display} )
+    set -- ${d0:|display_keys}
+    while [[ -n $1 ]]
+    do
+      unset ".zsticky.display[$1]"
+      shift
+    done
+    typeset -p 1 .zsticky.display >| $stickyfile.display
+  }
+fi
 
 # If invoked as a widget, behave a bit like run-help
 if zle
@@ -92,11 +259,22 @@ then
   zmodload -i zsh/parameter
   if [[ $* == -*l* || $functrace == *zle-line-init:* ]]
   then
+    local num stamp ceol=${ echoti el }
     fc -ap $stickyfile $stickysize $stickysize
+    echoti cup $LINES 1
+    zle reset-prompt
     echoti sc
     echoti home
     print -nr "$theme[color]"
-    fc -l "${@:--1}" | while read -r sticky; do print -- "$sticky"; done
+    fc -t %s -l "${@:--1}" |
+      while read -r num stamp sticky
+      do
+	if [[ -n ${.zsticky.display[$stamp]} ]]
+	then
+	  printf -v sticky "${.zsticky.display[$stamp]}$theme[color]" $sticky
+	fi
+	printf %s\\n "$num  "${sticky//$'\\n'/$ceol$'\n'}$ceol
+      done
     print -nr "$theme[reset]"
     echoti rc
   elif [[ $CONTEXT = (cont|select|vared) ]]
@@ -118,19 +296,46 @@ fc -ap $stickyfile $stickysize $stickysize
 # With a -l option, list the existing sticky notes
 if [[ "$*" == -*l* ]]
 then
+  local num stamp display
   print -nr "$theme[color]"
   # Use read/print loop to interpolate "\n" in history lines
-  fc -f "$@" | while read -r sticky; do print -- "$sticky"; done
+  fc -t %s "$@" |
+    while read -r num stamp sticky
+    do
+      if zstyle -t :sticky-note list-display &&
+	  [[ -n ${.zsticky.display[$stamp]} ]]
+      then
+	printf -v sticky "${.zsticky.display[$stamp]}$theme[color]" $sticky
+      fi
+      print -- "${| strftime -s REPLY -n '%x %H:%M' $stamp }  $sticky"
+    done
   print -nr "$theme[reset]"
   return 0
 fi
 
 # Edit a new sticky note and add it to the stickyfile
-while vared -h -p "%{$theme[color]%}" -M sticky -m sticky-vicmd sticky
-do
+while {
+    vared ${(kv)vared_options} sticky
+  } always {
+    # Assure we reach "return 0" to complete fc -ap
+    TRY_BLOCK_INTERRUPT=0
+} do
   {
-    [[ -n "$sticky" ]] && print -s -- "$sticky"
+    if [[ -n "$sticky" ]]
+    then
+      print -s -- "$sticky"
+      fc -W && SAVEHIST=0
+      # File is updated but internal "fc -l" is not yet.  Get the timestamp.
+      stamp=${${${| local line;
+		  while read line; do REPLY=$line; done <$stickyfile }#: }%%:*}
+      if [[ -n $stamp && -n ${.zsticky.display[last]} && -n $sticky_displays ]]
+      then
+	.zsticky.display[$stamp]=${sticky_displays[${.zsticky.display[last]}]}
+        typeset -p 1 .zsticky.display >| $stickyfile.display
+      fi
+    fi
   } always {
+    unset sticky_displays
     (( TRY_BLOCK_ERROR = 0 ))
   } && break
   echo -n -e '\a'
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index 17f6dfa29..dc62efab3 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -3,9 +3,8 @@
 %prep
   mkdir redir.tmp && cd redir.tmp
 
-  myfd=99
-  (echo >&$myfd) 2>msg
-  bad_fd_msg="${$(<msg)##*:}"
+  bad_fd_msg="${$( { exec 9>&-; echo >&9 } 2>&1)##*:}"
+  [[ -n "$bad_fd_msg" ]]
 
 %test
 


Messages sorted by: Reverse Date, Date, Thread, Author