A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label syntax. Show all posts
Showing posts with label syntax. Show all posts

Sublime text editor tricks

Sublime is not a bad text editor for Linux:

Mount a remote directory:  sshfs username@hostname:/remote/path /local/path

Put a vertical line after 80 characters: Preferences > Settings - User > ... add an entry: "rulers": [80]

Change syntax highlighting colours: Preferences > Browse Packages > Color Scheme - Default > ... edit the Color Scheme file you are using.

{
"color_scheme": "Packages/Color Scheme - Default/All Hallow's Eve.tmTheme",
"font_size": 10,
    "rulers": [80],
    "auto_complete": false
}


Shortcuts:

  • Shift-F11 = Enter "concentration" mode AKA "distraction free" mode

Things lacking in Eclipse for Perl

Using EPIC
  • You can't fold code on 'if' blocks, or any arbitrary block (only on subs and perldocs).
  • Word wrap causes the line numbers to be wrong (a single wrapped line has more than one line number)
  • Syntax highlighting is not a perfect fit (perhaps this or these might help):
    • POD and heredoc are both marked as 'Comment2' and so can't be different colours
    • Even though there is a 'Markup' entry, it doesn't seem to be used for POD
    • The colour of dollar signs can't be changed (it's the same as the variable name in vim)
    • Neither variables nor special characters change colour within interpolated strings (as in vim)

A unary-plus sign before a package name in Perl

ok +Some::Package::Foo->a_method_call($var), 'test succeeded';

This is to get around Perl's 'indirect object syntax'.
Otherwise
ok Mock::Basic->update(...);
looks like
Mock::Basic->ok->update(...);
which is probably not what is intended.
ok(Mock::Basic->update(...)); works as well.

It tells the parser "Hi. Since I have a leading (unary) plus sign, I'm now a scalar expression, so I qualify to match the first item in ok()'s prototype; please do not get confused and interpret me as a class name you should call an ok() method on."

Demonstration:
perl -MCGI -MTest::More -e'ok 1, "ok"; ok +CGI->new, +CGI->new; ok scalar CGI->new, "scalar"; ok( CGI->new, "brackets" ); ok CGI->new, "no plus";'
ok 1 - ok
ok 2 - CGI=HASH(0x8b68c0)
ok 3 - scalar
ok 4 - brackets
Undefined subroutine CGI::ok
 at -e line 1

See also, and

What a solitary underscore in Perl means

It represents the previous 'stat' structure, saving a system call.
See: http://perldoc.perl.org/5.8.8/functions/-X.html
and http://perldoc.perl.org/5.8.8/functions/stat.html

Vim features


  • Auto-complete (for Perl files): start typing, then press Ctrl-Shift-P

Eclipse notes

  • File associations are under Preferences | General | Editors | File Associations
  • Background colour is under: Preferences | General | Editors | Text editors 
    • and Preferences | oXygen | Editor
  • Syntax highlighting is under: Preferences | XML | XML Files | Editor | Syntax Coloring
    • and Preferences | oXygen | Editor | Syntax highlighting
  • Eclipse plugins site: http://eclipse-plugins.info/eclipse/
  • How to import/export syntax highlighting colours
  • No word wrap!