Fork me on GitHub

…copying a debugging question over from github to get more eyes on it. I have a function cider-pprint-eval-defun-to-comment. It’s a variant of cider-eval-defun-to-comment (C-c M-;) where the output is pretty-printed across multiple lines where necessary.


When the function is invoked via a keybinding it works as expected. When the function is invoked via M-x cider-pprint-eval-defun-to-comment the function completes without appearing to insert anything into the current buffer. However, as soon as I type any other character (including navigation like C-f, C-b) that’s when the inserted comment appears.


(☝️ I’m referring to the same cider pull request I mentioned last night….)


Anyone willing to help look into this?


I'm really new to elisp, but I'll look at it in a couple of hours. I want this patch to get it!


@fommil I know this is reaching way back in time, but did you ever find a solution to white-backgrounded stacktraces? "I have a dark theme (darcula) and when I get a stacktrace or test failure the default faces are all dark text on a white background." I'm experiencing the same issue.


> @ag resolve in the repl, could probably wrap it up in a cider command.


Indeed. That should be trivial to do.


@gonewest818 I can’t imagine what might be different. There’s no real difference between running a command with M-x or via a keybinding.


And I don’t see anything special happening in the wrapper command.


I think what you should do is instrumenting the command with the Elisp debugger (`C-u C-M-x` while inside its body) and just step through the code and see what’s going on.


annoyingly, bug doesn’t occur when I instrument the command with the debugger…


I think the issue is occurring in execute-extended-command in simple.el, in particular there seems to be a delay while it figures out a suggested shorthand for the new command: (`You can run the command 'cider-pprint-eval-defun-to-comment' with M-x -p-d-t RET`).


If I use the suggested shorthand M-x -p-d-t the bug doesn’t occur. Likewise if I just turn the feature off (setq suggest-key-bindings nil).


So I’m looking at the implementation in simple.el.


Interesting, there’s a “fixme” comment in the implementation that says “Can be slow. Cache it maybe?”


so… one workaround is if there is a valid keybinding for the function. In that case it just reminds you what the keybinding is, without trying to compute a shortened string.


That’s always the best approach to solving such problems.


> Does anyone know how to get emacs to respect cider indentation metadata? Would like to share formatting options across the team and it would be nice to have emacs editor support.


@tyler This only work when CIDER is running. There’s nothing special that you need to do - you just have to have this metadata attached to some definition and evaluate it.


> As far as I can tell cider-format-buffer dispatches to cljfmt, but even when I set up cljfmt in the project, cider doesn’t seem to do anything when I try to format using that command. When I run lein cljfmt fix it identifies the formatting errors correctly.


Well, what CIDER does is that it uses the cljfmt API to do the formatting. Not sure what you’d expect it to do.


I’ve been thinking recently about the usefulness of this, because it’s very annoying that results produced by clojure-mode + CIDER would normally differ from cljfmt. Maybe I’ll just remove this functionality at some point, as I doubt it’s useful to make people. When this was added I hope cljfmt would eventually add support for out metadata format as well.


> I thought the cljfmt readme had claimed emacs support for years


@gfredericks The README is referring just to this. That you can use this straight from CIDER, nothing more.


The only real advantage over running the external command is that using the API in CIDER is fast, as you don’t have to wait for a process to start every time. This command was intended to used as something you’d use as file save hook for instance.


But yeah, as I said, I think this didn’t turn out to be useful, so the chance of it being removed at this point is pretty big.