Hey! I have this in my Zsh configuration: autoload -Uz url-quote-magic zle -N self-insert url-quote-magic autoload -Uz bracketed-paste-magic zle -N bracketed-paste bracketed-paste-magic It works fine, but after some time, it stops working. Pasting an URL with a question mark left the mark unquoted. Just reexecing zsh fixes the issue. I don't really know how to start investigate such an issue. Bracketed paste never stops working. Thanks!
On Wed, Jul 6, 2022 at 11:13 PM Vincent Bernat <bernat@luffy.cx> wrote:
>
> zle -N self-insert url-quote-magic
> zle -N bracketed-paste bracketed-paste-magic
>
> It works fine, but after some time, [url-quote-magic] stops working.
> Bracketed paste never stops working.
First thing to check is whether any of your widgets have become
re-bound somehow.
zle -l -L bracketed-paste self-insert
should return
zle -N bracketed-paste bracketed-paste-magic
zle -N self-insert url-quote-magic
If that hasn't changed, does url-quote-magic work when just typing in
a URL without pasting?
If so, next I'd try
exec 2>/tmp/zshuqmtrace
functions -t url-quote-magic
and then paste a URL. See if you get anything in that trace file.
On 7/9/22 05:10, Bart Schaefer wrote: > On Wed, Jul 6, 2022 at 11:13 PM Vincent Bernat <bernat@luffy.cx> wrote: >> >> zle -N self-insert url-quote-magic >> zle -N bracketed-paste bracketed-paste-magic >> >> It works fine, but after some time, [url-quote-magic] stops working. >> Bracketed paste never stops working. > > First thing to check is whether any of your widgets have become > re-bound somehow. > zle -l -L bracketed-paste self-insert > should return > zle -N bracketed-paste bracketed-paste-magic > zle -N self-insert url-quote-magic I am using autosuggest, so I get: 07:22 ❱ zle -l -L bracketed-paste self-insert zle -N bracketed-paste _zsh_autosuggest_bound_1_bracketed-paste zle -N self-insert _zsh_autosuggest_bound_1_self-insert > If that hasn't changed, does url-quote-magic work when just typing in > a URL without pasting? It does not work either. > If so, next I'd try > exec 2>/tmp/zshuqmtrace > functions -t url-quote-magic > and then paste a URL. See if you get anything in that trace file. url-quote-magic ❱ setopt localoptions noksharrays extendedglob url-quote-magic ❱ local qkey='\?' url-quote-magic ❱ local -a reply match mbegin mend url-quote-magic ❱ [[ '?' != \\\? ]] url-quote-magic ❱ local lbuf='http://kjfkjkgjf/fgkfjgkf\?' url-quote-magic ❱ [[ 'http://kjfkjkgjf/fgkfjgkf?' == http://kjfkjkgjf/fgkfjgkf\? ]] url-quote-magic ❱ local -a words url-quote-magic ❱ words=( 'http://kjfkjkgjf/fgkfjgkf?' ) url-quote-magic ❱ local urlseps urlmetas urlglobbers localschema otherschema url-quote-magic ❱ [[ 'http://kjfkjkgjf/fgkfjgkf?' == (#b)([^:]##):* ]] url-quote-magic ❱ zstyle -s :url-quote-magic url-globbers urlglobbers '|' url-quote-magic ❱ zmodload -i zsh/parameter url-quote-magic ❱ reply=( noglob '=' globurl ) url-quote-magic ❱ zstyle -s :urlglobber url-other-schema otherschema '|' url-quote-magic ❱ [[ 'http://kjfkjkgjf/fgkfjgkf?' == noglob|=|globurl ]] url-quote-magic ❱ localschema=' ' url-quote-magic ❱ case http://kjfkjkgjf/fgkfjgkf? (*['"]*) url-quote-magic ❱ case http://kjfkjkgjf/fgkfjgkf? ((\ ):/(|/localhost)/*) url-quote-magic ❱ case http://kjfkjkgjf/fgkfjgkf? ((http|https|ftp):*) url-quote-magic ❱ [[ '' == *\?* ]] url-quote-magic ❱ zle .self-insert For some reason, typing manually an URL always failed, but not copy/pasting. It seems the condition if [[ "$words[-1]" == (#b)([^:]##):* ]] does not match. I am using "disable -p #" which seems to be the cause. Using "emulate -L zsh" at the top of the function instead of "setopt localoptions" fixes the issue. I though functions should use "emulate -L zsh" when using these options, but in Zsh codebase, "setopt localoptions" seems used often. Should any of this considered as a bug?
On Fri, Jul 8, 2022 at 10:40 PM Vincent Bernat <bernat@luffy.cx> wrote: > > I am using autosuggest, so I get: > > zle -N bracketed-paste _zsh_autosuggest_bound_1_bracketed-paste I can't think of any reason autosuggest would need to rebind that widget. > It seems the condition if [[ "$words[-1]" == (#b)([^:]##):* ]] does not > match. I am using "disable -p #" which seems to be the cause. Using > "emulate -L zsh" at the top of the function instead of "setopt > localoptions" fixes the issue. I though functions should use "emulate -L > zsh" when using these options, but in Zsh codebase, "setopt > localoptions" seems used often. Should any of this considered as a bug? "emulate -L" potentially resets a lot of things. The decision for each function has to be whether the scope requires all those elements to be reset, or whether to make minimal changes so as to behave as much as possible like the rest of the user's environment. In the case of url-quote-magic I can't presently think of any reason not to use "emulate -L". That said, I also can't think of any contributed function that intentionally defends itself against pattern disables.
On 2022-07-10 19:44, Bart Schaefer wrote: >> I am using autosuggest, so I get: >> >> zle -N bracketed-paste _zsh_autosuggest_bound_1_bracketed-paste > > I can't think of any reason autosuggest would need to rebind that widget. I am adding it to ZSH_AUTOSUGGEST_CLEAR_WIDGETS. I suppose I didn't want the last suggestion to be kept after pasting. >> It seems the condition if [[ "$words[-1]" == (#b)([^:]##):* ]] does not >> match. I am using "disable -p #" which seems to be the cause. Using >> "emulate -L zsh" at the top of the function instead of "setopt >> localoptions" fixes the issue. I though functions should use "emulate -L >> zsh" when using these options, but in Zsh codebase, "setopt >> localoptions" seems used often. Should any of this considered as a bug? > > "emulate -L" potentially resets a lot of things. The decision for > each function has to be whether the scope requires all those elements > to be reset, or whether to make minimal changes so as to behave as > much as possible like the rest of the user's environment > > In the case of url-quote-magic I can't presently think of any reason > not to use "emulate -L". Meantime, I am just wrapping it: autoload -Uz url-quote-magic function _vbe-url-quote-magic() { emulate -L zsh url-quote-magic "$@" } zle -N self-insert _vbe-url-quote-magic > That said, I also can't think of any > contributed function that intentionally defends itself against pattern > disables. It's a wonder I am not running into such issues more often. I'll just disable extendedglob as I am only interested into the negative pattern and I don't use it that often.