Reusing functionEdit

One of my first questions is the usage of SkipJavaBlanksAndComments in this indent file. This function is defined in the Java indent file, but it is useful in the JavaFX indent file, since the comment types are identical. I didn't want to reinvent the wheel, so I tried to use it and ended up making a copy of the function in my own indent file. Is there a way to simply reuse the existing version of the function without copying it?

Black panda 14:22, October 6, 2009 (UTC)

I do not have an authoritative answer, but I imagine in practice it would be better to duplicate the function as you have done. The cost of duplication is not high (although I fully understand the mistakes of repeating code), whereas having a JavaFX script dependent on a Java script would be awkward. Vim cannot use a function unless the script defining that function has been sourced. You could have code that sources indent/java.vim (while catching errors), and you could then use the function because it is global, but that's ugly. If you start Vim with no Java file loaded (start editing a .txt file), you can type :function Skip then press Tab to verify that no Skip* function is defined. If you now edit and repeat, you will find that the function exists (and :scriptnames would show that indent/java.vim has been loaded). JohnBeckett 06:30, October 7, 2009 (UTC)
I agree with JohnBeckett, duplication here is the way to go. To avoid the duplication (and do it right), you would have to collaborate with the author of indent/java.vim and extract the function to a separate autoload script, which then would have to be maintained jointly. Not worth it for such a small function.
You could make the SkipJavaBlanksAndComments() script-local by prefixing it with s: to better indicate that this is a private function. This is recommended for all internal script functions. -- Inkarkat 11:05, October 7, 2009 (UTC)
I decided to rename the function s:SkipJavaFxBlanksAndComments. This breaks the association with the Java version, in case that one changes. I also updated the indent script to deal with lines with closing brackets on their own and other minor idiosyncrasies. Hopefully people will continue to test it, as I am doing with various JavaFX files. By the way, is there a way to make the markup for displayed code have a larger font size? I can barely read the stuff between the tt and pre tags. Black panda 15:19, October 8, 2009 (UTC)
I think you just need to change your font size in your browser for monospace fonts. It looks fine for me. For some reason a lot of browsers default to something ridiculously small for monospace. --Fritzophrenic 16:17, October 8, 2009 (UTC)
Groan. I remember that I once had that problem where code on various web sites (not wikis) was absurdly small. I have a vague feeling that Internet Explorer used some personal css settings that could be customised, but there is too much garbage on the net now to find anything useful, and I have totally forgotten. I have not seen the problem since switching to Firefox some years ago, and I don't think I have tweaked anything much in Firefox. We really should try to find some info on this. Perhaps we can fix the problem by some code in Mediawiki:Common.css, because it will affect other users. JohnBeckett 00:46, October 9, 2009 (UTC)

Two errors in the script Edit

Using MacVim and two lines cause error messages in my setup.

First, function! s:SkipJavaFxBlanksAndComments(startline) After I removed "s:" no more error messages for this line. Apparently, the syntax doesn't like "s:" before the function name.

Second, if getline(earlier_prev) !~ '[\w\s],\s*$' And this one I can't fix.

Because of these errors, the script is unusable for me. Could you correct these.

Thanks for the script!

What version of "MacVim" are you using? I don't have a Mac, so I can't speak to this, so I'll ask for help. Inkarkat, why doesn't the "s:" prefix work for "MacVim"? Also, according to a comment on the main article, !~ does not work, but != does work. I assume that person also used "MacVim", or was the !~ syntax introduced in a later version? How would I future proof the script for an outdated version of Vim? --Black panda 19:59, November 29, 2009 (UTC)
Black panda, you've only applied the "s:" prefix to the function definition, not to the calls. I've fixed that for you. Regarding the !~, this is the correct syntax, and it has been in Vim since version 6. -- Inkarkat 20:44, November 29, 2009 (UTC)

To the OP who reported the error Please reply here letting us know the result. Can you use the script as it appears in the tip now? As Inkarkat says, the second problem you mentioned is valid syntax and should work (see :help expr4). If you still have a problem, please say exactly what happens. Is there an error (entering command :messages in Vim might help)? What is the error exactly? JohnBeckett 09:25, November 30, 2009 (UTC)

Working now! Edit

Black panda and Inkarkat,

I am the poster of both of the posts. Magically your single correction fixed both errors. I don't know how it happen, perhaps my removal of s: caused the second error. Unfortunately, I am too new to vim and javafx to fully understand the cause. Anyhow, it works now. Many thanks indeed for your effort!

On a different subject, do you also maintain the syntax script for javafx? The closest I could get is here: But, this script has some issues, too. E.g., it doesn't highlight "def" keyword, some well know types etc.

Hi Anonymous. You might consider emailing the author of that script (which is not me) and letting him know what's wrong. You could also try and fix it yourself, but please share it with others. Don't keep it to yourself. --Black panda 20:14, December 12, 2009 (UTC)

Another bug? Edit

Here's me again, still testing the script and seemingly stumbled upon another bug. Please see below code after "gg=G".

class Capitalization { 
   function capitalize(s: String) {
      "{s.substring(0,1).toUpperCase()}{s.substring(1, s.length()).toLowerCase()}";
   function run(args: String[]) {
      def c=Capitalization {};

As you can see on the 4th line the closing bracket is at the same level as the previous line while it should be at the same level as "function". The fifth line should be at the same level as "class".

The run function block is top level and so should start at the leftmost column.

And lastly, println line got indented though should not be.

Just guessing (please don't shoot me), it looks like indentation logic breaks after lines which contain opening and closing curly braces on the same line, i.e. 3rd and 7th.

Just in case, I am running MacVim 7.2 snapshot 51 (64bit Cocoa on Snow Leopard). And by the way, the code compiles OK.

Thanks for looking into this!

This is the initial fix. There was an error in the logic of the property detection, and also I didn't take into consideration that code could be interpreted in the strings of JavaFX. There is more work to be done, but this is my first attempt. Let me know what else needs fixing, as well as any ideas as to how to fix it. --Black panda 20:09, December 12, 2009 (UTC)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.