From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23167 invoked by alias); 1 Jun 2011 19:59:22 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29430 Received: (qmail 28290 invoked from network); 1 Jun 2011 19:59:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at m.gmane.org designates 80.91.229.12 as permitted sender) X-Injected-Via-Gmane: http://gmane.org/ To: zsh-workers@zsh.org From: Bernhard Tittelbach Subject: Behaviour of {beginning,end}-of-buffer-or-history Date: Wed, 01 Jun 2011 21:43:51 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: chello080109208103.3.graz.surfer.at User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.23) Gecko/20091001 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 Hi, recently I was dissatisfied with the behavior of my HOME/END keys. What I wanted was this: If cursor is a beginning/end of the buffer then jump to the beginning/end of the history Else jump to the beginning/end of that line, no matter whether we are in a multi- or single-line buffer Seemingly there are functions that do exactly that: beginning-of-buffer-or-history Move to the beginning of the buffer, or if already there, move to the first event in the history list. end-of-buffer-or-history Move to the end of the buffer, or if already there, move to the last event in the history list. But in reality, what above functions really do is this: If cursor is a beginning/end of a buffer then jump to the beginning/end of the history ElseIf cursor is somewhere in a SINGLE-LINE buffer then jump to the beginning/end of the history (why ???) Else jump to the beginning/end of the MULTI-LINE buffer I wonder if this is really how these functions are intended to work ? At the very least I would consider them misnamed, or does "buffer" really only ever refer to multi-line buffers ? In any case I thus wrote a bit of shell code that does the correct thing from my point of view (improvements welcome): ## --------------------------------------------------------------------- ## beginning-of-line OR beginning-of-buffer OR beginning of history ## (i.e. do it right, like beginning-of-buffer-or-history doesn't) function jump-position-in-line-or-buffer-or-history { local -a buflines beginning_of_lines end_of_lines cur_array local linepossum=0 buflines=(${(f)BUFFER}) beginning_of_lines=(0) for ((c=1;c<=$#buflines;c++)) do linepossum=$(( linepossum + ${#buflines[c]} )) end_of_lines+=( $linepossum ) beginning_of_lines+=( $((++linepossum)) ) done cur_array=(${(P)${${WIDGET/line-or-buffer-or-history/lines}//-/_}}) if [[ ${cur_array[(i)$CURSOR]} -le ${#cur_array} ]]; then zle .${WIDGET/line-or-buffer-or-history/buffer-or-history} "$@" else zle .${WIDGET/line-or-buffer-or-history/line} "$@" fi } zle -N beginning-of-line-or-buffer-or-history \ jump-position-in-line-or-buffer-or-history && \ bindkey '\eOH' beginning-of-line-or-buffer-or-history zle -N end-of-line-or-buffer-or-history \ jump-position-in-line-or-buffer-or-history && \ bindkey '\eOF' end-of-line-or-buffer-or-history ## --------------------------------------------------------------------- cheers, Bernhard