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

cider-repl-clear-buffer stops working #1252

Closed
dagda1 opened this issue Aug 11, 2015 · 21 comments
Closed

cider-repl-clear-buffer stops working #1252

dagda1 opened this issue Aug 11, 2015 · 21 comments
Labels

Comments

@dagda1
Copy link

dagda1 commented Aug 11, 2015

My projects.clj looks like this:

{:user {
        :dependencies [[com.cemerick/piggieback "0.2.1"]
                       [org.clojure/tools.nrepl "0.2.10"]]
        :plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]]
        }}

I'm pretty new to clojure and cider but when I have the code in one window and cider-repl running in the other, it is nice to be able to clear the repl buffer with C-c M-o but C-c M-o stops working after I have executed it once and the buffer has been cleared.

If I select cider-repl-clear-buffer from M-x I can see the error message:

Wrong type argument: integer-or-marker-p nil

The following stack trace in the *Messages* buffer

Loading /Users/paulcowan/projects/scratch/src/scratch/core.clj...
=> nil
Loading /Users/paulcowan/projects/scratch/src/scratch/core.clj...
=> nil
Quit
call-interactively: Wrong type argument: integer-or-marker-p, nil
user-error: Minibuffer window is not active
call-interactively: Wrong type argument: integer-or-marker-p, nil
Auto-saving...done
call-interactively: Wrong type argument: integer-or-marker-p, nilInvalid face attribute :foreground nil
Invalid face attribute :foreground nil [117 times]

So all I do is

  1. cider-jack-in
  2. Write some code and C-c C-k to execute it.
  3. C-c M-o and the buffer clears
  4. Write some code and C-c C-k to execute it.
  5. hit C-c M-o again and cider-repl-clear-buffer no longer works.

If nobody else is experiencing this error, I wonder if my workflow of using C-c C-k is normal?

@Malabarba
Copy link
Member

Do M-x toggle-debug-on-error, and then reproduce this error.
You'll get a proper backtrace which you can paste here to give us more information.

@dagda1
Copy link
Author

dagda1 commented Aug 12, 2015

Here is the backtrace:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
cider-repl-clear-buffer()
call-interactively(cider-repl-clear-buffer record nil)
command-execute(cider-repl-clear-buffer record)
execute-extended-command(nil "cider-repl-clear-buffer")
smex-read-and-run(("toggle-debug-on-error" "cider-repl-clear-buffer" "cider-jack-in" "list-packages" "magit-status" "ag-project" "enable-paredit-mode" "paredit-mode" "blink-cursor-mode" "global-company-mode" "ag-kill-buffers" "disable-paredit-mode" "kill-other-buffers" "load-file" "kill-some-buffers" "cider-quit" "package-install" "auto-save-mode" "eval-buffer" "cider-restart" "cider-version" "visit-tags-table" "magit-process-kill" "sdb" "ag-mode" "find-library" "minitest-mode" "revert-buffer" "ag/kill-process" "cider-interrupt" "elm-indent-mode" "erc-notify-mode" "ag-project-dired" "cider-repl-kill-input" "package-list-packages" "projectile-invalidate-cache" "cider-repl-toggle-pretty-printing" "org-table-toggle-formula-debugger" "cider-clear-compilation-highlights" "ag" "cd" "5x5" "arp" "dbx" "dig" "erc" "ert" "eww" "ftp" "gdb" ...))
smex()
call-interactively(smex nil nil)
command-execute(smex)

@bbatsov
Copy link
Member

bbatsov commented Aug 12, 2015

If nobody else is experiencing this error, I wonder if my workflow of using C-c C-k is normal?

Yeah, that's OK. Personally, I don't use C-c C-k that often - usually I just re-evaluate the code I've actually changed. What's your cider version info?

@dagda1
Copy link
Author

dagda1 commented Aug 12, 2015

@bbatsov here is my version info:

; CIDER 0.10.0snapshot (package: 20150801.627) (Java 1.7.0_45, Clojure 1.6.0, nREPL 0.2.10)

Do you think it would be possible, if you could describe your workflow in a few words?

I think that would be very beneficial to me.

@Malabarba
Copy link
Member

My workflow is to just reload code I just changed by hitting C-M-x on it. But there's nothing wrong with using C-c C-k, a lot of people do that and I'm sure one of them would have noticed your issue.

It's clear that one of the repl markers is being set to nil for you, even though all of them should always be valid markers.

  1. Do you have anything in cider-repl-clear-buffer-hook?
  2. When you get this problem, which of the following vars is nil for you: cider-repl-prompt-start-mark, cider-repl-output-start, cider-repl-output-end, or cider-repl-input-start-mark?

@dagda1
Copy link
Author

dagda1 commented Aug 12, 2015

Is cider-repl-clear-buffer-hook a command? I don't have it available through M-x.

@Malabarba
Copy link
Member

No, it's a variable. Try to see it with C-h v. If you don't get anything, that's normal.

@dagda1
Copy link
Author

dagda1 commented Aug 12, 2015

So when I run c-h v for cider-repl-prompt-start-mark I get:

cider-repl-prompt-start-mark is a variable defined in `cider-repl.el'.
Its value is nil

  Automatically becomes buffer-local when set.

for cider-repl-output-start

cider-repl-output-start is a variable defined in `cider-repl.el'.
Its value is nil

  Automatically becomes buffer-local when set.

The same is true for cider-repl-output-end and cider-repl-input-start-mark.

@Malabarba
Copy link
Member

Did you do that inside the repl buffer?

@dagda1
Copy link
Author

dagda1 commented Aug 12, 2015

Ah right, my bad,

Here are the variables in the buffer.

cider-repl-prompt-start-mark outputs

cider-repl-prompt-start-mark is a variable defined in `cider-repl.el'.
Its value is #<marker at 93 in *cider-repl scratch*>
Local in buffer *cider-repl scratch*; global value is nil

  Automatically becomes buffer-local when set.

cider-repl-output-start outputs:

cider-repl-output-start is a variable defined in `cider-repl.el'.
Its value is #<marker at 92 in *cider-repl scratch*>
Local in buffer *cider-repl scratch*; global value is nil

  Automatically becomes buffer-local when set.

cider-repl-output-end outputs

cider-repl-output-end is a variable defined in `cider-repl.el'.
Its value is #<marker at 92 in *cider-repl scratch*>
Local in buffer *cider-repl scratch*; global value is nil

cider-repl-input-start-mark outputs

cider-repl-input-start-mark is a variable defined in `cider-repl.el'.
Its value is #<marker at 99 in *cider-repl scratch*>
Local in buffer *cider-repl scratch*; global value is nil

  Automatically becomes buffer-local when set.

cider-repl-clear-buffer-hook gives no match.

@Malabarba
Copy link
Member

Ok, one more question. :) Is that after reproducing the problem?

@dagda1
Copy link
Author

dagda1 commented Aug 12, 2015

I've captured the variables again after the problem:

cider-repl-prompt-start-mark outputs

cider-repl-prompt-start-mark is a variable defined in `cider-repl.el'.
Its value is #<marker at 1 in *cider-repl scratch*>
Local in buffer *cider-repl scratch*; global value is nil

  Automatically becomes buffer-local when set.

cider-repl-output-start outputs:

cider-repl-output-start is a variable defined in `cider-repl.el'.
Its value is #<marker at 1 in *cider-repl scratch*>
Local in buffer *cider-repl scratch*; global value is nil

  Automatically becomes buffer-local when set.

cider-repl-output-end outputs

cider-repl-output-end is a variable defined in `cider-repl.el'.
Its value is #<marker at 1 in *cider-repl scratch*>
Local in buffer *cider-repl scratch*; global value is nil

cider-repl-input-start-mark outputs

cider-repl-input-start-mark is a variable defined in `cider-repl.el'.
Its value is #<marker at 255 in *cider-repl scratch*>
Local in buffer *cider-repl scratch*; global value is nil

cider-repl-clear-buffer-hook gives no match.

@Malabarba
Copy link
Member

Alright. Then I think it's safe to say that I am clueless. :)

@dagda1
Copy link
Author

dagda1 commented Aug 12, 2015

Same thing happens even if I use C-M x.

cider-repl-clear-buffer is not a happy bunny for me anyway after the first execution irrespective of what proceeds it.

@expez
Copy link
Member

expez commented Aug 13, 2015

@dagda1 you might have to dig into edebug to debug this function yourself. Learning edebug takes around 5 minutes--it's incredibly easy to use--and it's well worth the trouble imo.

@Malabarba
Copy link
Member

@scottdw
Copy link
Contributor

scottdw commented Aug 13, 2015

Are you running cider-repl-clear-buffer from the file buffer or the repl buffer, @dagda1?

@scottdw
Copy link
Contributor

scottdw commented Aug 13, 2015

Nevermind, that doesn't seem to affect it. It appears that the first time some code is evaluated the output appears before repl prompt and after C-c M-o it appears after the prompt. Pressing Enter to get back the repl prompt makes cider-repl-clear-buffer work again.

@dagda1
Copy link
Author

dagda1 commented Aug 13, 2015

@scottdw absolutely, that works. If I press enter after each evaluation then the repl can be cleared each time.

@dagda1
Copy link
Author

dagda1 commented Aug 13, 2015

I'm curious as to why experienced users have not encountered this. Do they not use the cider-repl-clear-buffer command?

@expez expez added the bug label Aug 14, 2015
@expez
Copy link
Member

expez commented Aug 14, 2015

I'm curious as to why experienced users have not encountered this. Do they not use the cider-repl-clear-buffer command?

I only use it when the output in the buffer is causing trouble. e.g. when it contains unbalanced parens etc and smartparens is screaming at me.

Additionally, it's super unusual to have forms causing side-effects and emitting output to the repl as toplevel forms that get evaluated when calling C-c C-k.

Steps to reproduce

  1. Open a clj buffer and insert (println (+ 1 1))
  2. C-c C-k
  3. C-c M-o
  4. C-c C-k

expez pushed a commit that referenced this issue Aug 17, 2015
After running cider-repl-clear-buffer and then loading a file creating
output (e.g. because it contains println statements) the output would
appear in the wrong place, causing the prompt to disappear.

The problem was in the function responsible for putting POINT in the right
place before emitting evaluation results into the repl buffer.  When the
prompt was the first line in the buffer,
cider-repl--end-of-line-before-input-start didn't move point at all.
There's now a special case in place to handle this situation.

I initially considered solving this problem by making sure that the prompt
wasn't the first line in the buffer, after noticing that he banner was
being deleted by cider-repl-clear-buffer.  While I think the banner should
be preserved by this function, the banner itself is optional so this was a
non-solution.
expez pushed a commit that referenced this issue Aug 17, 2015
After running cider-repl-clear-buffer and then loading a file creating
output (e.g. because it contains println statements) the output would
appear in the wrong place, causing the prompt to disappear.

The problem was in the function responsible for putting POINT in the right
place before emitting evaluation results into the repl buffer.  When the
prompt was the first line in the buffer,
cider-repl--end-of-line-before-input-start didn't move point at all.
There's now a special case in place to handle this situation.

I initially considered solving this problem by making sure that the prompt
wasn't the first line in the buffer, after noticing that he banner was
being deleted by cider-repl-clear-buffer.  While I think the banner should
be preserved by this function, the banner itself is optional so this was a
non-solution.
@expez expez closed this as completed in 2cccb45 Aug 17, 2015
bbatsov added a commit that referenced this issue Aug 17, 2015
[Fix #1252] Fix breakage in cider-repl-clear-buffer
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

5 participants