<commit_before>;;; feature/jump/autoload.el -*- lexical-binding: t; -*-

(defvar +jump--rg-installed-p (executable-find "rg"))
(defvar +jump--ag-installed-p (executable-find "ag"))

(defun +jump-to (prop identifier &optional other-window)
  (with-selected-window
      (if other-window
          (save-excursion (other-window 1) (selected-window))
        (selected-window))
    (let ((fn (plist-get +jump-current-functions prop)))
      (if (commandp fn)
          (call-interactively fn)
        (funcall fn identifier)))))

;;;###autoload
(defun +jump/definition (identifier &optional other-window)
  "Jump to the definition of the symbol at point.

Tries xref and falls back to `dumb-jump', then rg/ag, then
`evil-goto-definition' (if evil is active)."
  (interactive
   (list (thing-at-point 'symbol t)
         current-prefix-arg))
  (cond ((null identifier)
         (user-error "Nothing under point"))

        ((plist-member +jump-current-functions :definition)
         (+jump-to :definition identifier))

        ((ignore-errors (if other-window
                            (xref-find-definitions-other-window identifier)
                          (xref-find-definitions identifier))
                        t))

        ((and (require 'dumb-jump nil t)
              ;; dumb-jump doesn't tell us if it succeeded or not
              (let ((old-fn-sym (make-symbol "old-fn"))
                    successful)
                (cl-letf ((old-fn-sym (symbol-function 'dumb-jump-get-results))
                          ((symbol-function 'dumb-jump-get-results)
                           (lambda (&optional prompt)
                             (let* ((plist (funcall old-fn-sym prompt))
                                    (results (plist-get plist :results)))
                               (when (and results (> (length results) 0))
                                 (setq successful t))<commit_msg>Fix dumb-jump integration for +jump/definition, take 2 #227<commit_after>;;; feature/jump/autoload.el -*- lexical-binding: t; -*-

(defvar +jump--rg-installed-p (executable-find "rg"))
(defvar +jump--ag-installed-p (executable-find "ag"))

(defun +jump-to (prop identifier &optional other-window)
  (with-selected-window
      (if other-window
          (save-excursion (other-window 1) (selected-window))
        (selected-window))
    (let ((fn (plist-get +jump-current-functions prop)))
      (if (commandp fn)
          (call-interactively fn)
        (funcall fn identifier)))))

;;;###autoload
(defun +jump/definition (identifier &optional other-window)
  "Jump to the definition of the symbol at point.

Tries xref and falls back to `dumb-jump', then rg/ag, then
`evil-goto-definition' (if evil is active)."
  (interactive
   (list (thing-at-point 'symbol t)
         current-prefix-arg))
  (cond ((null identifier)
         (user-error "Nothing under point"))

        ((plist-member +jump-current-functions :definition)
         (+jump-to :definition identifier))

        ((ignore-errors (if other-window
                            (xref-find-definitions-other-window identifier)
                          (xref-find-definitions identifier))
                        t))

        ((and (require 'dumb-jump nil t)
              ;; dumb-jump doesn't tell us if it succeeded or not
              (let ((old-fn (symbol-function 'dumb-jump-get-results))
                    successful)
                (cl-letf (((symbol-function 'dumb-jump-get-results)
                           (lambda (&optional prompt)
                             (let* ((plist (funcall old-fn prompt))
                                    (results (plist-get plist :results)))
                               (when (and results (> (length results) 0))
                                 (setq successful t))
{'fraction_non_alphanumeric': 0.12909186906019007, 'fraction_numerical': 0.0021119324181626186, 'mean_word_length': 1.8990053557765876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4212655', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1042, 'n_words': 287}