[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

42. Select Syntax-Driven Regions in a Buffer

This is a radically cool, drop in mouse and keyboard-based library for selecting successively bigger syntactical regions within a buffer. Simply load this library and you are ready to try it out by double-clicking on various kinds of characters in different buffer major modes. You'll quickly get the hang of it. (It also provides a command to jump between beginning and end tags within HTML and SGML buffers.)

A great deal of smarts are built-in so that it does the right thing almost all of the time; many other attempts at similar behavior such as `thing.el' fail to deal with many file format complexities.

Double clicks of the Selection Key (left mouse key) at the same point will select bigger and bigger regions with each successive use. The first double click selects a region based upon the character at the point of the click. For example, with the point over an opening or closing grouping character, such as { or }, the whole grouping is selected, e.g. a C function. When on an _ or - within a programming language variable name, the whole name is selected. The type of selection is displayed in the minibuffer as feedback. When using a language based mainly on indenting, like Bourne shell, a double click on the first alpha character of a line, such as an if statement, selects the whole statement.

This whole package is driven by a single function, available in mouse and keyboard forms, that first marks a region based on the syntax category of the character following point. Successive invocations mark larger and larger regions until the whole buffer is marked. See the documentation for the function, id-select-syntactical-region, for the kinds of syntax categories handled.

Loading this package automatically installs its functionality on double-clicks (or higher) of the left mouse key. (See the documentation for the variable, mouse-track-click-hook, for how this is done.) A single click of the left button will remove the region and reset point.

The function, id-select-thing, may be bound to a key to provide the same syntax-driven region selection functionality. C-c C-m is a reasonable site-wide choice since this key is seldom used and it mnemonically indicates marking something. C-c s may be preferred as a personal binding.

Use C-g to unmark the region when done. Use, id-select-thing-with-mouse, if you want to bind this to a mouse key and thereby use single clicks instead of double clicks.

Three other commands are also provided:

mark and copy the syntactical unit to the kill ring

kill the syntactical unit at point

In HTML and SGML modes (actually any listed in the variable, `id-select-markup-modes'), moves point to the start of the tag paired with the closest tag that point is within or which it precedes, so you can quickly jump back and forth between open and close tags.

To autoload this package via mouse usage, add the following line to one of your initialization files:

  (add-hook 'mouse-track-click-hook 'id-select-double-click-hook)

To configure this package, type:

  M-x customize-group RET id-select RET

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on October, 2 2007 using texi2html