SPC/DEL navigation works
This commit is contained in:
@@ -42,6 +42,15 @@ Currently, we take care to only search from the point to the beg/end of the wind
|
|||||||
result))))
|
result))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
** TODO Avoid leaping to target directly under point
|
||||||
|
|
||||||
|
Currently, if the point is on ~a~, that very ~ab~ pair will be given as a potential target.
|
||||||
|
|
||||||
|
#+begin_src
|
||||||
|
↓
|
||||||
|
ab
|
||||||
|
#+end_src
|
||||||
|
|
||||||
** TODO Leap any direction
|
** TODO Leap any direction
|
||||||
|
|
||||||
** TODO Cleanup w/ ~pre-command-hook~
|
** TODO Cleanup w/ ~pre-command-hook~
|
||||||
|
|||||||
88
evil-leap.el
88
evil-leap.el
@@ -137,35 +137,36 @@ spice!
|
|||||||
|
|
||||||
Spice: If an entry with key LABEL already exists in LABELED-TARGETS, a fresh
|
Spice: If an entry with key LABEL already exists in LABELED-TARGETS, a fresh
|
||||||
hash table will be created and inserted into LABELED-TARGETS under key '?\\s'.
|
hash table will be created and inserted into LABELED-TARGETS under key '?\\s'.
|
||||||
This fresh hash table will itself have a key '?\\b' pointing back to
|
This fresh hash table will itself have a key '?\\d' pointing back to
|
||||||
LABELED-TARGETS. If this '?\\s' entry already exists in LABELED-TARGETS, it
|
LABELED-TARGETS. If this '?\\s' entry already exists in LABELED-TARGETS, it
|
||||||
will instead try to insert it into /that/ hash table, continuing until a
|
will instead try to insert it into /that/ hash table, continuing until a
|
||||||
suitable home is found.
|
suitable home is found.
|
||||||
|
|
||||||
|
;; Spice: Since the expected appearance of label overlays is so tightly coupled
|
||||||
|
;; with the above logic, the overlays are also created by this routine. Sorry!
|
||||||
|
|
||||||
This all implies that important parts of evil-leap will enter the eldritch world
|
This all implies that important parts of evil-leap will enter the eldritch world
|
||||||
of Undefined Behaviour, should either `evil-leap-safe-labels' or
|
of Undefined Behaviour, should either `evil-leap-safe-labels' or
|
||||||
`evil-leap-labels' contain '?\\s' or '?\\b'."
|
`evil-leap-labels' contain '?\\s' or '?\\d'."
|
||||||
;; If the label is already present in `labeled-targets', we insert it into the
|
;; If the label is already present in `labeled-targets', we insert it into the
|
||||||
;; "next" map at key '?\s'.
|
;; "next map" at key '?\s'.
|
||||||
(let ((existing-targets (ht-get labeled-targets label target)))
|
(if (ht-get labeled-targets label)
|
||||||
;; REVIEW: This is terribly inefficient to be ran in a tight loop (i.e.
|
;; If labeled-targets[?\s] (the "next map") exists, ...
|
||||||
;; `evil-leap--label-targets').
|
(if-let ((next-labeled-targets (ht-get labeled-targets ?\s)))
|
||||||
(if (<= (length evil-leap-labels) (length existing-targets))
|
;; ... recurse into it. ...
|
||||||
;; If labeled-targets[?\s] (the "next map") exists, ...
|
(evil-leap--add-to-labeled-targets!
|
||||||
(if-let ((next-labeled-targets (ht-get labeled-targets ?\s)))
|
next-labeled-targets label target)
|
||||||
;; ... recurse into it. ...
|
;; ... If it doesn't, create a new hash table, stored in
|
||||||
(evil-leap--add-to-labeled-targets!
|
;; `labeled-targets' at key '?\s', containing nought but a back-link key
|
||||||
next-labeled-targets label target)
|
;; ('?\d')[1], and the given label/target pair[2].
|
||||||
;; ... If it doesn't, create a new hash table, stored in
|
(evil-leap--add-overlay-target! target label)
|
||||||
;; `labeled-targets' at key '?\s', containing nought but a back-link key
|
(ht-set! labeled-targets ?\s
|
||||||
;; ('?\b')[1], and the given label/target pair[2].
|
(ht (?\d labeled-targets) ; [1]
|
||||||
(print "here!")
|
(label target)))) ; [2]
|
||||||
(ht-set! labeled-targets ?\s
|
;; The label does not exist, meaning we needn't muck around with the next
|
||||||
(ht (?\b labeled-targets) ; [1]
|
;; map. Proceed normally with `ht-set!'!
|
||||||
(label (list target))))) ; [2]
|
(evil-leap--add-overlay-target! target label)
|
||||||
;; The label does not exist, meaning we needn't muck around with the next
|
(ht-set! labeled-targets label target)))
|
||||||
;; map. Proceed normally with `ht-set!'!
|
|
||||||
(ht-set! labeled-targets label target))))
|
|
||||||
|
|
||||||
(defun evil-leap--label-targets-safe (targets)
|
(defun evil-leap--label-targets-safe (targets)
|
||||||
"TODO returns a hash table mapping labels to targets"
|
"TODO returns a hash table mapping labels to targets"
|
||||||
@@ -179,7 +180,7 @@ of Undefined Behaviour, should either `evil-leap-safe-labels' or
|
|||||||
(ht-set! labeled-targets 'auto-jump (car targets))
|
(ht-set! labeled-targets 'auto-jump (car targets))
|
||||||
(dolist (target (cdr targets) labeled-targets)
|
(dolist (target (cdr targets) labeled-targets)
|
||||||
(let ((lbl (pop labels)))
|
(let ((lbl (pop labels)))
|
||||||
(evil-leap--add-overlay-target! target lbl)
|
;; (evil-leap--add-overlay-target! target lbl)
|
||||||
(evil-leap--add-to-labeled-targets! labeled-targets lbl target)))))
|
(evil-leap--add-to-labeled-targets! labeled-targets lbl target)))))
|
||||||
|
|
||||||
(defun evil-leap--label-targets-unsafe (targets)
|
(defun evil-leap--label-targets-unsafe (targets)
|
||||||
@@ -189,7 +190,7 @@ of Undefined Behaviour, should either `evil-leap-safe-labels' or
|
|||||||
(labeled-targets (ht-create 'eq)))
|
(labeled-targets (ht-create 'eq)))
|
||||||
(dolist (target targets labeled-targets)
|
(dolist (target targets labeled-targets)
|
||||||
(let ((lbl (pop labels)))
|
(let ((lbl (pop labels)))
|
||||||
(evil-leap--add-overlay-target! target lbl)
|
;; (evil-leap--add-overlay-target! target lbl)
|
||||||
(evil-leap--add-to-labeled-targets! labeled-targets lbl target)))))
|
(evil-leap--add-to-labeled-targets! labeled-targets lbl target)))))
|
||||||
|
|
||||||
(defun evil-leap--label-targets (targets)
|
(defun evil-leap--label-targets (targets)
|
||||||
@@ -254,21 +255,29 @@ associated labels."
|
|||||||
- read a key from the user;
|
- read a key from the user;
|
||||||
- if the key corresponds to a label, jump to it;
|
- if the key corresponds to a label, jump to it;
|
||||||
- otherwise, let the input `fall through,' as if Leap were never here."
|
- otherwise, let the input `fall through,' as if Leap were never here."
|
||||||
(progn
|
;; REVIEW: Should the return value of `evil-leap-action' be returned by us?
|
||||||
;; REVIEW: Should the return value of `evil-leap-action' be returned by us?
|
;; (with-output-to-temp-buffer (format "*select - %s*" (current-time))
|
||||||
(evil-leap--try-auto-jump labeled-targets)
|
;; (pp labeled-targets))
|
||||||
(let ((given-key (evil-read-key)))
|
(evil-leap--try-auto-jump labeled-targets)
|
||||||
(if-let ((selected-target (ht-get labeled-targets given-key)))
|
(let ((given-key (evil-read-key)))
|
||||||
(funcall evil-leap-action selected-target)
|
(if-let ((selected-target (ht-get labeled-targets given-key)))
|
||||||
;; If we are given a key that does not correspond to any label, we let
|
;; '?\s' and '?\d' are special targets that lead to alternative sets
|
||||||
;; it 'fall through' to give it a proper run through Emacs' command
|
;; of labeled targets; if we find another hash table, select from that
|
||||||
;; loop. We do this as a formality in the general case, but it is
|
;; one instead.
|
||||||
;; essential to the idea behind auto-jump.
|
(if (ht-p selected-target)
|
||||||
|
;; TODO: Overlays should be updated here.
|
||||||
|
(progn (print "space or del!")
|
||||||
|
(evil-leap-select-from-labeled-targets selected-target))
|
||||||
|
(funcall evil-leap-action selected-target))
|
||||||
|
;; If we are given a key that does not correspond to any label, we let
|
||||||
|
;; it 'fall through' to give it a proper run through Emacs' command
|
||||||
|
;; loop. We do this as a formality in the general case, but it is
|
||||||
|
;; essential to the idea behind auto-jump.
|
||||||
|
|
||||||
;; REVIEW: Should the passthrough behaviour be configurable in the
|
;; REVIEW: Should the passthrough behaviour be configurable in the
|
||||||
;; non-auto-jump case?
|
;; non-auto-jump case?
|
||||||
(progn (push given-key unread-command-events)
|
(progn (push given-key unread-command-events)
|
||||||
nil)))))
|
nil))))
|
||||||
|
|
||||||
|
|
||||||
; Labels
|
; Labels
|
||||||
@@ -289,7 +298,7 @@ with key SECOND-CHAR."
|
|||||||
(ht-each
|
(ht-each
|
||||||
(lambda (_label target)
|
(lambda (_label target)
|
||||||
;; 1. A value in `labeled-targets' isn't always a target (e.g. entries
|
;; 1. A value in `labeled-targets' isn't always a target (e.g. entries
|
||||||
;; at '?\s' and '?\b').
|
;; at '?\s' and '?\d').
|
||||||
;; 2. If a target is an auto-jump candidate, its `overlay' slot is nil.
|
;; 2. If a target is an auto-jump candidate, its `overlay' slot is nil.
|
||||||
(when-let ((overlay (and (evil-leap-target-p target)
|
(when-let ((overlay (and (evil-leap-target-p target)
|
||||||
(evil-leap-target-overlay target))))
|
(evil-leap-target-overlay target))))
|
||||||
@@ -372,7 +381,6 @@ Keyword arguments
|
|||||||
(second-char (evil-read-key))
|
(second-char (evil-read-key))
|
||||||
(_ (evil-leap--unlabel-other-branches second-char branches))
|
(_ (evil-leap--unlabel-other-branches second-char branches))
|
||||||
(labeled-targets (ht-get branches second-char)))
|
(labeled-targets (ht-get branches second-char)))
|
||||||
(pp labeled-targets)
|
|
||||||
(evil-leap-select-from-labeled-targets labeled-targets))
|
(evil-leap-select-from-labeled-targets labeled-targets))
|
||||||
;; TODO: would it be faster to go through `labeled-targets' and unlabel them
|
;; TODO: would it be faster to go through `labeled-targets' and unlabel them
|
||||||
;; ourselves?
|
;; ourselves?
|
||||||
|
|||||||
Reference in New Issue
Block a user