<commit_before>_POWERLINE_SOURCED="$0:A"

_powerline_columns_fallback() {
	if which stty &>/dev/null ; then
		local cols="$(stty size 2>/dev/null)"
		if ! test -z "$cols" ; then
			echo "${cols#* }"
			return 0
		fi
	fi
	echo 0
	return 0
}

integer _POWERLINE_JOBNUM

_powerline_init_tmux_support() {
	emulate -L zsh
	if test -n "$TMUX" && tmux refresh -S &>/dev/null ; then
		# TMUX variable may be unset to create new tmux session inside this one
		typeset -g _POWERLINE_TMUX="$TMUX"

		function -g _powerline_tmux_setenv() {
			emulate -L zsh
			local -x TMUX="$_POWERLINE_TMUX"
			tmux setenv -g TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
			tmux refresh -S
		}

		function -g _powerline_tmux_set_pwd() {
			_powerline_tmux_setenv PWD "$PWD"
		}

		function -g _powerline_tmux_set_columns() {
			_powerline_tmux_setenv COLUMNS "${COLUMNS:-$(_powerline_columns_fallback)}"
		}

		chpwd_functions+=( _powerline_tmux_set_pwd )
		trap '_powerline_tmux_set_columns' SIGWINCH
		_powerline_tmux_set_columns
		_powerline_tmux_set_pwd
	fi
}

_powerline_init_modes_support() {
	emulate -L zsh

	test -z "$ZSH_VERSION" && return 0

	typeset -ga VS
	VS=( ${(s:.:)ZSH_VERSION} )

	# Mode support requires >=zsh-4.3.11
	if (( VS[1] < 4 || (VS[1] == 4 && (VS[2] < 3 || (VS[2] == 3 && VS[3] < 11))) )) ; then
		return 0
	fi

	function -g _powerline_get_main_keymap_name() {
		REPLY="${${(Q)${${(z)${"$(bindkey -lL main)"}}[3]}}:-.safe}"
	}

	function -g _powerline_set_true_keymap_name() {
		_POWERLINE_MODE="${1}"
		local plm_bk="$(bindkey -lL ${_POWERLINE_MODE})"
		if [[ $plm_bk = 'bindkey -A'* ]] ; then
			_powerline_set_true_keymap_name ${(Q)${${(z)plm_bk}[3]}}
		fi
	}

	function -g _powerline_zle_keymap_select() {
		_powerline_set_true_keymap_name $KEYMAP
		zle reset-prompt
		test -z "$_POWERLINE_SAVE_WIDGET" || zle $_POWERLINE_SAVE_WIDGET
	}

	function -g _powerline_set_main_keymap_name() {
		local REPLY
		_powerline_get_main_keymap_name
		_powerline_set_true_keymap_name "$REPLY"
	}

	_powerline_add_widget zle-keymap-select _powerline_zle_keymap_select
	_powerline_set_main_keymap_name

	if [[ "$_POWERLINE_MODE" != vi* ]] ; then
		_POWERLINE_DEFAULT_MODE="$_POWERLINE_MODE"
	fi

	precmd_functions+=( _powerline_set_main_keymap_name )
}

_powerline_set_jobnum() {
	# If you are wondering why I am not using the same code as I use for bash 
	# ($(jobs|wc -l)): consider the following test:
	#     echo abc | less
	#     <C-z>
	# . This way jobs will print
	#     [1]  + done       echo abc |
	#            suspended  less -M
	# ([ is in first column). You see: any line counting thingie will return 
	# wrong number of jobs. You need to filter the lines first. Or not use 
	# jobs built-in at all.
	_POWERLINE_JOBNUM=${(%):-%j}
}

_powerline_update_counter() {
	zpython '_powerline.precmd()'
}

_powerline_setup_prompt() {
	emulate -L zsh

	for f in "${precmd_functions[@]}"; do
		if [[ "$f" = '_powerline_set_jobnum' ]]; then
			return
		fi
	done
	precmd_functions+=( _powerline_set_jobnum )

	VIRTUAL_ENV_DISABLE_PROMPT=1

	if test -z "${POWERLINE_NO_ZSH_ZPYTHON}" && { zmodload libzpython || zmodload zsh/zpython } &>/dev/null ; then
		precmd_functions+=( _powerline_update_counter )
		zpython 'from powerline.bindings.zsh import setup as _powerline_setup'
		zpython '_powerline_setup(globals())'
		zpython 'del _powerline_setup'
		powerline-reload() {
			zpython 'from powerline.bindings.zsh import reload as _powerline_reload'
			zpython '_powerline_reload()'
			zpython 'del _powerline_reload'
		}
		powerline-reload-config() {
			zpython 'from powerline.bindings.zsh import reload_config as _powerline_reload_config'
			zpython '_powerline_reload_config()'
			zpython 'del _powerline_reload_config'
		}
	else
		if test -z "${POWERLINE_COMMAND}" ; then
			POWERLINE_COMMAND="$($POWERLINE_CONFIG_COMMAND shell command)"
		fi
<commit_msg>Use special function for appending to precmd_functions<commit_after>_POWERLINE_SOURCED="$0:A"

_powerline_columns_fallback() {
	if which stty &>/dev/null ; then
		local cols="$(stty size 2>/dev/null)"
		if ! test -z "$cols" ; then
			echo "${cols#* }"
			return 0
		fi
	fi
	echo 0
	return 0
}

_powerline_append_precmd_function() {
	if test -z "${precmd_functions[(re)$1]}" ; then
		precmd_functions+=( $1 )
	fi
}

integer _POWERLINE_JOBNUM

_powerline_init_tmux_support() {
	emulate -L zsh
	if test -n "$TMUX" && tmux refresh -S &>/dev/null ; then
		# TMUX variable may be unset to create new tmux session inside this one
		typeset -g _POWERLINE_TMUX="$TMUX"

		function -g _powerline_tmux_setenv() {
			emulate -L zsh
			local -x TMUX="$_POWERLINE_TMUX"
			tmux setenv -g TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
			tmux refresh -S
		}

		function -g _powerline_tmux_set_pwd() {
			_powerline_tmux_setenv PWD "$PWD"
		}

		function -g _powerline_tmux_set_columns() {
			_powerline_tmux_setenv COLUMNS "${COLUMNS:-$(_powerline_columns_fallback)}"
		}

		chpwd_functions+=( _powerline_tmux_set_pwd )
		trap '_powerline_tmux_set_columns' SIGWINCH
		_powerline_tmux_set_columns
		_powerline_tmux_set_pwd
	fi
}

_powerline_init_modes_support() {
	emulate -L zsh

	test -z "$ZSH_VERSION" && return 0

	typeset -ga VS
	VS=( ${(s:.:)ZSH_VERSION} )

	# Mode support requires >=zsh-4.3.11
	if (( VS[1] < 4 || (VS[1] == 4 && (VS[2] < 3 || (VS[2] == 3 && VS[3] < 11))) )) ; then
		return 0
	fi

	function -g _powerline_get_main_keymap_name() {
		REPLY="${${(Q)${${(z)${"$(bindkey -lL main)"}}[3]}}:-.safe}"
	}

	function -g _powerline_set_true_keymap_name() {
		_POWERLINE_MODE="${1}"
		local plm_bk="$(bindkey -lL ${_POWERLINE_MODE})"
		if [[ $plm_bk = 'bindkey -A'* ]] ; then
			_powerline_set_true_keymap_name ${(Q)${${(z)plm_bk}[3]}}
		fi
	}

	function -g _powerline_zle_keymap_select() {
		_powerline_set_true_keymap_name $KEYMAP
		zle reset-prompt
		test -z "$_POWERLINE_SAVE_WIDGET" || zle $_POWERLINE_SAVE_WIDGET
	}

	function -g _powerline_set_main_keymap_name() {
		local REPLY
		_powerline_get_main_keymap_name
		_powerline_set_true_keymap_name "$REPLY"
	}

	_powerline_add_widget zle-keymap-select _powerline_zle_keymap_select
	_powerline_set_main_keymap_name

	if [[ "$_POWERLINE_MODE" != vi* ]] ; then
		_POWERLINE_DEFAULT_MODE="$_POWERLINE_MODE"
	fi

	_powerline_append_precmd_function _powerline_set_main_keymap_name
}

_powerline_set_jobnum() {
	# If you are wondering why I am not using the same code as I use for bash 
	# ($(jobs|wc -l)): consider the following test:
	#     echo abc | less
	#     <C-z>
	# . This way jobs will print
	#     [1]  + done       echo abc |
	#            suspended  less -M
	# ([ is in first column). You see: any line counting thingie will return 
	# wrong number of jobs. You need to filter the lines first. Or not use 
	# jobs built-in at all.
	_POWERLINE_JOBNUM=${(%):-%j}
}

_powerline_update_counter() {
	zpython '_powerline.precmd()'
}

_powerline_setup_prompt() {
	emulate -L zsh

	_powerline_append_precmd_function _powerline_set_jobnum

	VIRTUAL_ENV_DISABLE_PROMPT=1

	if test -z "${POWERLINE_NO_ZSH_ZPYTHON}" && { zmodload libzpython || zmodload zsh/zpython } &>/dev/null ; then
		_powerline_append_precmd_function _powerline_update_counter
		zpython 'from powerline.bindings.zsh import setup as _powerline_setup'
		zpython '_powerline_setup(globals())'
		zpython 'del _powerline_setup'
		powerline-reload() {
			zpython 'from powerline.bindings.zsh import reload as _powerline_reload'
			zpython '_powerline_reload()'
			zpython 'del _powerline_reload'
		}
		powerline-reload-config() {
			zpython 'from powerline.bindings.zsh import reload_config as _powerline_reload_config'
			zpython '_powerline_reload_config()'
			zpython 'del _powerline_reload_config'
		}
	else
		if test -z "${POWERLINE_COMMAND}" ; then
			POWERLINE_COMMAND="$($POWERLINE_CONFIG_COMMAND shell command)"
		fi

{'fraction_non_alphanumeric': 0.12230492813141684, 'fraction_numerical': 0.0077002053388090345, 'mean_word_length': 4.334017796030117, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '349422', 'n_tokens_mistral': 3307, 'n_tokens_neox': 3103, 'n_words': 681}