Text Editor with Scripting...for Linux - javascript

For a while now, I have been using UltraEdit on my Windows box. The ability to write scripts with a familiar language (JavaScript) has proved to be extremely useful. The only problem is that I cannot use it on my Linux box at work. Is there a comparable text editor that runs on Linux and has an integrated scripting engine?
Not breaking the bank and being cross-platform would be great.
EDIT:While recordable macros are great, I use the scripting engine much more.

All of the major open-source editors and most of the others hava a scripting facility of some description - some (Emacs in particular) are famous for it. The only ones that don't tend to be very lightweight ones like pico.
vim has a native scripting language and can also be built with embedded Python, Tcl or Perl interepreters that can operate on selections, buffers etc through the plugin mechanism. Emacs is all about scripting - it's has a LISP interpreter built right into the core of the system and most of the editor is written in LISP. There is a running joke about emacs describing it as a LISP interpreter that someone just happened to use to write a text editor.
Vim's user interface is descended from vi, which is somewhat quirky but very powerful once you get used to it. It also does recorded keyboard macros particularly well and has a very nice regular expression search/replace facility.
Emacs is regarded as a bit of a baroque monstrosity and is very large and complex. However, its scripting capability is second to none and there is an enormous variety of macro packages that do many things. It has a very loyal following of people who swear by it; once you've gotten over the learning curve (there is an enormous body of resources on the web to help with this) it's a very powerful system indeed. You can customise emacs into a whole IDE and there are people around who claim to spend the majority of their tube time in it.
Both of these editors can work in text mode or with a GUI and are highly portable, running on a wide variety of platforms. They are both open-source.
I've used both; I used to use XEmacs (a major code-fork of emacs that goes back a number of years) back in the 1990s but went to vim later on. I even use vim on Windows.
If you find the user interface of Vim or Emacs a bit too much, there are a variety of other text editors available, many of which offer scripting. Examples of these are SciTE, which has a built in Lua interpreter, NEdit, which has a homebrew macro language of its own or GEdit, which is substantially written in Python (which can also be used for scripting it) and has a plugin API.
EDIT: Outside of a few specific projects (e.g. Mozilla) Javascript never got much traction as a stand-alone or embedded scripting language in open-source circles. Historically there wasn't a popular open-source Javascript interpreter that got widespread acceptance in the way that Python or Tcl/Tk did. Javascript is more widely used in closed source systems such as UltraEdit or InDesign (to name a couple) whereas other languages were more popular on open-source projects.
None of the open-source text editors that I am aware of feature javascript as an option for a scripting language (feel free to step in and comment or edit this if you know of one). You will probably have to move off Javascript to another language such as Python or LISP. However, now that QT comes with a Javascript interpreter (QTScript) you may find some of the KDE-based ones offering this as a scripting option, but I am not specifically aware of any off the top of my head.

emacs is free and has its own embedded lisp dialect which can be used to write nearly anything, including light scripting as well as mail user agents and IRC clients ;-)
There's a bit of a learning curve, but my experience with emacs has been very positive. I don't like modal interfaces too much, and no other editor puts the navigation shortcuts right under your fingers.

Vim is omnipresent and vimscript is really easy and text-editing oriented: http://vimdoc.sourceforge.net/htmldoc/usr_41.html
That comes by default. You can also use Python, Ruby, Perl, Scheme... but that requires compiling.
Python might be a good choice, since omnicomplete requires it. I run a separate binary for omnicomplete anyway since I like the ultra-lean vim for other usage, check here:
http://vim.wikia.com/wiki/Compile_a_separate_copy_of_Vim_for_Python_coding
Honestly I haven't used python to script vim per se. I usually code, python or not, with vanilla vim and no auto-complete. I do however call python and any other command from vim to process my files line by line, might reply with more about that if you are interested, but that doesn't require to compile anything, works as is.
EDIT: if you want a point-and-click editor, you can run Cream on gVim http://cream.sourceforge.net/download.html
I still think that vim takes little time to get used to and is VERY worth learning, more so considering you can use your basic vi knowledge to connect to a server via SSH no problem, and it's installed in any *nix. I like knowledge I can reuse, saves me time and trouble long term.

I use jEdit, that is a great editor and allows to be scripted with beanshell. As it is written in Java it runs well under Windows and Linux.
Simon Groenewolt mentioned, that a plugin (JavascriptShell) exists, that allows you to write Macros and Scripts also in Javascript, not only in Beanshell.

If you don't need really complex scripting, vim/gvim allows you to record a keystroke sequence and play it back. And you can give a repeat count on the playback, so you can record an operation on one line, then repeat it for the next 10,000 lines in one step.

Wow, I really don't want to start a holy war here, but all these Emacs recommendations are kind of missing the point. Emacs is very powerful, but let's be honest. It doesn't have a learning curve so much as a learning WALL. Going from a point-and-click IDE style editor like UltraEdit is going to be a huge culture shock.
And honestly, when someone says they like to write scripts in javascript, and are looking for something similar in Linux, the first thing you say is "learn LISP"?!
This is why people think Linux is hard to use
I'm going to go in another direction entirely and suggest Aptana Studio
It has built-in highlighting and code-completion for a variety of languages, and supports scripting in javascript with Eclipse Monkey. It is based on Eclipse, and therefore runs on java hence multiplatform. And it is available for free.

It's kind of cliche, but emacs. Or am I misunderstanding what UE's script engine is?

Try Emacs, either XEmacs or GNU Emacs.

I use gedit. You can write plugins in Python.

Komodo Edit is made on top of Mozilla's XUL Runner. It offers possibilities for extending it thorough either extensions (like Firefox) or macros, snippets, commands. You may write these snippets in either JavaScript or Python, which is nice, but you still have to know the API in order to do something useful.
Being built with Mozilla technology it runs on Linux too.

It looks like Komodo Edit, SciTE, and Eclipse Monkey are the winners. Komodo Edit seems to be most similar to Ultra Edit. SciTE is something I've used before, and Lua is not that difficult; SciTE's API though does not seem as extensive as Komodo Edit's API. Eclipse Monkey is something I am definitely going to use, but it requires Eclipse, which is definitely not a text editor.
EDIT: UltraEdit is coming out for Mac and Linux Soon.

The traditional way for doing scripted text editing in Linux is to use the facilities that have (almost) always been available in *nixes: sed, awk, grep, things of that nature. Sure, they maybe don't appear to be as "handy" as one might find an integrated Javascript engine, but they are very mature and work well. If this scripting language MUST be inside the editor, Emacs is probably a good one here too.
You could use an "integrated" type solution to solve the problem, as lots of others have mentioned, but IMHO the commandline is more powerful in this regard.

SciTE can be scripted with Lua and is a good, simple editor which behaves much the same way if you're switching between Linux and Windows every day.

I don't know what you're using the scripting capabilities in your editor for, but you may want to consider automating those tasks using Linux command-line tools such as sed or awk.

Related

Pluggable language engines for browsers. Why not?

Firefox has a SpiderMonkey javascript engine. Chrome has V8 javascript engine.
Obviously those engines are a separate products and browsers utilize some kind of interface API to interact with them.
On the other hand programmers longed for a long time for their favorite language in browser. So much so, that we have products like GWT (for java), parenscript (for common lisp), HJScript (for haskell), and i'm sure many other libraries for many other languages that allow programmers stay with their favorite language and generate client side code as well.
The idea is so obvious that i am surprised that there's no implementation of it yet. Why not publish the interface API of browser to language engine and allow web sites to provide custom language engines as downloadable bundles. With current internet speeds 3-4 megabytes one time download is not a problem for majority of applications, even more so for intranet usage.
So where's our pluggable engines ?
You don't need pluggable engines really, just an agreed upon byte-code format. Google is going down that path now with NaCl and PNaCl which is based on LLVM. So any program that compiled down to a safe subset of LLVM byte-code could be run in the browser.
Browser vendors can't even agree on a common video format (see the html5 <video> debate) or on how the document DOM object should look like, and you want them to agree on a whole language interface?
Good luck.
I guess you forgot about applets and embed's. Both offer exactly what you want. And both suck for the very same reason.
We've been down this route in the past.
Older versions of IE supported VBScript as a scripting language in addition to JScript.
The result was a whole load of sites that only worked in IE.
This isn't what the web needs again. As a developer, I may desperately want to write code using my favourite language, but as a user I want to be able to browse all sites on the web without having to worry about which plug-ins I need for any given site, or whether my preferred browser can even use those plug-ins.
This is the problem that Microsoft's Silverlight has had. It might be a marvellous technology, but to the end user, why do I want another plug-in? Silverlight has managed to gain some market share thanks to the sheer power of Microsoft, but really not that much.
Now, if the code reaching the end user is consistent, regardless of the language it's written in, then the language doesn't matter. But this effectively means compiled code (or at least bytecode), which is a whole different kettle of fish to running a scripting language in the browser.

Javascript (and HTML rendering) engine without a GUI for automation?

Are there any libraries or frameworks that provide the functionality of a browser, but do not need to actually render physically onto the screen?
I want to automate navigation on web pages (Mechanize does this, for example), but I want the full browser experience, including Javascript. Thus, I'd like to have a virtual browser of some sort, that I can use to "click on links" programmatically, have DOM elements and JS scripts render within it, and manipulate these elements.
Solution preferably in Python, but I can manage others.
PhantomJS and PyPhantomJS are what I use for tasks like these.
What it is, is a headless WebKit based browser which is fully controllable via JavaScript. There's a C++ implementation (PhantomJS) and a Python one (PyPhantomJS). I prefer the Python one though, because it has a plugin system which allows you to add functionality to the core without actually modifying any code, unlike the C++ one. :)
There is an absolute ton of free software technology now available: take your pick at http://wiki.python.org/moin/WebBrowserProgramming but if you have specific questions join pyjamas-dev on google groups and i'll be happy to give further details, there. brief answer: you can run pywebkitgtk "headless", or you can use xulrunner (via python-hulahop) again using pygtk without actually doing "browserwidget.show()", and there's also pykhtml. also you could use python COM to connect to MSHTML.DLL.
these are all "cheat" methods: using python bindings to a graphical web browser engine without actually firing up the graphical bit. if you really wanted to put some serious hard-core programming in, you could create a "port" of webkit which was not connected to a GUI toolkit: as an experienced webkit programmer i'd put it as around... 2 weeks of full-time effort to make such a "headless" version of webkit.
l.
Looks like http://watin.sourceforge.net/ might be a good way to go.
If you don't have to go pure Python, you could do IronPython since it's a C# project.
take a look at this little doosy on ajaxian
http://ajaxian.com/archives/server-side-rendering-with-yui-on-node-js
It also talks about Aptana Jaxer which I think runs on a headless firefox so is basically the Mozilla browser engine in all it's glory.
There is Kapow. Its pure Java and costs money:
http://kapowtech.com/
And there is Lixto: Its Eclipse based and uses Mozilla Gecko as rendering engine (unless they already changed it to WebKit, as they said they'll do years ago). Its very nice and also costs money:
http://www.lixto.com/?page_id=50
They are both graphical tools where you define the site navigation and what should be extracted by point and click. But you can also write xpath and regular expressions and even JavaScript that runs in the sites context.
I used them both in the lectures web data extraction and applied web data extraction at the technical university Vienna (Lixto is written by the Professor who held the lecture).
HTMLUnit in Java is very good. I think it's only the Java implementations of headless browsers that manage to provide Javascript support.
MaxQ, I read about here, sounds like it might be interesting: "written in Java, generates Jython scripts"
Try HtmlUnit !!!

Breakpoints in Ruby IDE?

I currently use TextMate for Ruby/Javascript/Actionscript development and it is amazing. But one thing I would really love to use are breakpoints so I could stop code execution and examine the state of the variables and walk through the code. Something like what Flex Builder does.
Does TextMate have this capability? Or what do you use to do breakpoints and that sort of thing with Ruby? How about for Javascript too?
Thanks!
Since TextMate is not an IDE but just a text editor (on steroids though!) I believe this is something totally not supported.
As for the javascript, this is something you can do with firebug (at least for firefox) and similar tools are included (or can be found) for IE, Chrome and Safari :)
There are 3 mostly-Java IDEs that run under Mac OS X yet do a good job of developing (and of course debugging) Ruby.
Eclipse, with the Aptana plugin;
IntelliJ IDEA (it knows lots of programming languages)
NetBeans (I think).
All three are free (even IntelliJ, they have an Open Source edition out now), so you can just download, play around with it, get accustomed and go to town.
Eclipse with the Dynamic Languages Toolkit supports Ruby debugging. I have used it in the past, and it supports Javascript as well.
TextMate is an editor and not a full-blown IDE, so it doesn't support debugging.
If you're looking for a Ruby IDE, I highly recommend RubyMine. It's got great support for debugging, running tests, easily navigating between files, and basic refactoring. Admittedly it's a lot more heavyweight, so I tend to use it for major work (or when getting up to speed on an existing code base), and still use TextMate for quick changes.
There are some open source solutions as well. In the past I've used NetBeans and RadRails, and particularly NetBeans has worked very well for me, too. Not as good as RubyMine, but well worth checking out if you're on a budget.
I should also point out that you can debug Ruby apps from the command line, using the ruby-debug gem. Basically, you place a debugger call into your code to set a breakpoint, and then run the app with rdebug instead of ruby. Check out this article for an overview.
arcadia is a ruby editor written in ruby with ruby debugging support. A little rough still, but at least you get the good feeling of running ruby :)
-r

JavaScript tools for Visual Studio 2005

I need to find if there are any tools targeting both Visual Studio 2005 and JavaScript. I'm interested in plugins which will increase the quality of work done in VS2005 with JavaScript oriented development.
I think you'll be hard pressed to find anything specific for VS2005, since it is a dev environment and JS is a client technology. However, a couple of ideas you might want to consider:
jQuery. The recent availability of Intellisense for jQuery (although I think it is only for VS2008) helps your quality of work in the sense that you don't have to spend so much time looking back and forth at documentation, although I would say that is the best way to really become familiar with it anyway. There are several other good JS libraries out there, but (a) I don't think that was the point of your question, and (b) jQuery is the only one "semi-officially" supported in VS that I'm aware of.
Script#. Although I haven't used it, it looks interesting... basically you program in C#, and it gets translated to JS at runtime.
If you could afford it, I'll recommend upgrading to Visual Studio 2008. You can open .NET 2.0 application without converting them. It comes with much better Javascript Intellisense.
(source: scottgu.com)
One of the other JavaScript features in VS 2008 is the much-improved support for JavaScript debugging.
These features are enabled in both the free Visual Web Developer 2008 Express edition as well as in Visual Studio, and makes using JavaScript and building AJAX applications significantly easier.
If you are using jQuery in your applications, then you could install jQuery Intellisense in VS 2008.
Well, if you want something that will help you write better Javascript in Visual Studio then you can give JSLint a try. It's a plugin that will verify your Javascript code, spot errors, and help you debug it.
Beware, JSLint can hurt feelings.

Javascript interpreter to replace Python

In terms of quick dynamically typed languages, I'm really starting to like Javascript, as I use it a lot for web projects, especially because it uses the same syntax as Actionscript (flash).
It would be an ideal language for shell scripting, making it easier to move code from the front and back end of a site, and less of the strange syntax of python.
Is there a good, javascript interpreter that is easy to install (I know there's one based on java, but that would mean installing all the java stuff to use),
I personally use SpiderMonkey, but here's an extensive list of ECMAScript shells
Example spidermonkey install and use on Ubuntu:
$ sudo apt-get install spidermonkey
$ js myfile.js
output
$ js
js> var f = function(){};
js> f();
Of course, in Windows, the JavaScript interpreter is shipped with the OS.
Just run cscript or wscript against any .js file.
There are four big javascript interpreters currently. V8, Squirrelfish, Spidermonkey and Rhino. I think more important than performance is how well it integrates into existing infrastructure, and I guess Rhino with its bridge to Java wins here.
Try jslibs, a scripting-focused standalone JS runtime and set of libraries that uses SpiderMonkey (the Gecko JS engine).
On the 'easy to translate' theme, there's also Lua.
It's somewhat similar to Javascript, but more 'orthogonal' (closer to functional roots).
The heavy orientation to 'pure' programming theory has made it really small and fast. It's the fastest scripting language around, and the JIT runs circles around the new JavaScript JITs that are starting to appear.
Also, since it was originally thought as an extension language, it has a very nice and clean interface to C, making it very easy to create bindings to any C library you might want to access.
Google's V8 can be used as a standalone interpreter. Configuring with scons sample=shell will build an executable named shell, that can be called like so: ./shell file.js.
You'll need some server-side JavaScript interpreter. Check out the following blog post. Something such as Rhino might be useful for you.
You might try toying around with SquirrelFish or v8, both should be runnable on the command line.
FYI, there is a built-in one already on modern windows platforms. You need to use JScript, but it's close enough. Same environment also allows for VBScript. To run a program you can execute something like:
cscript foo.js
The windows system API is a bit weird and frustrating if you expect the same flexibility as with basic JS objects, but they do have thorough documentation if you can handle digging through the MSDN pages and seeing all the examples in VBScript.
Not sure what's available for Linux/Mac in terms of js shell.
Well, for safety reasons, javascript had not been provided with file access right by design. So as a scripting language, it's a bit limited.
But still, if you really want to, spider monkey is your best option. Here is a tuto :
http://developer.mozilla.org/en/Introduction_to_the_JavaScript_shell
Node.JS. It's great. Has many modules. you can do all your file scripting with Node.
In my years I've found most Javascript developers find it quite easy to transfer over to PHP and vice versa - it isn't a direct answer to your question, although if you're working in ActionScript and JavaScript then you're best to stick with something like PHP (if you're not willing to move to Java, and stick with the ECMA base)

Categories