Editor SlickEdit

From Apache OpenOffice Wiki
Jump to: navigation, search

Although not open-source nor free as in beer, SlickEdit is a powerful commercial code editor with a built-in symbol tagging and quick code navigation features just to name a few. It is especially well suited for a large-scale C/C++/Java project where the number of source files easily exceeds thousands. This page aims to describe how to set up SlickEdit for optimal hacking experience of OpenOffice.org (OO.o) codebase.

Editor Setup

Code format

Indentation

The OO.o project mandates 4-space indentation & use of whitespace characters for indentation for newly-submitted code. But the legacy code still mostly uses tab characters for indentation. So, you need to set up SlickEdit to properly handle this format.

Go to Tools > Options > File Extension Setup..., and select the extension of c. Select the Indent tab page and set the following options:

  • Change the Indent style to Syntax indent, and set the number to 4.
  • Set the Tabs setting to +4, which sets the tab spacing to every 4 characters.
  • Uncheck the Indent with tabs check box if checked.

The c extension also covers other file extensions that are commonly used for C/C++ sources files, such as cpp, cxx, h, hpp, and hxx, so you don't need to set these options for all of these extensions individually. We also use another extension hrc to manage string resource identifiers. So you should probably add this extension and have it refer to the c extension so that it is treated as a C/C++ extension (to get the syntax highlighting and symbol tagging to work correctly).

Brace style

Although there is no one particular brace style that our project mandates, we generally use BSD style throughout our code base. A BSD style code looks like this:

 if (condition)
 {
     // Do something for this condition....
 }
 else
 {
     // Do something different when the condition is not met...
 }

To set this brace style for the editor so that its various syntax expansion features can set the brace(s) in the right place, go to Tools > Options > File Extension Setup..., select the c extension, click the Options button in the bottom, and set the brace style to Style 2.

Workspace Setup

Setting up workspace and projects

In SlickEdit, projects are organized with the concept of workspace and project, where individual projects go under their parent workspace. In working on the OO.o code base, the recommended way to set up the hacking environment is to create a master workspace first, then register each module as its child project. SlickEdit's built-in symbol database is workspace-wide, so it's important to set up your workspace and projects this way.

Creating a new workspace

From the GUI menu, go to Project > New, and switch to the Workspaces page. There should be only one type of workspace you can choose, Blank workspace, and the location you choose determines where the workspace file and the global symbol database get stored. I recommend setting the workspace location to the root directory of the OO.o code base, where the module directories are located.

For ooo-build, because of its patch-set nature, I recommend you complete the build first, which will create the module directories in build/current. Then create your workspace there.

Adding a new project to the workspace

TODO: fill it.

Copying workspace files

Because of the frequent resyncing of CWS, the workspace for an old milestone becomes obsolete after the resync. I've written a python script to copy the old workspace & project files into a new build tree. The source code for this script is posted below.

#!/usr/bin/env python
# copy_seworkspace.py
 
import sys, os.path, getopt, shutil
 
def debug(msg, abort=True):
    sys.stderr.write(msg+"\n")
    if abort:
        sys.exit(1)
 
def usage():
    # TODO: write a nice usage output here.
    pass
 
class SEWorkspace(object):
 
    @staticmethod
    def visit(instance, dirname, names):
        for name in names:
            if os.path.splitext(name)[1] in ['.vpw', '.vpj']:
                fullpath = dirname + "/" + name
                instance.addSrcWorkspaceFile(fullpath)
 
 
    def __init__(self, srcdir, destdir):
        if not os.path.isdir(srcdir):
            debug(srcdir + " is not a directory")
 
        if not os.path.isdir(destdir):
            debug(destdir + " is not a directory")
 
        self.srcdir = os.path.abspath(srcdir)
        self.destdir = os.path.abspath(destdir)
        self.filelist = []
 
        # Print some useful output.
        print "-"*68
        print "source dir: %s"%self.srcdir
        print "destination dir: %s"%self.destdir
 
 
    def walk(self):
        print "base directory is " + self.srcdir
        # Find all of vpw and vpj files under this path.
        os.path.walk(self.srcdir, SEWorkspace.visit, self)
 
 
    def addSrcWorkspaceFile(self, filepath):
        filepath = os.path.abspath(filepath)
        self.filelist.append(filepath)
        print "adding %s ..."%filepath
 
 
    def copyToDest(self):
        print "-"*68
        print "copying to destination directory ..."
        for srcfile in self.filelist:
            if srcfile.find(self.srcdir) != 0:
                continue
            destfile = srcfile.replace(self.srcdir, self.destdir)
            print "writing %s ..."%destfile
            shutil.copy(srcfile, destfile)
 
        return
 
 
def main(args):
    try:
        opts, args = getopt.getopt(args, "", [])
    except getopt.GetoptError:
        usage()
        sys.exit(1)
 
    if len(args) < 2:
        debug("takes two arguments")
 
    obj = SEWorkspace(args[0], args[1])
    obj.walk()
    obj.copyToDest()
 
 
if __name__=='__main__':
    main(sys.argv[1:])

To use, just run

 ./copy_seworkspace.py [old base dir] [new base dir]

and the script copies all of *.vpw; *.vpj files to the new location while preserving their paths relative to the base directory.

Commands

SlickEdit has quite a number of built-in commands at your disposal. In fact, nearly everything the editor does is a command hence can be accessed from the editor's command line. To activate the command line, simply hit ESC, which moves focus to the input box that appears in the status area. Once the focus moves to the command line box, you can type a command and hit ENTER to execute it.

Useful Commands

xml-beautify

This command beautifies XML content in current buffer. For this command to work, the document mode must be in XML mode.

Custom Macro Commands

One of the strengths of SlickEdit is its extensibility via Slick-C - the built-in macro language. In fact, the vast majority of SlickEdit's high-level features are written in this language. Slick-C looks and behaves like C for the most part, although some parts of the language look a little like REXX from which it was originally modeled.

To code in Slick-C, you need to create a new file with an extension .e, and include at the top [c,N]

  1. include "slick.sh"

which imports built-in functions and constants. To write a new command, the function signature must be preceded by the _command keyword to indicate to the editor that this function is a command. If you are inside SlickEdit, typing _command and hitting space should expand it to a skeleton function.

Once the command is written, all you need to do is load the file so that the command name becomes visible to the editor. To load, either hit F12, or type load in SlickEdit's command line box (hit ESC to activate the command line).

By convention, all underscores in a function name get translated into dashes; if you write a command named do_foo, that command becomes available as do-foo in the command line.

ooo-lxr

This command allows a quick lookup of a symbol name via LXR. To use, activate the command line by hitting ESC, and type ooo-lxr <symbol name> then it will launch a web browser to display the search result.

[c,N] _command void ooo_lxr(_str symbol_name=) name_info(COMMAND_ARG',') {

  _str baseurl = 'http://go-oo.org/lxr/';
  if (symbol_name == ) {
     goto_url(baseurl);
  } else {
     goto_url(baseurl'ident?i='symbol_name, true);
  }

}

ooo-api

This command allows you to quickly jump to the API page of an UNO interfaces/services. To use, run

ooo-api [api name without the leading com.sun.star].

For example, running

ooo-api table.XCellRange

will bring you to the page for com.sun.star.table.XCellRange interface.

[c,N] _command void ooo_api(_str api_name=) name_info(COMMAND_ARG',') {

  _str baseurl = 'http://api.openoffice.org/docs/common/ref/com/sun/star';
  if (api_name == ) {
     goto_url(baseurl'/module-ix.html', true);
  } else {
     _str relurl = stranslate(api_name, '/', '.');
     goto_url(baseurl'/'relurl'.html', true);
  }

}

Macro Variables

The behavior of certain built-in commands may be controlled by a number of global macro variables. To change the value of a macro variable, activate the command line and run set-var, then type the name of the variable whose value you wish to change. Once the name is entered, you can then change its value. If there is an existing value, it gets displayed in the input box.

def_xml_no_schema_list

This is a space-delimited list of extensions for which the editor should not attempt to download the schema upon loading. Note that you must prepend the dot '.' to the extension. This is useful when working with an XML file whose schema file is not at the location specified in the root element. Otherwise you'll get an error message every time you open an XML file.

See Also

Personal tools