2011-06-22 34 views
2

私は現在、テキストファイルの基本的なASCIIチェックボックスのサポートのためにPythonScriptで非常に簡単なスクリプトを書いています。Notepad ++ Scripting:Newlineを削除するには?

私がAlt + F2を押すと、行がチェックボックスで始まる場合は[]を[x]に、[x]を[]にトグルするか、そうでなければ現在の位置に[]を挿入するという計画です。ほとんど

from Npp import * 
import string 

# If the line starts with [ ] or [x] the script toggles the value between the two possibilites 
# if the line doesn't contains [ ] the script adds the empty box at the current position 
curLine = editor.getCurLine() 
curPos = editor.getCurrentPos() 
curLineNr = editor.lineFromPosition(curPos) 
strippedLine = curLine.lstrip() 

if (strippedLine.startswith('[ ]')): 
    curLine = curLine.replace('[ ]', '[x]', 1).rstrip('\n') 
    editor.replaceWholeLine(curLineNr, curLine) 
    editor.gotoPos(curPos) 
elif (strippedLine.startswith('[x]')): 
    curLine = curLine.replace('[x]', '[ ]', 1).rstrip('\n') 
    editor.replaceWholeLine(curLineNr, curLine) 
    editor.gotoPos(curPos) 
else: 
    editor.addText('[ ] ') 

私が働くスクリプトを書きました

が...しかし、このスクリプトは置き換えエディタ行の後に改行を追加します。非常に愚かな作業arroundは、新しく挿入された行を削除することですが、私は最初にそれを挿入したくないです。

編集:/ これは動作しています。 editor.replaceWholeLineメソッドを使用するだけで、魅力的に機能します。

+1

解決した場合は、自分の質問に答えを投稿してください。次に、解決された問題を考えることができます。 – rafalotufo

答えて

1

editor.replaceWholeLineメソッドをeditor.replaceLineメソッドで使用します。

上記のスクリプトは現在動作します

関連する問題