Profiler output suggests that forward-match is a bit expensive. Here
is profiler output from the original code, when profiler is wrapped
around tabify-selection:
------------------------------------------------------------------------------------------------------------
loop [34] 0.1%
get-backward-sexp method in ...k/private/racket.rkt:425:2 [28] 99.9%
[37] 50648(61.1%) 0(0.0%) stick-to-next-sexp? method in ...k/private/racket.rkt:425:2 ...
do-forward-match method in ...rk/private/color.rkt:71:2 [50] 99.9%
...
------------------------------------------------------------------------------------------------------------
get-forward-sexp method in ...k/private/racket.rkt:425:2 [38] 17.1%
stick-to-next-sexp? method in ...k/private/racket.rkt:425:2 [37] 82.9%
[50] 61043(73.6%) 53(0.1%) do-forward-match method in ...rk/private/color.rkt:71:2 ...
colorer-driver method in ...rk/private/color.rkt:71:2 [66] 99.8%
match-forward method in paren-tree% [72] 0.1%
------------------------------------------------------------------------------------------------------------
The patch does the prerequisite string matching before calling forward-match.
Reference to dev list: http://lists.racket-lang.org/dev/archive/2012-November/010976.html
Handle close parentheses in a smarter way while in
auto-parens mode and be a little more smart about
inserting brace pairs in general.
In summary:
- Add some "smart-skip" behavior to insert-close-paren,
described in the documentation.
- When auto-parens mode is enabled,
the existing "balance-parens" keybinding invokes
insert-close-paren with a smart-skip argument of
'adjacent
- A new "balance-parens-forward" keybinding invokes
insert-close-paren with a smart-skip argument of
'forward (whether or not auto-parens mode is
enabled)
- Enable basic smart-skip behavior for
strings ("...") and |...| pairs, specifically, typing
a double-quote or bar character when the cursor
immediately precedes one causes the cursor to simply
skip over the existing one
- Tweak auto-insertion of block comment pairs; i.e.
typing hash and a bar results in a properly balanced
#||# pair. Also, when you type a bar character when
the cursor immediately precedes a closing bar and
hash of a comment, then the cursor skips over both
characters (this seems better than having it just
skip over the bar, and then having to introduce a
new keybinding to detect when a hash is typed while
the cursor is between a bar and a hash)
- In strings and line/block comments, auto-parens mode
no longer has any effect (you can still use the M+..
keybindings to force insertion of a particular brace
pair)
- Detect when a character constant is being typed, and
don't insert brace pairs if so; i.e. if the cursor
is immediately after #\ , then typing any open parens,
double quote, or bar, does _not_ result in the
insertion of an open/close pair even in auto-parens
mode
- Add a bunch of tests related to auto-parens, matching
pairs of braces, strings, comments, etc. to
collects/tests/framework/racket.rkt
I started from tabs that are not on the beginning of lines, and in
several places I did further cleanings.
If you're worried about knowing who wrote some code, for example, if you
get to this commit in "git blame", then note that you can use the "-w"
flag in many git commands to ignore whitespaces. For example, to see
per-line authors, use "git blame -w <file>". Another example: to see
the (*much* smaller) non-whitespace changes in this (or any other)
commit, use "git log -p -w -1 <sha1>".
Before this commit, opening collects/drracket/private/unit.rkt required
about 17.5 megabytes of memory and after this commit, it is down to
about 15 megabytes.
The precise measurement I did was to create a frame and a scheme:text%
object in it, record the result of current-memory-use, open the file,
and record current-memory-use again.
For comparison, using a text:standard-style-list% object instead of
the scheme:text% requires only about 4.1 megabytes. One difference
being that there are about 3x more snips (10,204 vs 33,901 (after the
commit)), since we have one snip for each region that has a different
color in the scheme:text version, and the text:standard-style-list has
no colors and thus about two per line (there are 5006 lines in the
file).
double clicking inside a string) and when clicking on close
parentheses (specifically, only special case close parens that are
actually parentheses according to the colorer, rather than special
casing all close parens).