Skip to content

Commit

Permalink
Add racket-pdb-{next previous}-use commands
Browse files Browse the repository at this point in the history
  • Loading branch information
greghendershott committed Mar 27, 2023
1 parent fccae42 commit e368825
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions racket-pdb.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@

(defvar racket-pdb-control-c-hash-keymap
(racket--easy-keymap-define
`(
;; ("j" ,#'racket-pdb-next-definition)
;; ("k" ,#'racket-pdb-previous-definition)
;; ("n" ,#'racket-pdb-next-use)
;; ("p" ,#'racket-pdb-previous-use)
`(("n" ,#'racket-pdb-next-use)
("p" ,#'racket-pdb-previous-use)
("." ,#'xref-find-definitions)
("?" ,#'xref-find-references)
("r" ,#'racket-pdb-rename)
Expand Down Expand Up @@ -534,6 +531,45 @@ Uses pdb to query for sites among multiple files."
(_
(racket--doc prefix path racket--xp-binding-completions)))))

;;; Next/previous use

(defun racket--pdb-def-or-use-overlay-at (pos)
(seq-some (lambda (o)
(and (memq (overlay-get o 'face)
'(racket-xp-def-face racket-xp-use-face))
o))
(overlays-at pos)))

(defun racket-pdb-next-use ()
"When point is a highlighted definition or use, go to the next related site."
(interactive)
(when-let (o (racket--pdb-def-or-use-overlay-at (point)))
(let ((pos (overlay-end o)))
(catch 'exit
(while t
(setq pos (next-overlay-change pos))
(when (= pos (point-max))
(throw 'exit nil))
(when-let (o (racket--pdb-def-or-use-overlay-at pos))
(goto-char (overlay-start o))
(throw 'exit nil))
(incf pos))))))

(defun racket-pdb-previous-use ()
"When point is a highlighted definition or use, go to the previous related site."
(interactive)
(when-let (o (racket--pdb-def-or-use-overlay-at (point)))
(let ((pos (overlay-start o)))
(catch 'exit
(while t
(setq pos (previous-overlay-change pos))
(when (= pos (point-min))
(throw 'exit nil))
(when-let (o (racket--pdb-def-or-use-overlay-at pos))
(goto-char (overlay-start o))
(throw 'exit nil))
(decf pos))))))

;;; Mode line status

(defvar-local racket--pdb-mode-status nil)
Expand Down

0 comments on commit e368825

Please sign in to comment.