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

Opening paren in first column of docstring results in incorrect highlighting, paredit failures #183

Closed
cemerick opened this issue Oct 24, 2013 · 9 comments

Comments

@cemerick
Copy link
Contributor

A snippet that will provoke the problems:

(defn foo
  "doc
(example)"
  [x]
  (repeat 20 [:x x]))

The opening paren in the docstring being in the first column causes (AFAICT) later expressions to be incorrectly highlighted. Sometimes it's subtle (e.g. affecting only the color of later brackets or parens), but sometimes it's not, e.g. here, where entire expressions are highlighted as if they were strings:

https://pbs.twimg.com/media/BW75CHSCMAAoUun.png

Further, some paredit commands will fail following the docstring containing the paren, e.g. "Invalid context for command paredit-wrap-sexp", splice will fail and report "unspliceable string".

Just moving the opening paren in the docstring fixes the problems.

Thanks to @tomfaulhaber for noticing the correlation with the open paren's column position.

@technomancy
Copy link
Contributor

This is actually Emacs warning you about a bug in its own parser--zero-column parens in strings need to be escaped for the built-in forward-sexp etc stuff to work. I don't think it's feasible to fix this in clojure-mode unfortunately.

@ska2342
Copy link

ska2342 commented Oct 24, 2013

If I am not mistaken, this is actually a duplicate of #140 which might be closed as well, if it's not fixable in clojure-mode.

@cemerick
Copy link
Contributor Author

I asked around about this, and there seems to be a reasonable workaround:

(setq open-paren-in-column-0-is-defun-start nil)

Been happy with this in my init.el for a day, and messed around in some very large files/forms to see if there was any painful effect on perf, or other ill effects. It's all good AFAICT. It seems to be a global setting, so it may not be a reasonable default for clojure-mode to set, although perhaps there's some hook trickery that can toggle it as one enters and leaves different types of files? Anyway, it seems to be a good workaround for me.

@tsdh
Copy link
Contributor

tsdh commented Oct 28, 2013

@cemerick You could do (set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil) in the clojure-mode major mode function.

@cemerick
Copy link
Contributor Author

@tsdh You mean, to make the setting local to Clojure buffers? I think I know what you mean by "major mode function". :-P That fact makes me not want to propose your suggestion as a change to clojure-mode, in addition to the default being what it's been forever. If someone with more understanding of emacs/emacs-lisp mode innards has some confidence that a buffer-local change is a good new default for clojure-mode, that'd be great.

@technomancy
Copy link
Contributor

I thought the above snippet would just disable the warning, but it turns out it actually fixes the undesirable behaviour entirely. Bizzare default, but par for the course with Emacs. Looks like a great change to me; thanks @tsdh.

@tsdh
Copy link
Contributor

tsdh commented Oct 29, 2013

@cemerick with "major mode function", I mean the function clojure-mode, and of course we may make open-paren-in-column-0-is-defun-start buffer-local there to have a different value than elisp mode without having to twiddle the global value.

@cemerick
Copy link
Contributor Author

@tsdh Yeah, makes sense. I'll put together a PR to do this, and we'll see what the powers-that-be say. :-)

cemerick added a commit to cemerick/clojure-mode that referenced this issue Oct 30, 2013
@cemerick
Copy link
Contributor Author

gh-187 is the PR. I'll try to stop being so daft and over-cautious now. Thanks, @tsdh.

technomancy added a commit that referenced this issue Oct 30, 2013
set open-paren-in-column-0-is-defun-start to nil buffer-local in clojure-mode, fixes gh-183, fixes gh-140
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

No branches or pull requests

4 participants