abo-abo / avy

Jump to things in Emacs tree-style
1.74k stars 111 forks source link

Request: Jump with single character from one set, or multiple chars from another set #194

Open alphapapa opened 7 years ago

alphapapa commented 7 years ago

Hi,

Thanks for avy, it makes navigating quick and easy.

I recently decided to add the whole alphabet to avy-keys so I can jump to more positions with a single keypress. But then I realized that, when there are more than 26 positions, avy uses the last key in the list as the first key for all subsequent multi-character jumps. So I put f at the end of the list, so at least every pair starts with a key on the home row. But then it becomes more awkward if the second character of the pair is not on the home row.

It would be nice to have the best of both worlds: jump to the first (length set-1) positions with the characters from set-1 and use characters from another set for all positions beyond that number. Then I could make set-1 the whole alphabet, and make the second set only the home row. That way, more positions are available with a single keypress, but for ones that require two, they would be entirely on the home row.

Thanks for your consideration.

abo-abo commented 7 years ago

Thanks for avy, it makes navigating quick and easy.

You're welcome.

I recently decided to add the whole alphabet to avy-keys so I can jump to more positions with a single keypress. But then I realized that, when there are more than 26 positions, avy uses the last key in the list as the first key for all subsequent multi-character jumps. So I put f at the end of the list, so at least every pair starts with a key on the home row. But then it becomes more awkward if the second character of the pair is not on the home row.

This can be solved by putting a key from the home row as the last element of avy-keys.

It would be nice to have the best of both worlds: jump to the first (length set-1) positions with the characters from set-1 and use characters from another set for all positions beyond that number. Then I could make set-1 the whole alphabet, and make the second set only the home row. That way, more positions are available with a single keypress, but for ones that require two, they would be entirely on the home row.

Nice idea. But I don't think it's high priority, especially since many people already got used to how it works now. Feel free to play around with avy-tree. It's possible to do what you want by changing only this function.

Here's an example change to get you started:

(defun avy-tree (lst keys)
  "Coerce LST into a balanced tree.
The degree of the tree is the length of KEYS.
KEYS are placed appropriately on internal nodes."
  (let ((len (length keys)))
    (cl-labels
        ((rd (ls)
           (let ((ln (length ls)))
             (if (< ln len)
                 (nreverse
                  (cl-pairlis keys
                              (mapcar (lambda (x) (cons 'leaf x)) ls)))
               (let ((ks (nreverse (copy-sequence keys)))
                     res)
                 (dolist (s (avy-subdiv ln len))
                   (push (cons (pop ks)
                               (if (eq s 1)
                                   (cons 'leaf (pop ls))
                                 (rd (avy-multipop ls s))))
                         res))
                 (nreverse res))))))
      (rd lst))))
pheaver commented 7 years ago

Hello. My colleague and I were just trying out avy for the first time and found we wanted this exact functionality :).