Skip to content
Robin Haberkorn edited this page Jun 27, 2015 · 25 revisions

Here you can put SciTECO macros that are neither suitable for the macro library that ships with SciTECO, nor for inclusion into the SciTECO language itself. These are typically macros you would add to your SciTECO profile (~/.teco_ini). Nevertheless you will find yourself writing many small macros for everyday use. If you catch yourself copying these macros over and over again, why not share them here?

Some of the macros here might one day grow into a part of the standard library.

When adding a macro to this page, please

  • add a subheading per macro, explaining its parameters and semantics
  • insert the macro as a code block
  • avoid using unprintable characters, i.e. write ^A instead of ASCII code 1, avoid using the default escape string termination, etc.
  • make sure the macro is valid SciTECO code, so it can be pasted into a SciTECO script file directly
  • try to avoid platform-dependencies and undesired side-effects, e.g. the search/replace registers should be backed up if you modify them, etc.

Warning: The macros on this page might require a recent Git revision of SciTECO. The existing SciTECO release is very outdated. In other words, you will have to build SciTECO yourself to use them.

Indent Code Block

The following macro implements indention of code blocks.

  1. The first argument it pops from the stack is the number of lines to indent. Indention is done according to Scintilla's indention policy, i.e. by using SciTECO's ^I command. Empty lines are left empty. Negative values remove one level of indention, handling hard as well as soft tabs. One is implied if the argument is missing.
  2. The second argument is a repeat count (default is 1).

For instance, 10m#it will indent the next 10 lines.

@^U#it{
  "~1'U.i "~1'U.c
  .U.p
  Q.i">
    Q.i<
      0A-10"N 0A-13"N Q.c<@^I//> ''
    :L;>
  |
    -Q.i< Q.c<
      0A-9"=D | @ES/GETTABWIDTH//<0A-^^ "N1;'D> '
    > :L;>
  '
  Q.pJ
}

Copy/Paste from X11 Clipboard

This is a wrapper around the EC and EG commands, allowing you to copy buffer contents into the X11 clipboard or paste the current X11 clipboard at the current position.

It requires the xclip tool to be installed. Your Linux distribution probably has a package for xclip.

  • Without arguments, the current clipboard is pasted
  • With one argument, a range of lines is copied to the clipboard. Two arguments select a character range to be copied into the clipboard. The arguments are passed through to the EG command in case you wonder. This form of the macro does not change the current document.

Naturally, if you copied into the X11 clipboard and rub out the macro call, SciTECO will not restore the previous state of the clipboard.

@^U#xc{ "~
  @EC'xclip -selection clipboard -out'
|
  ! EG will consume arguments on stack !
  @EG.n'xclip -selection clipboard -in >/dev/null'
' }

Skip Function

Jumps to the end of the next "function" - actually just to the end of the next pair of balanced curly braces. This is more or less sufficient in many languages that use curly braces for code blocks.

@^U#sf/ [_ (
  <@S"^E[{,}]" -A-^^{"=1|-'%.n"=1;'>
) ]_ /

Jump to next long line

This macro is useful for finding the next line that exceeds 80 (display) characters - in case you want to break it into smaller lines. It leaves dot at the next best 81st column it finds. Note that Scintilla also allows you to set up visual hints to highlight long lines using SCI_SETEDGEMODE and related messages.

@^U#lc{ 
  <LR .@ES/SCI_GETCOLUMN//-80">
     81,0,.@ES/SCI_LINEFROMPOSITION//@ES/SCI_FINDCOLUMN//J 1;
  ' L>
}

Delete Camel-Cased Word

Deletes the next camel-cased word beginning at the current buffer position. E.g. if dot points to fooBar, it will delete foo.

@^U#nv{
  (<:D; 0A"W1;'>)
}

Compress Command Line

A command-line editing macro that when executed, compresses a sequence of repeating characters at the end of the command-line into a number followed by that character. It rubs out itself in the process. For instance if you have typed cccccccccc and then type m#cm, the c's are compressed to 10c.

@^U#cm{{
  -3D -AU.c <."=1;' -A-Q.c"N1;' -D %.n> Q.n\ Q.c@I//
}}