見出し画像

CotEditorで、SakuraEditorの「選択範囲の行頭に引用符を付加する」機能を再現するには

SakuraEditorが羨ましくなる瞬間って、やはり「選択範囲の行頭に引用符を付加して、PasteBoardに出力する」機能が欲しくなる…って時じゃないかしら。
…ということで、CotEditorのGitHubに然様な要望を投げてみた。
→ CotEditor Issues:a selection is copied to the clipboard with quotation marks added at the beginning of selection each line.

We would like the feature where a selection is copied to the clipboard with quotation marks added at the beginning of selection each line, like Sakura Editor.

Sakura Editor に搭載されている様な、選択範囲の各行頭に、引用符を付加した状態で、クリップボードにコピーされる、という機能がCotEditorにも搭載されることを希望します。

https://github.com/coteditor/CotEditor/issues/1366

すると、こんな識者リプライが付いてた。

To keep the user interface clean and minimal, I suppose general text editors like CotEditor should not implement such a very specific feature.

Instead, I recommend writing your own script to realize it. In CotEditor scripting, you can use the keyword %%%{CotEditorXInput= Selection}%%% to obtain the selected text and %%%{CotEditorXOutput= Pasteboardputs}%%% to set modified text to the pasteboard. See the help bundled for the detail of how to script CotEditor.

CotEditorのような一般的なテキストエディタでは、ユーザ・インタフェースをすっきりさせるために、このような特殊な機能は実装しない方が良いと思われます。

その代わり、それを実現するための独自のスクリプトを書くことをお勧めします。CotEditorのスクリプトでは、%%{CotEditorXInput= Selection}%%というキーワードで選択テキストを取得し、%%{CotEditorXOutput= Pasteboardputs}%%で変更テキストをペーストボードにセットすることができます。CotEditor のスクリプトの書き方は、同梱のヘルプを参照してください。

…だって。

えーと。AppleScriptでスクリプトを記述することにして。

スクリプト自身が呼ばれた場合のみ:
 「挿入したい文字列」が nill の場合:
  何もしないで処理終了。

 「選択範囲」が nill の場合:
   何もしないで処理終了。
 「選択範囲」が nill 以外の場合:
   0行目〜最終行迄、下記を繰り返す:
    現在の対象行の、先頭 0 文字目に、指定の「挿入したい文字列」「1バイトの空白文字」を挿入する。
   加工された「選択範囲」を Return する。

…で、実現したいことの骨格が出来上がった、感じ?
…っつーか、これ、AppleScriptで再現できるの?

この記事が気に入ったらサポートをしてみませんか?