Auto-completion in Textmate for Ruby? - ruby

I'm really used to auto-completion coming from Netbeans.
In Netbeans, when I type a 'string' and then hit a 'dot' it will print out a list of methods for the String class.
TextMate doesn't seem to have that function.
Is it something you could add?
Would save A LOT of time instead of using the ri/irb/online doc all the time.

Install the Ruby TextMate bundle, open a Ruby file and type alt+esc to get the autocompletion.

You have discovered the fundamental difference between a text editor and an IDE: a text editor edits text (duh!), i.e. an unstructured stream of characters. It doesn't know anything about objects, messages, methods, mixins, modules, classes, namespaces, types, strings, arrays, hashes, numbers, literals etc. This is great, because it means that you can edit anything with a text editor, but it also means that editing any particular thing is harder than it were with a specialized editor.
A Ruby IDE edits Ruby programs, i.e. a highly structured semantic graph of objects, methods, classes etc. This is great, because the IDE knows about the rules that make up legal Ruby programs and thus will e.g. make it impossible for you to write illegal Ruby programs and it can offer you automated transformations that guarantee that if you start out with a legal Ruby program, you end up with a legal Ruby program (e.g. automated refactorings). But it also means that you can only edit Ruby programs.
In short: it's simply impossible to do what you ask with a text editor. You need an IDE. (Note: you can of course build an IDE on top of a text editor. Emacs is a good example of this. But from what I have read, the TextMate plugin API is simply not powerful enough to do this. I could be wrong, though – since I don't have a Mac, I'm mostly dependent on hearsay.)

TM's "equivalent" is hitting escape, I believe.
You can make escape "go across files" for completion if you use the ruby amp TM bundle http://code.google.com/p/ruby-amp/
GL.
-r

Related

Adding keyword commands and functions to Textmate 2 bundle syntax

I want to add some additional syntax highlighting definitions to an existing bundle, but I need some general advice on how to do this. I'm not building a syntax from scratch, and I think my request is pretty simple, but I think it involves some subtleties for which I find the manual somewhat impenetrable in finding the answer.
Basically, I'm trying to fill out the syntax definitions for the Stata bundle. It's great, but there is no built in support for automatically highlighting the base commands and the installed functions, only a handful of basic control statements. Stata is a language which is primarily used by calling lots of different high level pre-defined command calls, like command foo bar, options(). The convention is that these command calls be highlighted.
There are a ton of these commands, and stubs which are used for convenience. Just the base install has almost 3500. Even optimizing them using the bundle helper, which obviously gets rid of the stub issue, still yields a massive regex list. I can easily cut this down to less than 1000 important ones, but its still a lot. There are also 350 "functions" which I would like to match with the syntax function()
I essentially have 3 questions:
Am I creating a serious problem by including a very comprehensive list of matching definitions?
How do I restrict a command to only highlight when it either begins a line or there is only whitespace between the beginning line and the command
What is the preferred way of restricting the list of functions() to only highlight when they have attached parentheses?

customize vim with ruby scripts

Vimscript is difficult. Ruby is not quite so diffiuclt. Customizing Vim with Ruby scripts can be done, and I am trying to learn how. This is a useful presentation about it which covers the basics, but meaningful examples are scarce (and these are rather complicated), so I'm wondering if anyone with experience in this area can offer some smaller examples of Vim mappings and shortcuts written in Ruby.
As a specific example of the kind of scale I'm looking for, let's suppose I want to create section headers for my documentation or something, as in
----------------------------------------------
------------------- SECTION ------------------
----------------------------------------------
where the section name is centered in the set of hyphens, and to achieve this I visually select the word
SECTION
on it's own line, and hit leader <arbitrary keystroke>.
Counterargument: Vimscript isn't difficult, maybe a bit different; after all, much of it is modeled after Python.
I do agree that for certain, complex tasks (especially anything that requires interaction with the "outside world", be it file systems, web service calls, etc.), or stuff that benefits from library functions, a different programming language (and fortunately one can choose among powerhorses like Perl, Python, and Ruby) has undeniable benefits.
But the example task you're giving is just a simple sequence of yanking, simple string manipulation, followed by paste. There's little meat, and the interaction with the Vim buffer isn't that different when done in an integration language. That's my main point: You still have to integrate with Vim, and for that, some knowledge of Vim's structure (and that means Vimscript) is necessary.

Xcode "new method" shortcut?

My initial take on XCode is that it makes hard things easier, and easy things harder (find & replace requires way too many keystrokes, for example...). The biggest one to me, however is a lack of a method wizard... I tend to write lots of small methods, and I'm finding it hard to believe that you can't declare your method in a popup and have the interface and implementation files populated with stubs. Am I missing something? Frankly, I get far more functionality out of vi from an editor perspective.
I don't think you can do that exactly as you want it (without a plugin like Accessorizer), but it's not necessary, since you can create your own snippets, as highlighted in this snippet question, that will then contain the stubs you really need. Since most basic methods are written for you (or only require a few keywords to be autogenerated with your requirements, with #synthesize, etc...), it makes sense to me.
However, this could make your day if you still are unhappy :D

Setting up TextMate for Haskell programming on Mac OS X

I am new to mac, and am in the process of getting my computer setup with all the programs I need, one of them being Haskell.
To my surprise, the Haskell platform for OS X is not like in Windows (where there is an GUI editor built on the platform installation - winGHiC). After looking a lot around, I found this editor TextMate which is supposed to be compatible with Haskell but am finding it quite complex to setup the Haskell Bundle for it.
I have already downloaded and installed the following:
Haskell Platform for Mac OS X
Xcode 3.4 (Haskell Prerequisite)
TextMate
haskell.tmbundle files (mentioned above)
Is anyone familiar on how to get it working? It will mean a lot to me a detailed stepwise explanation, like I said, I has been only 1 day since I used OS X for the first time.
Thanks a bunch.
Well it's good work that you have found that the tmbundle is on Github these days.
You should be able to find the inbuilt options by clicking Bundles, then Haskell. There are fairly few in the standard Haskell.tmbundle. The most obviously useful one is ... load file command-shift-r or command-R. If you have written a module with ending .hs or .lhs, it ... opens it in ghci.
(There was some talk of an integrated terminal in TextMate II, but who knows? One annoying feature of a non-integrated terminal is that one is tempted to 'reload' by clicking command-R rather than by doing :r inside ghci; in certain frenzies it will develop that I have 15 copies of Terminal open.)
Many of the nice features are just general TextMate things, determined by the language description, so it might be good to read a general description of TextMate niceties. For example, if several lines are highlighed, then command-/ comments them out with --s; or, if they are already commented, uncomments them. I had hacked together something to do this, long before I realized it was already there, not having studied the manual closely enough.
Everything has keybindings, of course, and it is very easy to add your own to run little scripts and insert little snippets, much more so than in Emacs, say.
Under Bundles click Bundle Editor and examine the text for different kinds of things.
So, for example, to make a tab trigger to start a language extension pragma {-#LANGUAGE ... #-} where the cursor is in the space ...make a copy of a Snippet and substitute
{-#LANGUAGE ${1}#-}
selecting Activation: Tab Trigger, and (say) LANG as the trigger.
One nice thing is that they are all shell scripts, or else (like this one) partial shell scripts with some TextMate variables around, and you can pretty much write them in your own preferred language. (For the Haskell bundle I don't have any Haskell ones to speak of any more, but for other bundles I do.)
The syntax highlighting is surprisingly sound, but trips over a few fancy extensions, e.g. "PackageImports" , GADT syntax, markup for the Haddock documentation system, and some other oddities. I have hacked my own, but I find the format of the syntax files pretty unintelligible, so it's no use sending you a copy. The Haskell.tmbundle has been emended by some knowledgeable Haskellers in the last two or three years. The person who first made it was just learning Haskell, and hadn't e.g. composed Haddocked modules, but on the other hand, he seems fortunately to have been very skilled and to have had an intimate knowledge of the TextMate machinery.
Notice by the way that TextMate stores the emendations you make in the Bundle Editor in a rather strange way. The bundles that come with TextMate, e.g. C, Ruby, HTML, LaTeX, etc. are in /Applications/Textmate.app/.../Bundles. The ones you install are in /Library/Application\ Support/TextMate/Bundles. When you make emendations through the Bundle Editor, they are stored in your local ~/Library/Application\ Support/TextMate/Bundles. It sort of makes sense but it's a little complicated, and impedes public improvement of the Haskell bundle. (The one bundle I share with people, not the Haskell one, I keep in the lattermost, outermost directory under git revision, so the original and my emendations are together.)
The "Lookup on Hoogle" keybinding/option acts on highlighted terms; here's a replica for the hayoo website, which can search for uses of a type-signature
echo "<meta http-equiv=\"refresh\" content=\"0;
http://holumbus.fh-wedel.de/hayoo/hayoo.html?query=${TM_SELECTED_TEXT:=$TM_CURRENT_WORD}\">"
If you cabal install hoogle, then you can make a local call to hoogle with a script like so:
hoogle --w --n=100 '${TM_SELECTED_TEXT:=$TM_CURRENT_WORD}'
choosing Save: Nothing, Input: Selected Text, Or: Word, Output: Show as HTML
Other emendations I have made are mostly trivial, like a tab trigger snippet for `{-#LANGUAGE ... #-} or else eccentricities of my own.
One thing worth mentioning that I managed to integrate is the typeof executable from Hackage, cabal install typeof, which runs to ghci for an inferred type signature. I have a key binding to show the inferred type as displayed bit of html, but also to insert it. It's a bit delicate but here is the text for the displayer of types
#!/bin/bash
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
module="${TM_FILEPATH}"
echo $word | typeof $module
choosing Input: Selected Text, Or: Line ; Output: Show as Tool Tip, Activation : Key Equivalent (then choose a keybinding , mine is control-option-command-j) Similarly, for type insertion via typeof make a new C (command file) heading and include this:
#!/bin/bash
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
module="${TM_FILEPATH}"
echo $word | typeof $module | typeof_wordorder
# typeof_wordorder is the following hack compiled
# in my local ~/bin
# module Main where
# main = interact reword where
# reword :: String -> String
# reword xs =
# xs ++ (head . words . concat . lines $ xs)
Here typeof and typeof_worderorder are Haskell executables, the first cabal-installed, the second is the above commented idiocy, compiled in my local ~\bin to get around some escaping nonsense. Here you should choose Output : Insert as Snippet
Sorry, I'm just thinking of random things. You should keep posting questions under this heading, as I think it would be worthwhile to see how one might trip up, but also what hacks our cleverer Haskeller friends may have thought of. I keep meaning to put a 'fork' of my tmbundle on github, but it's not too thrilling, and the organization of Bundle directories forever defeats me.

What are the things you would like improved in the Ruby language?

What are the things you wish Ruby (and more generally the Ruby community) would improve?
I read somewhere that Ruby is the love-child of Smalltalk and LISP, with Miss Perl as the Nanny.
I have a lot of respect for Ruby's parents, but I'm not sure I like the influence Miss Perl had on the child. Specifically, I don't like the predefined variables: I need a cheat sheet to know what they mean. You could say "just don't use them". Well, I don't... but other people do. And when I download a plugin on the Web, I have no choice but to fetch my cheat-sheet if I ever need to go and touch the source code. I just wish they would remove those from the language itself.
Also, I think that Ruby is too much of a moving target. My code breaks on every new Ruby upgrade, even on minor releases. This is true also of Ruby on Rails and most Rails plugins I have worked with: they just change all the time, and nobody seems to care whether the changes break everything or not. IMHO, although I love a lot of things in Ruby, this lack of stability is almost a show-stopper.
I wish people would consider backward compatibility between minor releases as an unbreakable rule when releasing a new language (or library or framework) version.
I wish that some of the lesser used modules of the standard library were documented.
Make require-ing files less painful. Don't ask me how, but maybe have one file dedicated to knowing the paths involved and just get rid of the relative path crud from everything else.
Getting rid of the artificial distinction between Modules and Classes would be nice.
Both Modules and Classes are Namespaces. Modules are also Mixins, while Classes aren't. Classes can also be instantiated while Modules can't. This distinction is unnecessary. Just get rid of Modules and allow Classes to be used as Mixins.
An example of a language where this works is Newspeak.
I'd appreciate being able to install ruby 1.9 as an RPM rather than having to use the source.
Make Ruby completely Message Sending based, get rid of everything that is not a message send: local variables, global variables, instance variables, class hierarchy variables, constants, magic globals, magic constants, builtin operators, builtin keywords, even literals. See Self, Ioke or Newspeak for the incredible power and elegance this gains.
I wish they would get rid of the predefined variables: $!, $&, $+, etc.
I would like to have support for static compile-time metaprogramming. The Converge Programming Language might be a good starting point.
Replace the Mixin system with a Traits system.
Replace Exceptions with a Common Lisp style Conditions system.

Resources