* avy.el: Add sub-package for building a completion tree. * avy-test.el: Add. * Makefile: Add. * ace-window.el (ace-jump-mode): Don't require. (avy): Require. (aw-leading-char-face): Update. (aw-background-face): New defface. (aw-list-visual-area): Rename to `aw-window-list'. It returns simple windows now, instead of visual area structs. (aw-overlays-lead): New defvar. (aw-overlays-back): New defvar. (ace-window-mode): Use own minor mode, instead of `ace-jump-mode'. (aw--done): Update. (aw--lead-overlay): New defun. (aw--make-leading-chars): New defun. (aw--remove-leading-chars): New defun. (aw--make-backgrounds): New defun. (aw-select): Simplify. (ace-window): Update doc. (aw-visual-area<): Rename to `aw-window<'. It deals with simple windows now.old-master
parent
8b5f10a471
commit
d81f079ba5
4 changed files with 291 additions and 148 deletions
@ -0,0 +1,14 @@ |
||||
EMACS = emacs
|
||||
# EMACS = emacs-24.3
|
||||
|
||||
LOAD = -l avy.el -l avy-test.el
|
||||
|
||||
.PHONY: all test clean |
||||
|
||||
all: test |
||||
|
||||
test: |
||||
$(EMACS) -batch $(LOAD) -f ert-run-tests-batch-and-exit
|
||||
|
||||
clean: |
||||
rm -f *.elc
|
||||
@ -0,0 +1,42 @@ |
||||
(require 'ert) |
||||
(require 'avy) |
||||
|
||||
(ert-deftest avy-subdiv () |
||||
(should |
||||
(equal (avy-subdiv 5 4) |
||||
'(1 1 1 2))) |
||||
(should |
||||
(equal (avy-subdiv 10 4) |
||||
'(1 1 4 4))) |
||||
(should |
||||
(equal (avy-subdiv 16 4) |
||||
'(4 4 4 4))) |
||||
(should |
||||
(equal (avy-subdiv 17 4) |
||||
'(4 4 4 5))) |
||||
(should |
||||
(equal (avy-subdiv 27 4) |
||||
'(4 4 4 15))) |
||||
(should |
||||
(equal (avy-subdiv 50 4) |
||||
'(4 14 16 16))) |
||||
(should |
||||
(equal (avy-subdiv 65 4) |
||||
'(16 16 16 17)))) |
||||
|
||||
(ert-deftest avy-read () |
||||
(should |
||||
(equal |
||||
(avy-read '(0 1 2 3 4 5 6 7 8 9 10) |
||||
'(?a ?s ?d ?f ?g ?h ?j ?k ?l)) |
||||
'((97 . 0) |
||||
(115 . 1) |
||||
(100 . 2) |
||||
(102 . 3) |
||||
(103 . 4) |
||||
(104 . 5) |
||||
(106 . 6) |
||||
(107 . 7) |
||||
(108 (97 . 8) |
||||
(115 . 9) |
||||
(100 . 10)))))) |
||||
@ -0,0 +1,82 @@ |
||||
;;; avy.el --- set-based completion -*- lexical-binding: t -*- |
||||
|
||||
;; Copyright (C) 2015 Oleh Krehel |
||||
|
||||
;; Author: Oleh Krehel <ohwoeowho@gmail.com> |
||||
;; Version: 0.1.0 |
||||
;; Keywords: completion |
||||
|
||||
;; This file is not part of GNU Emacs |
||||
|
||||
;; This file is free software; you can redistribute it and/or modify |
||||
;; it under the terms of the GNU General Public License as published by |
||||
;; the Free Software Foundation; either version 3, or (at your option) |
||||
;; any later version. |
||||
|
||||
;; This program is distributed in the hope that it will be useful, |
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
;; GNU General Public License for more details. |
||||
|
||||
;; For a full copy of the GNU General Public License |
||||
;; see <http://www.gnu.org/licenses/>. |
||||
|
||||
;;; Commentary: |
||||
;; |
||||
;; Given a LIST and KEYS, `avy-read' will build a balanced tree of |
||||
;; degree B, where B is the length of KEYS. |
||||
;; |
||||
;; The corresponding member of KEYS is placed in each internal node of |
||||
;; the tree. The leafs are the members of LIST. They can be obtained |
||||
;; in the original order by traversing the tree depth-first. |
||||
|
||||
;;; Code: |
||||
|
||||
(defmacro avy-multipop (lst n) |
||||
"Remove LST's first N elements and return them." |
||||
`(if (<= (length ,lst) ,n) |
||||
(prog1 ,lst |
||||
(setq ,lst nil)) |
||||
(prog1 ,lst |
||||
(setcdr |
||||
(nthcdr (1- ,n) (prog1 ,lst (setq ,lst (nthcdr ,n ,lst)))) |
||||
nil)))) |
||||
|
||||
(defun avy-read (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) |
||||
(cl-pairlis keys ls) |
||||
(let ((ks (copy-sequence keys)) |
||||
res) |
||||
(dolist (s (avy-subdiv ln len)) |
||||
(push (cons (pop ks) |
||||
(if (eq s 1) |
||||
(pop ls) |
||||
(rd (avy-multipop ls s)))) |
||||
res)) |
||||
(nreverse res)))))) |
||||
(rd lst)))) |
||||
|
||||
(defun avy-subdiv (n b) |
||||
"Distribute N in B terms in a balanced way." |
||||
(let* ((p (1- (floor (log n b)))) |
||||
(x1 (expt b p)) |
||||
(x2 (* b x1)) |
||||
(delta (- n x2)) |
||||
(n2 (/ delta (- x2 x1))) |
||||
(n1 (- b n2 1))) |
||||
(append |
||||
(make-list n1 x1) |
||||
(list |
||||
(- n (* n1 x1) (* n2 x2))) |
||||
(make-list n2 x2)))) |
||||
|
||||
(provide 'avy) |
||||
|
||||
;;; avy.el ends here |
||||
Loading…
Reference in new issue