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

Fix occasional error when indenting namespace-qualified function #1475

Merged
merged 1 commit into from
Dec 19, 2015

Conversation

rfkm
Copy link
Contributor

@rfkm rfkm commented Dec 19, 2015

I got (args-out-of-range -1 -1) error when I tried to indent a namespace-qualified function call in a CLJS buffer which is associated with browser REPL connection.

Stacktrace:

Debugger entered--Lisp error: (args-out-of-range -1 -1)
  replace-match(#("foo" 0 3 (face font-lock-type-face fontified t)) t t #("foo/bar" 0 3 (fontified t face font-lock-type-face) 3 4 (fontified t face default) 4 7 (fontified t)) 1)
  cider--get-symbol-indent(#("foo/bar" 0 3 (fontified t face font-lock-type-face) 3 4 (fontified t face default) 4 7 (fontified t)))
  clojure--get-indent-method(#("foo/bar" 0 3 (fontified t face font-lock-type-face) 3 4 (fontified t face default) 4 7 (fontified t)))
  clojure--find-indent-spec-backtracking()
  clojure--find-indent-spec()
  clojure-indent-function(142 (1 133 134 nil nil nil 0 nil nil (133)))
  calculate-lisp-indent()
  lisp-indent-line()
  clojure-indent-line()
  indent-according-to-mode()
  electric-indent-post-self-insert-function()
  self-insert-command(1)
  newline(nil 1)
  call-interactively(newline nil nil)
  command-execute(newline)

I haven't found minimal steps to reproduce it yet, but the cause is clear.
It is because cider-resolve-alias is called between string-match and replace-match in cider--get-symbol-indent 1.
cider-resolve-alias can also call string-match 2 , so the match data can be replaced with another one.

This PR should fix it by backing up the match data with save-match-data macro.

[1]

cider/cider-mode.el

Lines 291 to 292 in 491d5e5

(when (string-match cider-resolve--prefix-regexp symbol-name)
(when-let ((sym (intern-soft (replace-match (cider-resolve-alias ns (match-string 1 symbol-name))

[2] E.g. cider-resolve-alias -> cider-resolve--get-in -> cider-current-connection -> cider-find-connection-buffer-for-project-directory -> file-truename -> string-match

bbatsov added a commit that referenced this pull request Dec 19, 2015
Fix occasional error when indenting namespace-qualified function
@bbatsov bbatsov merged commit ba6af51 into clojure-emacs:master Dec 19, 2015
@bbatsov
Copy link
Member

bbatsov commented Dec 19, 2015

👍 The fix looks good. We should check the codebase for other places where we might run into the same issue.

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

Successfully merging this pull request may close these issues.

2 participants