はじめに
テキストエディタ nano で Delphi (Pascal) の構文強調表示 (シンタックスハイライト) をやってみたくなりました。
本記事は『nano for Windows』を対象としています。
構文強調表示
nano で構文強調表示するには設定が必要です。
設定ファイルは .nanorc で、%USERPROFILE% に置く必要があります。テンプレートの .nanorc は『nano for Windows』インストールフォルダにあると思います。
設定
%USERPROFILE%\.nanorc を編集します。次のようになっている行があれば、
## To include most of the existing syntax definitions, you can do:
#include "@PKGDATADIR@/*.nanorc"
アンコメントして、@PKGDATADIR@ の部分を実際のパスに置き換えます。パス区切り文字は ¥ (バックスラッシュ) ではなく / (スラッシュ) にする必要があります。
## To include most of the existing syntax definitions, you can do:
include "c:/nano/syntax/*.nanorc"
これで、syntax フォルダにある *.nanorc が有効になり、構文強調表示されるようになります。
Delphi 用の構文強調表示設定
nano には Delphi (Pascal) 用の設定ファイルは用意されていないので、自前で作る必要があります。ネットを探せばあるにはあるのですが、バージョン互換性の問題なのか、うまく動作しませんでした。
...という事で、自分で書きました。
## Syntax highlighting for Delphi files.
syntax "delphi-dark" "\.pas$" "\.dpr$" "\.dpk$" "\.inc$"
comment "//"
# Reserved Words
icolor brightyellow "\b(and|array|as|asm|begin|break|case|class|const|constructor|destructor|div|do|downto|else|end|except|file|finalization|finally|for|function|goto|if|implementation|in|initialization|inline|interface|is|label|mod|nil|not|of|object|on|or|packed|procedure|program|property|raise|record|repeat|set|shl|shr|string|then|to|try|type|unit|until|uses|var|while|with|xor|private|protected|public|published|automated|strict|read|write|default|nodefault|stored|implements)\b"
# Directives
icolor cyan "\b(absolute|abstract|assembler|cdecl|deprecated|dispid|dynamic|export|external|far|forward|message|name|near|override|overload|pascal|platform|register|reintroduce|safecall|stdcall|virtual)\b"
# Numeric
color brightmagenta "\b[0-9]+(_[0-9]+)*(\.[0-9]+(_[0-9]+)*)?([eE][+-]?[0-9]+(_[0-9]+)*)?\b"
icolor brightmagenta "\$[0-9a-f]+(_[0-9a-f]+)*\b"
icolor brightmagenta "\%[01]+(_[01]+)*\b"
# String
icolor brightblue "'([^']|'')*'"
icolor brightblue "#\$[0-9a-f]+\b"
# Comments
color brightgreen "//.*"
color brightgreen start="\{" end="\}"
color brightgreen start="\(\*" end="\*\)"
# Compiler directives
icolor brightcyan start="\{\$" end="\}"
11 Alexandria で導入された 2 進数リテラルや桁区切りにも対応しています。
おわりに
キーバインドについても %USERPROFILE%\.nanorc を編集する事で変更できます。以下の記述で大体 OK なのですが、〔Ctrl〕+〔V〕が何かとバッティングするようで、うまくペーストできません。
## === Key bindings ===
## For all details, see 'man nanorc', section REBINDING KEYS.
unbind ^N main
#unbind ^U all
unbind ^V all
unbind ^Y all
bind ^C copy main
bind ^F whereis main
bind ^Q exit all
bind ^R replace main
bind ^S savefile main
bind ^V paste all
bind ^X cut main
bind ^Y redo main
bind ^Z undo main
bind F3 findnext main
bind F15 findprevious main
ペーストには元々の〔Ctrl〕+〔U〕が使えます。
もう、Micro でいいんじゃないかなぁ (^^;A
See also:

