Difference between revisions of "Editor SlickEdit"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Custom Macro Commands: added ooo-lxr-lookup.)
(Custom Macro Commands)
Line 127: Line 127:
  
 
and the script copies all of *.vpw; *.vpj files to the new location while preserving their paths relative to the base directory.
 
and the script copies all of *.vpw; *.vpj files to the new location while preserving their paths relative to the base directory.
 +
 +
= Useful Commands =
 +
== xml-beautify ==
 +
This command beautifies XML content in current buffer.
  
 
= Custom Macro Commands =
 
= Custom Macro Commands =

Revision as of 18:05, 23 April 2007

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

SlickEdit's built-in symbol database is workspace-wide, so it's important to set up your workspace and projects with this in mind.

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.

[python,N]

  1. !/usr/bin/env python
  2. 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.

Useful Commands

xml-beautify

This command beautifies XML content in current buffer.

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-lookup

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-lookup <symbol name> then it will launch a web browser to display the search result.

[c,N] _command void ooo_lxr_lookup(_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);
  }

}

See Also

Personal tools