8000 ivy-avy fails with ' Wrong type argument: number-or-marker-p, nil' · Issue #3074 · abo-abo/swiper · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ivy-avy fails with ' Wrong type argument: number-or-marker-p, nil' #3074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
avik-of-omne opened this issue May 18, 2025 · 4 comments
Closed
Labels

Comments

@avik-of-omne
Copy link

when ivy-avy is called, I see that ivy-call calls swiper--action with a plain string (the line of text that was selected with the avy key). Subsequently swiper--line-number fails, since the string has no text property (get-text-property fails on the input string).

@basil-conto
Copy link
Collaborator

Please provide more details:

  • How/when/where are you calling ivy-avy?
  • What is the exact sequence of keys/commands that you invoke?
  • If you M-x toggle-debug-on-error RET before reproducing the error, do you get a backtrace that you can share here?
  • Are you able to reproduce the error starting from emacs -Q or make plain, i.e. without other parts of your user-init-file configuration?
  • What is your M-x emacs-version RET or, even better, M-x report-emacs-bug RET output?
  • What version of Ivy and Swiper are you using? If you've installed them with the built-in package manager, you can look at the name of the directory where the packages are installed:
    1. M-x find-library RET ivy RET C-x C-j
    2. M-x find-library RET swiper RET C-x C-j

I am unable to reproduce an error involving swiper or swiper-isearch and ivy-avy. Here is what I'm trying:

  1. make plain
  2. C-x C-f ivy.el RET
  3. M-x swiper RET foo C-' f
  4. M-x swiper-isearch RET foo C-' l k
M-x report-emacs-bug RET excerpt
In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.18.4, Xaw3d scroll bars) of 2025-04-03 built on tais
Repository revision: 12b06992dfc944dcd4104a3ae1ce60285b349095
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101016
System Description: Debian GNU/Linux trixie/sid

Configured using:
 'configure 'CFLAGS=-Og -ggdb3' -C --prefix=/home/blc/.local
 --enable-checking=structs --without-native-compilation
 --with-file-notification --with-x-toolkit=lucid --with-x'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XAW3D XDBE XIM XINERAMA XINPUT2
XPM XRANDR LUCID ZLIB

Important settings:
  value of $LANG: en_IE.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Elisp/l

Minor modes in effect:
  counsel-mode: t
  ivy-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug lisp-mnt message yank-media puny rfc822
mml mml-sec epa derived epg rfc6068 epg-config gnus-util
text-property-search mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils vc-git diff-mode track-changes easy-mmode
vc-dispatcher color ffap thingatpt tramp rx trampver tramp-integration
files-x tramp-message tramp-compat shell pcomplete comint ansi-osc
parse-time iso8601 time-date format-spec ansi-color tramp-loaddefs dired
dired-loaddefs targets/plain ivy-avy avy ring finder-inf
0blayout-autoloads 0x0-autoloads 0xc-autoloads avy-autoloads
hydra-autoloads lv-autoloads info plz-autoloads request-autoloads
s-autoloads wgrep-autoloads two-column targets/elpa package browse-url
url url-proxy url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source eieio eieio-core cl-macs icons password-cache json subr-x
map byte-opt gv bytecomp byte-compile url-vars counsel xdg swiper cl-seq
cl-extra help-mode ivy ivy-faces colir cl-loaddefs cl-lib rmc iso-transl
tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
touch-screen tool-bar dnd fontset image regexp-opt fringe tabulated-list
replace newcomment text-mode lisp-mode prog-mode register page tab-bar
menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse
jit-lock font-lock syntax font-core term/tty-colors frame minibuffer
nadvice seq simple cl-generic indonesian philippine cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop
case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo x-toolkit xinput2 x multi-tty move-toolbar
make-network-process tty-child-frames emacs)

@basil-conto basil-conto added enhancement Suggestion to improve or extend existing behavior moreinfo Waiting for author to provide more information and removed enhancement Suggestion to improve or extend existing behavior labels May 18, 2025
@avik-of-omne
Copy link
Author

Thanks for your quick response!

This is the emacs version :
GNU Emacs 30.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30, cairo version 1.15.12) of 2025-05-16

This is the init file that I am starting with :
(require 'ivy)
(require 'ivy-avy)
(global-set-key (kbd "C-s") 'swiper)
(global-set-key (kbd "M-]") 'ivy-avy)

These are the entries for swiper and ivy in my .emacs.d :
ivy-0.15.1
ivy-0.15.1.signed
ivy-avy-0.15.1
ivy-avy-0.15.1.signed
ivy-explorer-0.3.2
ivy-explorer-0.3.2.signed
ivy-readme.txt

I set debug-on-entry to swiper--action, and got this stack trace :
Debugger entered--beginning evaluation of function call form:

  • (swiper--line-number x)
  • (1- (swiper--line-number x))
  • (let ((ln (1- (swiper--line-number x))) (re (ivy--regex ivy-text)) (case-fold-search (ivy--case-fold-p ivy-text))) (if (null x) (user-error "No candidates$
  • #f(lambda (x) [evil-ex-search-direction evil-ex-search-persistent-highlight evil-ex-search-pattern evil-search-module t] "Goto line X." (let ((ln (1- (swi$
  • apply(#f(lambda (x) [evil-ex-search-direction evil-ex-search-persistent-highlight evil-ex-search-pattern evil-search-module t] "Goto line X." (let ((ln (1$
  • swiper--action(" (global-set-key (kbd "C-s") 'swiper)")
    funcall(swiper--action " (global-set-key (kbd "C-s") 'swiper)")
    (if ivy-marked-candidates (ivy--call-marked action) (funcall action x))
    (unwind-protect (if ivy-marked-candidates (ivy--call-marked action) (funcall action x)) (ivy-recursive-restore))
    (prog1 (unwind-protect (if ivy-marked-candidates (ivy--call-marked action) (funcall action x)) (ivy-recursive-restore)) (if (or (eq ivy-exit 'done) (minib$
    (cond ((null action) current) (t (select-window (ivy--get-window ivy-last)) (set-buffer (let* ((cl-x ivy-last)) (progn (or (let* (...) (progn ...)) (signa$
    (let* ((action (if (functionp ivy-inhibit-action) ivy-inhibit-action (and (not ivy-inhibit-action) (ivy--get-action ivy-last)))) (current (let* ((cl-x ivy$
    ivy-call()
    (let* ((ivy-recursive-last (and (active-minibuffer-window) ivy-last)) (ivy--display-function (if (or ivy-recursive-last (not (window-minibuffer-p))) (prog$
    (progn (let ((init-fn (ivy-alist-setting ivy-init-fns-alist caller))) (if init-fn (progn (funcall init-fn)))) (if (equal overriding-local-map '(keymap)) ($
    (progn (let ((--cl-keys-- --cl-rest--)) (while --cl-keys-- (cond ((memq (car --cl-keys--) '(:predicate :require-match :initial-input :history :preselect :$
    (let* ((predicate (car (cdr (plist-member --cl-rest-- ':predicate)))) (require-match (car (cdr (plist-member --cl-rest-- ':require-match)))) (initial-inpu$
    ivy-read("Swiper: " (#(" (require 'ivy)" 0 1 (swiper-line-number 1 display "1 ")) #(" (require 'ivy-avy)" 0 1 (swiper-line-number 2 display "2 ")) #(" " 0$
    (setq res (ivy-read "Swiper: " candidates :initial-input initial-input :keymap swiper-map :preselect (if initial-input (cl-position-if #'(lambda (x) (<= ($
    (and (setq res (ivy-read "Swiper: " candidates :initial-input initial-input :keymap swiper-map :preselect (if initial-input (cl-position-if #'(lambda (x) $
    (unwind-protect (and (setq res (ivy-read "Swiper: " candidates :initial-input initial-input :keymap swiper-map :preselect (if initial-input (cl-position-i$
    (let ((preselect (if (or swiper-use-visual-line (null search-invisible)) (count-screen-lines (point-min) (save-excursion (beginning-of-visual-line) (point$
    (let ((candidates (swiper--candidates))) (swiper--init) (setq swiper-invocation-face (plist-get (text-properties-at (point)) 'face)) (let ((preselect (if $
    swiper()
    funcall-interactively(swiper)
    call-interactively(swiper nil nil)
    command-execute(swiper)

I evaluated 'x' on frame 0, and got this :
" (global-set-key (kbd "C-s") 'swiper)"

The key strokes I did were the following :
C-x C-f ~/tmp_emacs (this is the ad hoc .emacs file whose contents are listed above)
C-s g l (I get a swiper listing of the lines 4 and 5)
M-] (the keystroke that I have mapped to ivy-avy)
a (to go to the first match)

At this point I encounter :
Wrong type argument: number-or-marker-p, nil

Please let me know what else I can provide. And thanks again for your promptness.

@basil-conto
Copy link
Collaborator

Thanks for the details! With this I was able to reproduce the issue and realise what's going on and what I'd misunderstood in the OP.

The problem is that ivy-avy does not work with swiper, which is why swiper's keymap swiper-map overrides its binding C-' to swiper-avy instead:

(define-key map (kbd "C-'") #'swiper-avy)

Similarly swiper-isearch uses the keymap swiper-isearch-map which inherits this override from swiper-map:

swiper/swiper.el

Line 1630 in 2529a23

(set-keymap-parent map swiper-map)

By contrast ivy-avy.el binds ivy-avy to C-' in the default ivy-minibuffer-map keymap:

swiper/ivy-avy.el

Lines 111 to 112 in 2529a23

(unless (lookup-key ivy-minibuffer-map (kbd "C-'"))
(define-key ivy-minibuffer-map (kbd "C-'") 'ivy-avy))

That means that binding M-] to ivy-avy globally will not work reliably for all Ivy-based commands.

I suggest you adapt your configuration to something like the following instead:

;;; init.el --- my user-init-file -*- lexical-binding: t -*-
(autoload 'ivy-avy "ivy-avy" nil t)
(keymap-global-set "C-s" #'swiper)
(with-eval-after-load 'ivy
  (keymap-set ivy-minibuffer-map "M-]" #'ivy-avy))
(with-eval-after-load 'swiper
  (keymap-set swiper-map "M-]" #'swiper-avy))

@basil-conto basil-conto added support and removed moreinfo Waiting for author to provide more information labels May 19, 2025
@avik-of-omne
Copy link
Author

Yes, it works! Thanks.

basil-conto added a commit to basil-conto/swiper that referenced this issue May 26, 2025
Both counsel-ag and counsel-grep seem to work with the default C-'
binding of ivy-avy in ivy-minibuffer-map, so overriding it with
swiper-avy may be unnecessary (abo-abo#1711).

Meanwhile swiper works only with swiper-avy and not ivy-avy, so
remap the latter to the former in swiper-map.  This means users who
change the C-' binding in ivy-minibuffer-map will not have to also
repeat the same in swiper-map (abo-abo#1711, abo-abo#3074).  Keep C-' override for
backward compatibility.

* counsel.el (counsel-ag-map, counsel-grep-map): Remove swiper-avy
key binding.  Add docstring.
* swiper.el (swiper-map): Remap ivy-avy to swiper-avy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0