Skip to content
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

sp-unwrap-sexp throws wrong-type-argument nil in minibuffer #1158

Open
zalky opened this issue May 2, 2023 · 0 comments
Open

sp-unwrap-sexp throws wrong-type-argument nil in minibuffer #1158

zalky opened this issue May 2, 2023 · 0 comments

Comments

@zalky
Copy link

zalky commented May 2, 2023

Expected behavior

When working with list expressions in the minibuffer, if I have a set of parenthesis (), and the cursor is inside the expression, sp-unwrap-sexp should unwrap the expression.

Actual behavior

sp-unwrap-sexp throws a (wrong-type-argument stringp nil)

Steps to reproduce the problem

  1. Eval an elisp expression in the minibuffer
  2. Enter an empty expression ()
  3. Move the cursor inside the parenthesis
  4. Try sp-unwrap-sexp

Backtraces if necessary (M-x toggle-debug-on-error)

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match("^[\n\11 ]+\\'" nil nil)
  string-match-p("^[\n\11 ]+\\'" nil)
  (if (string-match-p "^[\n\11 ]+\\'" (thing-at-point 'line)) (progn (let ((b (bounds-of-thing-at-point 'line))) (delete-region (car b) (cdr b)))))
  (save-excursion (goto-char new-end) (if (string-match-p "^[\n\11 ]+\\'" (thing-at-point 'line)) (progn (let ((b (bounds-of-thing-at-point 'line))) (delete-region (car b) (cdr b))))) (setq indent-to (point)) (goto-char new-start) (if (string-match-p "^[\n\11 ]+\\'" (thing-at-point 'line)) (progn (let ((b (bounds-of-thing-at-point 'line))) (delete-region (car b) (cdr b))))) (setq indent-from (point)))
  (let ((new-start (let ((struct sexp)) (- (plist-get struct :beg) (length (plist-get struct :prefix))))) (new-end (let ((struct sexp)) (- (- (plist-get struct :end) (length (plist-get struct :cl))) (length (plist-get struct :op)) (length (plist-get struct :prefix))))) indent-from indent-to) (save-excursion (goto-char new-end) (if (string-match-p "^[\n\11 ]+\\'" (thing-at-point 'line)) (progn (let ((b (bounds-of-thing-at-point ...))) (delete-region (car b) (cdr b))))) (setq indent-to (point)) (goto-char new-start) (if (string-match-p "^[\n\11 ]+\\'" (thing-at-point 'line)) (progn (let ((b (bounds-of-thing-at-point ...))) (delete-region (car b) (cdr b))))) (setq indent-from (point))) (if (memq major-mode sp-no-reindent-after-kill-modes) nil (let ((c (current-column)) (i (sp--current-indentation))) (sp--indent-region indent-from indent-to) (sp--back-to-indentation c i))))
  (if no-cleanup nil (let ((new-start (let ((struct sexp)) (- (plist-get struct :beg) (length (plist-get struct :prefix))))) (new-end (let ((struct sexp)) (- (- (plist-get struct :end) (length ...)) (length (plist-get struct :op)) (length (plist-get struct :prefix))))) indent-from indent-to) (save-excursion (goto-char new-end) (if (string-match-p "^[\n\11 ]+\\'" (thing-at-point 'line)) (progn (let ((b ...)) (delete-region (car b) (cdr b))))) (setq indent-to (point)) (goto-char new-start) (if (string-match-p "^[\n\11 ]+\\'" (thing-at-point 'line)) (progn (let ((b ...)) (delete-region (car b) (cdr b))))) (setq indent-from (point))) (if (memq major-mode sp-no-reindent-after-kill-modes) nil (let ((c (current-column)) (i (sp--current-indentation))) (sp--indent-region indent-from indent-to) (sp--back-to-indentation c i)))))
  sp--unwrap-sexp((:beg 7 :end 9 :op "(" :cl ")" :prefix "" :suffix ""))
  (progn (sp--unwrap-sexp ok))
  (if ok (progn (sp--unwrap-sexp ok)))
  (let ((ok (save-excursion (sp-forward-sexp arg)))) (if ok (progn (sp--unwrap-sexp ok))) ok)
  (let ((sp-navigate-consider-symbols nil)) (let ((ok (save-excursion (sp-forward-sexp arg)))) (if ok (progn (sp--unwrap-sexp ok))) ok))
  sp-unwrap-sexp(1)
  funcall-interactively(sp-unwrap-sexp 1)
  call-interactively(sp-unwrap-sexp nil nil)
  command-execute(sp-unwrap-sexp)

Environment & version information

In recent enough smartparens you can call M-x sp-describe-system to generate this report. Please fill manually what we could not detect automatically. Edit the output as you see fit to protect your privacy.

  • smartparens version: 20230225.1026
  • Active major-mode: minibuffer
  • Emacs version (M-x emacs-version): GNU Emacs 28.2 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00 Version 12.0.1 (Build 21A559)) of 2022-09-12
  • Spacemacs/Evil/Other starterkit (specify which)/Vanilla: Vanilla
  • OS: Mac OS X

Lead and Potential Resolution

I think that thing-at-point is returning nil in the minibuffer for whatever reason in sp--unwrap-sexp on these lines.

I have no idea if this is expected behaviour for thing-at-point in this context. If it is, then there probably needs to be a check like the following:

        (if-let ((thing (thing-at-point 'line))
                 ((string-match-p "^[\n\t ]+\\'" thing))
                 (b (bounds-of-thing-at-point 'line)))
            (delete-region (car b) (cdr b)))

While this eliminates the error me, if thing-at-point is not supposed to return nil in this situation, then this might not be the right solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

No branches or pull requests

1 participant