Is there a quick way to show the code of a method declared in the Scala Console? - scala

I frequently use the Scala console to evaluate and test code before I actually write it down in my project. If I want to know the contents of a variable, I can just enter it and scala evaluates it. But is there also a way to show the code of methods I entered?
I know there's the UP-key to show single lines, but what I was searching for is to show the whole code at once.

There's a file in your home directory named .scala_history that contains all of your recent REPL history. I regularly copy and paste code from this file into project source files. It's not exactly the same as showing the code for individual methods in the REPL, but it might help you accomplish the same goals.
See the comments by Paul Phillips in this issue for a discussion of some related functionality in the REPL (grouping statements in the history):
At some point I implemented the logic for this, but the real obstacle
is jline. It has enough trouble figuring out where the cursor is under
the simplest conditions. Start throwing big multiline blocks into the
history and it breaks down in tears. Would love to see this and
SI-2547 addressed by the community.
...
I expect to fix this soon too, but it depends on how well the recent
jline work goes. I implemented it long ago, and display issues are the
impediment.
Both of these comments are over two years old, so I wouldn't hold your breath.

I dont know a command to load all the code from command line.
What you can do is to :load path/to/my/file.scala to load some complex code and re- :load it when you changed the code in the file.

Related

Alternative for println in Scala

I am required to print huge amounts of data ( in the order of a few 100 MBs) on the console. Using println for this is failing miserably on IntelliJ.
Is there any alternative like console.log which can handle and display this data without lagging and slowing down?
Thanks in advance!
You can buffer, and perhaps bypass character encoding. It's also worth looking at the IntelliJ settings, particularly if you don't see this problem when running from the commandline - perhaps IntelliJ is offering some functionality in its console (e.g. highlight errors, link stack traces to line numbers) that involves scanning every line. You might also worry about word wrapping in your console
(That said, I'm not sure how you expect to understand anything from 100MB of printing - if it's something you need to look at an overview of to "see the pattern", try making code see the pattern the same way you do)

What am I looking for to debug this elisp?

I have an org-mode file that I'm trying to export to a Beamer LaTeX PDF through XeTeX. It was working fine last night on this machine, and just as well on another machine on which I edited it afterward. Both are running org-mode 8, Emacs 24, same export process (3 runs of XeLaTeX)
When I synced back to this machine and tried to export again, I got the error Wrong block type at a headline named "". I checked all my headlines and gave them all names, but still got the same result.
Thanks to the wonders of indexed searchable FLOSS code, I immediately found the snippet online:
(env-format
(cond ((member environment '("column" "columns")) nil)
((assoc environment
(append org-beamer-environments-extra
org-beamer-environments-default)))
(t (user-error "Wrong block type at a headline named \"%s\""
raw-title))))
I'm not really solid on elisp at all, though, and I don't know most of what's going on here. From this snippet, what would I do to start debugging? (I realize I can start the emacs debugger, but it's not a PKE meter, I can't just wave it around.)
IMHE the best way to figure out what's wrong when you've found the relevant snippet of code is to use Edebug.
You should read the documentation to learn more about it, but basically here is my procedure:
identify the part of the code that crashes
instrument the code with Edebug (C-uC-M-x)
re-execute the code and go step by step to figure out what's going on (n)
If the problem is in another function, jump to it GOTO 2.
Iterate until you've understood the code and find a way to fix it.
Posting this answer just so that the specific solution to the particular problem the error was flagging is understood.
Apparently the version of Beamer I have on the other machine has a "normal" Beamer environment that specifies an otherwise blank, unformatted block. This is not present in this machine's install, or at least org/XeLaTeX don't know about it.
My steps were:
Search for all unnamed headings
Name each of them uniquely
Reproduce the error with the identifying string
Check the block type property against the available type list given in org-beamer-mode
Remove the offending type and replace it with another one
This is great and all, but I don't think it's the "best answer" because it involves no actual understanding of what the emacs interpreter was trying to tell me. If I didn't have a good idea of what was going on generally with the TeX, there's no way it would have worked. Dunno if this technique would impress anybody at an interview ;)

emacs Semantic/senator : autocomplete for external lib's

It seems this forum is more alive than mailing list : http://sourceforge.net/mailarchive/forum.php?forum_name=cedet-semantic.
I would like repost my quest from a week ago from there:
First hi to all who contribute to this great package as CEDET :D .
Without much hussle I am able to get working most of the CEDET futures, but when it comes to senator / semantic things get more tought :\ .
Parsing local files are fine.
I don't use EDE not to get things more complicated.
I use the 1.0.6 git trunk version, for compability with ECB.
First is the rumble about the emacs core / cedet git-trunk hussle. How do I check that current installation is running the latter ? ( I have done some .emacs modificaitons see below) .
I generally cannot get the proper autocomplete working for external libs - in this case the OGRE3D project, which all are in the /usr/include/OGRE. I suppose I have added to 'search path' include properly, semantic-describe-c-env. sees them added properly.
2.a What are the basic commands to the semantic parser ? , that is I need to force it to parse the desired includes.
Once I saw semantic parsing the OGRE files in the 'idle time'. Still the autocomplete does not work ( OGRE:RAY is not recongized as a type).
senator-completition-menu-pop gives some non-matching 'c**p'
2.b I know there are customize-group options for semantic, tough their description say little to me.
From the other post:
"Yes, there is a setup cost. You can use semanticdb.sh to pre-parse your
code, but if you never open every file, you might end up with Emacs
having such a huge data structure it gets larger that your machine can
handle. If your project is small, this shouldn't be a problem."
Well this might be, if that would parse OGRE.
here's my .emacs:
.emacs at pastebin.com
Here's what I got on the mailing list, hope that it would help someone , thaks to Eric Ludlam :D :
======================
1. First is the rumble about the emacs core / cedet git-trunk hussle. How do I check that current installation is running the latter ? ( I have done some .emacs modificaitons see below) .
After emacs start, use:
M-x cedet-version RET
and look for the 1.1 version from CEDET/bzr.
I just tried this and noticed not everything has the right version
number. Interesting. I'll have to look into that.
Anyway, the next thing to try is:
M-x locate-library RET cedet RET
and make sure it points where you think it should.
2. I generally cannot get the proper autocomplete working for external libs - in this case the OGRE3D project, which all are in the /usr/include/OGRE. I suppose I have added to 'search path' include properly, semantic-describe-c-env. sees them added properly.
If you enable global-semantic-decoration-mode you can right-click on
header files, and it will give you some options, such as showing where
it things the header is, and showing if it has been parsed yet or not.
2.a What are the basic commands to the semantic parser ? , that is I need to force it to parse the desired includes.
You can use the include menu to force a header to be parsed, or visit
said include. If it can't find it, you can add OGRE to your path from
there too.
If you vist your header, you can use the senator menu to force a file to
reparse, or use:
C-u M-x bovinate RET
to do it.
Once I saw semantic parsing the OGRE files in the 'idle time'. Still the autocomplete does not work ( OGRE:RAY is not recongized as a type). senator-completition-menu-pop gives some non-matching 'c**p'
Autocomplete can fail for many reasons. The best way to find out why is:
M-x semantic-analyze-debug-assist RET
at a place you want to do completion. It will tell you about your
header files, symbols, and the like. It could be your preprocessor
symbols need some setup.
For large complex library headers, sometimes it is just a matter of
having the right pre-processor symbols setup in Semantic so that the
right bits of the headers get parsed for symbols. You'd have to visit a
header where a symbol you want to complete is, and see if it was parsed.
Using:
M-x boviante RET
will dump the symbol table.
2.b I know there are customize-group options for semantic, tough their description say little to me.
From the other post:
"Yes, there is a setup cost. You can use semanticdb.sh to pre-parse your code, but if you never open *every* file, you might end up with Emacs having such a huge data structure it gets larger that your machine can handle. If your project is small, this shouldn't be a problem." Well this might be, if that would parse OGRE.
I doubt parsing the includes is the problem here. I think there is just
something new in the ogre headers we'll have to deal with.
Eric
===================================

CDT compare broken?

Help. I have been relying on the compare editor for code review, and it mostly works quite well.
But for some reason, on some files, it is giving me inconsistent results and telling me that some code is different when it is not. It can't seem to deal with commented out code in this file.
It tells me that later functions are different and tries to match lines in those functions.
I have also found cases where it simply thinks the code is different but it is not.
It then decides that there must be changes in hundreds of lines below this.
I am able to work around by remove the code with #if 0, #endif, but it is not pretty.
Has anyone else seen this and do you know of any way to fix it?
I am trying to get a clean diff do I can see just the actual changes between the files.
It is driving me to drink - and it is still early in the day!

Modify Lisp function without rewriting it?

I wrote a Lisp function earlier that had an error. The first challenge was to figure out how to view the function again. That challenge is solved. Now that I see WHAT I have done wrong, I want to modify the contents of the defined function without rewriting the whole thing?
Seems like as intelligent as Lisp is, there HAS to be a way to do this, I just don't know what it is because I am fairly new to the language. Can this be done?
Judging from the question, I think that you have a strange setup. It seems to indicate that you are writing your functions directly at the REPL. Don't do that.
The usual setup is to have an IDE (for example, Emacs with Slime) where you edit a source file, and then "send" top-level forms (like function definitions) to the REPL.
Every useful REPL has a history functionality. It allows you to move in the history of your input backwards and forwards.
When I write code in the REPL simple keystrokes like m-p gets back earlier code. Some IDEs might even be able to locate source code in a Lisp listener with m-. .
In most REPLS you can also search incrementally backwards.
If you want a log of your input use the function DRIBBLE..
There are some more options, like retrieving the code from the function - when a Lisp IDE supports that.
There is the advice functionality in many Lisps, which lets you run additional code before or after or around an existing function. But the comment is right, why wouldn't you rewrite a function if you're still learning and trying things out? Do they charge you by the compile cycle?