Getting started with ASDF package management and Common Lisp - build

I'm having trouble getting started with ASDF and Common Lisp.
How can I get a minimal example working?

To answer my own question:
So, how to do your "Hello World!" with ASDF build system? Here's what worked for me. I'll help you side-step the time-consuming traps that I fell into.
Watch this video. He explains installation of sbcl, emacs, quicklisp (a Lisp library manager), slime, and quickproject, which sets up a project with ASDF.
Now to side-step a few traps:
slime didn't seem to work with clisp. I had to use scbl. Note, I'm on ubuntu 16.04.
You must have your .asd file in the path of your ASDF system. You can accomplish this by working in ~/common-lisp/; if you don't have it you can make it. See here to setup ASDF to look in other directories.
Once you have they system built, load the system with (asdf:load-system :<system>). Also, to access functions in a different package, use the following syntax: (<package>::<function> ...).
Happy coding.
For vim users: Emacs and Lisp, specifically with quicklisp and emacs's package manager, is a beautiful combination. Probably because Emacs is written in Lisp. I see the value of this. But I'm a vim user. I was pleased to find Evil, a great vim layer for emacs. Check out this 4 minute video, which impressed me. Also, here is a post of another vim user setting it up to be like his vim environment, better in some cases. I now think the combination of emacs and vim is better than either alternative.

Related

Why my clojure repl formatting is broken?

I am new to Clojure, and I am usually using it from (Spac)emacs, where the repl formats fine. However, when I try to use the repl within a gnome-terminal, then the formatting is broken, i.e. after 'sending' some code, the line of code gets 'reformatted' as shown in the screencast below:
Anybody has some idea what is going on here? The terminal is just a basic 'gnome-terminal' on Fedora.
B.t.w. the same screencast is used for reporting an issue with criterium about the bench example hanging.
Disclaimer: this is not a solution to the problem, but it shows,
where the problem lies and what are workarounds.
TL;DR: call clojure (which does not use rlwrap¹; use
Rebel-Readline
instead, for more features
clj calls clojure, but checks, if rlwrap is installed and uses
that to call clojure with some settings, that are suitable for a Lisp.
rlwrap is a great tool, to get readline capabilities with
interactive CLI tools, that don't have it (e.g. emacs/vi-mode, history,
"hippy" completion). But in this case it is the culprit to smash up the
REPL. What's underlying problem is not clear, but in cases like this
the options usually are: buggy software (the terminal, rlwrap, or the
way Clojure interacts with the terminal), wrong/buggy TERM settings or
term-capabilities.
That said, rlwrap might be the "just good enough" option here
anyway. First of all Clojure developers tend to use the REPL via the
editor anyway. Second there is a far superior option to get what
rlwrap brings to the table:
Rebel-Readline
Beside emacs/vi-modes and history it brings (and probably more):
syntax highlighting for both input and output (with pretty-printing)
multi-line edit in the REPL
proper auto-completion
showing the doc-string of the function under the cursor
¹) From: https://github.com/hanslub42/rlwrap
rlwrap is a 'readline wrapper', a small utility that uses the GNU Readline library to allow the editing of keyboard input for any command.
This is a rlwrap bug that has been fixed upstream (but, as of now, is still open in several distributions) . In a nutshell, either:
use a recent rlwrap (0.46-1 or newer),
or avoid the very newest readline (8.2 or newer),
or put set enable-bracketed-paste off in your inputrc
See this bug report on Github (or this summary of the history of this issue)
Hans Lub (rlwrap maintainer)

Clojure Worksheets

I have been learning Clojure a bit recently. Is there such a thing in Clojure world as Scala-like worksheets, into which I can put any code and get it evaluated as soon as I save it? Or maybe there's a similar solution for Clojure?
I am now working with lein repl and, sadly, can't say it's the most usable tool ever.
In Lisp development in general (and Clojure in particular) the preferred programming style is what's usually dubbed interactive programming - the developer keeps an image of the app loaded at all times and interacts with it via a REPL. You can easily modify the loaded code on the fly and test changes immediately in the REPL (that's not easy at all with Scala - one has to resort to something like JRebel to do it). I find the Scala worksheets a pretty primitive solution in comparison...
The workflow that I follow in Clojure is:
I open nREPL.el in Emacs - this loads my lein2 project with all of its dependencies and gives me a REPL which I can use the try out stuff
I write some code in source code and load the changed functions (maybe by evaluating a top level form with C-M-x
Afterwards I'd press C-x C-z to jump back to the REPL and I try out the new code in it
I go back to step 2
Basically the Clojure REPL is much more powerful than the Scala REPL and I personally consider it hugely superior to the Scala IDE worksheets. Once you get used to the interactive incremental style of programming Lisp offers everything else starts to look strangely complex by comparison. I'm not familiar with Eclipse's CounterClockWise Clojure plugin, but I'm pretty sure it offers similar functionality to Emacs's nREPL.el.
You might want to take a look at the autoexpect plugin for Leiningen. Every time you save any file in the working directory, the plugin compiles and runs your code; as a bonus, it will evaluate any "expect" function calls which can serve as tests. This is very helpful for test driven development and is a nice compliment to working with the REPL as described in the other answer (I often use one or the other or both together depending on how many test cases I have in place).
I should note that running autoexpect is far faster than running "lein test" or "lein run" repeatedly, due to the startup cost of the JVM and Leiningen.
It sounds like what you are looking for is the Clojure Koan plugin. This a worksheet-style problem-solving exercise tool that watches your edits and provides instant feedback on the correctness of your work.
For actual development workflow I second the advice others here have provided on tooling and interactive environment setup, but since you specifically said you are learning Clojure, this can be a fun approach. There is also a web application called 4Clojure that you might have fun playing with.
However you will eventually (or right away) want to get a smooth and convenient development environment set up, and I haven't seen any mention so far of a few important tools. One person mentioned Nrepl. If you like Emacs, there's a slime/swank-like interaction mode that jacks into nrepl called nrepl.el that provides very nice integration between editing files and messing around in the repl. Similarly there is VimClojure, and you can find plugins for IntelliJ (LaClojure) and Eclipse (Counterclockwise) that are also popular and well-maintained.
Someone mentioned autoexpect. If you are looking for a good TDD setup, I would recommend midje. If you are using a 2.0 preview release of leiningen there are a few issues with the lazytest integration being in flux, and lazytest itself is or should be deprecated. But I prefer midje over expectations, personally, and these problems will surely be worked out in the 2.0 release of lein-midje. The stable version of lein-midje that works with the non-preview (1.x) leiningen has autotest-like functionality using lazytest.
As nobody has mentioned it, cursive is really nice these days, although I was sad to move back to a full blown IDE. You can easily do the same thing as Emacs with the built in repl, just move into the namespace that you are working with and synchronise every time you make changes. It's a really nice way of working.

Emacs tutorial for large projects

can someone be kind enough to direct me to emacs tutorials for large C++ project using gdb as debugger, the project does contain make file.
I did search for emacs tutorials but some are too advanced for beginners and some only target one single file tutorial. I did read the previous posts too but did not find an answer suitable for large projects. Also I am not used to using 'git', one of the answers in previous posts.
Actually, learning Emacs is a thing that just can't be easy. You'll have to learn the basics before you will be able to read "advanced" tutorials.
The first thing you should do is to work through the builtin tutorial (C-h t). It's really good.
Then you should try to familiarize yourself with Emacs configuration basics. The easy way suggested by many users is to get a ready-for-use configuration (such as Emacs Starter Kit) and try to understand it and then tailor to your own needs and preferences. The advantages of using a ready-made configuration kit are:
It's a working code useful for learning the basics of Elisp. This learning path is way faster than reading Elisp manuals and gathering configuration code one small piece at a time.
It demonstrates a lot of useful Emacs features which otherwise might require you long time (sometimes years) to discover.
It offers a framework which you can base on writing your own configuration.
Still you should undoubtedly get rid of whatever parts of configuration you don't need.
Then (or along with the previous step) read some tutorial about using Emacs as a development platform. You can easily find a lot of tutorials via "emacs for [c] development" queries to Google. Here is one of many.
Then install Cedet (Alex Ott has written a great tutorial about it) and start feeling the power.
After that you'll know what to do next.
By the way, there is a great collection of Emacs resources maintained by Bozhidar Batsov.
Start simple. Launch Emacs without any customisations and start editing your source files. The only "tutorial" you'll need to do basic editing is the inbuilt one you'll get by hitting Control H followed by t (Referred to as C-h t in Emacs speak).
Compiling can be done by typing M-x (Alt x) compile and hitting enter. It will prompt you for the compile command which is by default make. Change it to whatever suits you.
Running gdb is done using M-x gdb and hitting enter. The interface is similar to the M-x make.
Don't use things like the Emacs starter kit which makes assumptions on your behalf. While useful as a starting point for newbies, it suppresses curiosity and that's the key to learning Emacs. The above things should be enough for you to start. Once you hit problems and are not satisfied with the ways of doing things, you can search for resources and things. Emacs is not an "IDE" and so you won't have the tight integration which many custom editors have. Don't expect it.

Vim code completion

Is it possible to make Vim complete the code for you, like in any other IDE (not just word searching, but members of classes, methods etc.)?
What are the best options / plugins available?
Clang Complete lets you use Clang for accurate auto-completion of C and C++
I believe that following this list of links you will be able to leave any IDE and become a faithful user of vim, see some plugins that help you with IDE resources...
snipMate plugin faster code complete skels
video showing snipmate on vimeo
article about sparkup html codding to understand this resource
video showing sparkup html complete to see this in action
Auto complete popup plugin here
Advanced undo resource
some interesting videos on advanced usage of vim on vimeo
more free videos at vimcasts.org
amazing article about vim in this link
vim for php programmers (useful not only for php programmers) here
This is a little out dated. A rising star in Vim code completion is the "YouCompleteMe" plugin. Check it out here.
Omni completion is definitely the way to go. Instantiate it in insert mode with Ctrl+X Ctrl+O.
I use it in conjunction with SuperTab as well to allow for tab completion similar to bash shell.
Don't use it myself but I have heard of Omni complete:
http://vim.wikia.com/wiki/Omni_completion
The Vim Wiki contains a couple of things that may be of use for auto completion of words.
You can try this out Dictionary completions, get dictionary for you language. Simple ways
if you are programming in c++, there are ctag and cscope and with OmniCppComplete plugin.
Hope it will help
It's possible, but most people don't.
vim is a fairly generic editor, that said, it does contain some "code completion" features such as word completion, etcetera, but nothing like the likes of, say, Delphi's IDE.
Such a system could be added by scripting vim - vim can directly run several scripting languages that make this easy, or you could send the file through an external script.

Django + Emacs (as TextMate replacement)

There is any complete tutorial how to configure emacs for using with Django (1.1) (on Mac)?
Im thinking about switch from TextMate to Emacs to have multiplatform editor for django. I have my fav. theme from textmate and I want to convert this to emacs (maybe is "converter" for this?). Switching from Textmate is a good idea ?
I second #docgnome's suggestion of Django mode and yasnippet, but the real kicker that will make you never want to go back to TextMate is to integrate PyFlakes into your development environment, at which point Emacs will provide you on-the-fly notification of errors in your Python code. These go far beyond the typo-level error detection you get for free merely by having syntax highlighting; you'll be notified of errors such as variable before assignment, unused imports, and bad indentation, among other things.
Installing PyFlakes in Emacs is relatively straightforward: just download and install PyFlakes, and then add the following to your ~/.emacs or ~/.emacs.d/init.el, as appropriate:
(when (load "flymake" t)
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pyflakes" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init)))
(add-hook 'python-mode-hook 'flymake-mode)
That's it. You should now notice that, whenever you're editing Python, errors are highlighted in red. Mouse over to see a full explanation of what's wrong with the provided line.
As far as theming like TextMate: theming can be a bit annoying Emacs; unless you truly want the exact theme you have in TextMate, I'd grab Color Theme for Emacs and find one that suits your fancy. You can almost certainly find one very close to your current TextMate one, and won't have to deal with manually configuring faces.
You might check out Django mode for emacs. What specific functionality were you looking for? For snippets, I recommend yasnippet which is inspired by the TextMate snippet system.