Noir and Lein under Eclipse - clojure

I am trying to use CCW + lein for clojure devl. I built a small Noir app which has page for /
with command line lein run , I am able to see the output at localhost
But how to run within CCW + Lein under eclipse , I press Run , and then open the browser
, it is not working .. ? What's the problem ? How to debug within Eclipse the web app. ie test
whether the server is running , any other web related debugging ?
Thanks
Sunil

You can start the application from the Eclipse REPL. Open the context dialog (right-click), navigate to Clojure and then click Load-file in REPL. After which write (-main) (or manually (server-start ...) in the REPL.
I mainly use Emacs for Clojure development so there is probably a better way to achieve this.

Related

Is there a better way to debug clojure code?

I've been working with Clojure for few weeks now, primarily with Lein+Luminus framework. I've been looking for a way to debug code while on the REPL.
I really like the way how pry(on Ruby) works, when it comes to debugging and runtime invocation. Is there an equivalent to pry for clojure code? or probably a technique/tool that I've missed?
There are two paths to consider to improve your REPL and debugging experience:
Using a REPL and debugger integrated with your editor or IDE of choice
Using an embedded nREPL server
The first is an essential part of setting up your local Clojure development environment and should be done regardless. The second option, using an embedded nREPL server, is closer in usage to how you would use a binding.pry call in your code since it gives you access to the running application, but it isn't used to stop execution at a certain point, but rather give you a REPL with access to your running application and it doesn't provide any additional debugging features on its own.
Editor/IDE with REPL and Debugger
Text editors like Emacs and Vim have excellent Clojure support (both for editing and interacting with a REPL), and most Java IDE's have Clojure support as well.
At this point (May 2015) I'd highly recommend trying Jetbrain's Intellij IDEA with the Cursive plugin because of its excellent support for debugging. You can use the free community edition of Intellij, and the Cursive plugin is (at this point) free as well.
Intellij IDEA
To install Cursive, you go into Intellij's settings, add the correct Cursive plugin repository for the version of Intellij you have, install Cursive, and restart the IDE.
Once Cursive is active, you can simply open an existing Leiningen project in Intellij via "File > Open...". To get a REPL running, click "Run > Edit Configurations" in the main menu. In the window that appears, click the "+" button at the top left and select "Clojure REPL > Local". I'd change the name of the run configuration from "Unnamed" to something like "REPL", but otherwise keep the defaults and press "OK" to save the run configuration.
Now you have a way to run a REPL set up for the project you've opened. You can now click "Run > Run 'REPL'" (or whatever you named that run configuration) for a normal REPL, or better yet click "Run > Debug 'REPL'" to boot up the REPL in a debug mode that allows you to use Intellij's debugging features to debug your Clojure code. Set break points, add breakpoint conditions, run code and inspect frames, variables, etc., like you would in any debugger.
In your case, you'd want to click "Run > Debug 'REPL'" and then execute in that REPL the code you use to boot up your application.
Embedded nREPL Server
The above approach assumes that you first start a Clojure REPL and then boot up your application. If instead you want to have your application boot up normally and then optionally get a REPL that lives inside the running Clojure program, using nREPL directly is your best option.
From its own README:
nREPL is a Clojure network REPL that provides a REPL server and client, along with some common APIs of use to IDEs and other tools that may need to evaluate Clojure code in remote environments.
You should follow these instructions to add a running nREPL server to your application, but here is the most important part:
=> (use '[clojure.tools.nrepl.server :only (start-server stop-server)])
nil
=> (defonce server (start-server :port 7888))
#'user/server
Once you have a running nREPL server as part of your Clojure application, you can attach to it using your editor or IDE of choice (each editor/IDE has a different way of doing this, but most expose a way to attach to a running REPL by providing the host (usually localhost) and the port on which an nREPL server is running), or by invoking Leiningen directly at the command-line like this:
lein repl :connect <port>
You can specify the <port> when you configure the nREPL server as shown above. It also prints it out when it starts.
clj-debugger is a basic REPL debugger which provides features pretty similar to those available in pry-debug. You might consider it as an alternative to using the debuggers available in tools like CIDER & Cursive.
debugging is a huge problem in clojure as we are not aware of where the error occurred as well. define this macro :
(defmacro dbg[x] `(let x# ~x to understand where the eroor is thrown

How to configue Pydev test runner to use Docker

I am developing a Django app or two using pydev as my IDE. I like it a lot :) However, I recently got really excited about Docker and am using Docker and Fig to serve my application now. My problem is that I would like to run my tests in this build environment- seems like this is kinda the point after all!
I know how to actually do it.
fig run web python3 /code/manage.py test
would run the tests. If I didn't want to use the Django runner, I could run
fig run web python3 /code/myapp/tests.py
Either way though, I cannot figure out how to issue that command from the IDE. All of the run configurations point to the configured python.exe ... does anyone know if there is a way to replace that with a fully customized command?
Well, the PyDev launch configuration is really targeted towards running Python, but there are alternatives to running it through other ways:
Create an external tool run (run > external tools > external tools configuration): You should be able to run anything you want from there... the downside is that this isn't really integrated into PyDev, so, if you have stack-traces they won't be clickable (and you won't be able to debug either).
Create a launcher script which in turn uses subprocess to launch the command you want... if you redirect things tracebacks should be clickable. The downside is that you won't be able to create a debug session either -- but you can still use the remote debugging in this case (http://pydev.org/manual_adv_remote_debugger.html)
Improve PyDev to do that better... (i.e.: get the code: http://pydev.org/developers.html and add docker support to a project through fig -- it should be something close to org.python.pydev.django which has special integration for running in django -- with some tweaks to the start command line, even starting in debug mode directly can work here)... if you decide to go that route, you can create a feature request at https://sw-brainwy.rhcloud.com/tracker/PyDev/ and ask code-related stuff and I'll help :)
Possibly you can create a custom executable which acts like Python but in reality just forwards things to other places (i.e.: to fig run) -- I haven't actually tested this, but in theory it should work (in the past there was work to support dummy 'python' runners such as that -- i.e.: for supporting http://cctbx.sourceforge.net/ -- so, it should work -- but you still have to create this launcher script for your use case to pass things to fig run). If the work is done properly, the debugger could work here too.

Pressing arrow keys do not work correctly in Clojure console

I downloaded the Clojure jar. Its version is 1.6.0.
When I run Clojure in console I press arrow keys but they don't move the cursor but produce these characters "[[D^[[C.
I start Clojure using this command:
java -cp clojure-1.6.0.jar clojure.main
using Java 1.7.0_55 64 bit on Ubuntu 14.04 LTS 64 bit.
How can I get back normal arrow keys behaviour ?
The repl bundled with Clojure is pretty terrible. But that's okay, because you want to install Leiningen anyway, and its repl is much better, including the various readline stuff you're used to.
But in general, if there's some app that does a terrible job of being a repl, you can always use rlwrap to wrap the app in readline.
You are following hopelessly outdated instructions/tutorials. The generally accepted way to interact with all things clojure is through Leiningen. Then start Clojure by running:
lein repl
You can create a new web project by running:
lein new compojure my-project-name
or a new general project by running:
lein new my-project-name

Can't open clojure the project in Intellij IDEA with La Clojure

I was going through this tutorial
http://wiki.jetbrains.net/intellij/Getting_started_with_La_Clojure and I got stuck here
http://wiki.jetbrains.net/intellij/Getting_started_with_La_Clojure#Opening_project_in_IntelliJ_IDEA. I don't know way but 'open project' dialog does show the file 'project.clj'. So I'm not able open the clojure project. (And also I don't know how to create new one)
Is this bug of IDEA/La clojure or I did something wrong?
To open/import clj projects, you need to have the Leiningen plugin installed.
Unfortunately, the latest official release of the lein plugin for intellij doesn't work well with Intellij13 (crashed my idea on load every time until removed manually).
I'm guessing that because of Cursive there wasn't a newer release even though the latest version of the plugin on github does work.
I followed the instructions on the lein plugin's git page to create a plugin bundle from the latest version: https://github.com/derkork/intellij-leiningen-plugin
Assuming you're using Intellij13, creating the bundle yourself and then installing it from disk will enable you to open clj project files.

REPL hangs on SublimeREPL for Clojure (Windows PC)

I'm trying to use SublimeREPL with Sublime Text 2 so that I can programme with Clojure. I have installed SublimeREPL using the package manager.
I go to
Tools > SublimeREPL > Clojure
and start a repl this seems to start fine, but whatever I type in and hit enter does nothing. It does not return anything not even an error.
I have Lein installed.
I am using a Windows PC
Has anyone had this problem?
Yes, I have had this trouble with versions 2 and 3. From what I can see, it's a known issue. I have also reported it on GitHub: https://github.com/wuub/SublimeREPL/issues/356
Also, this solution worked for me: Sublime Text, SublimeREPL, Clojure & Windows 8