<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>pnotepad.org forums &#187; Tag: indent - Recent Posts</title>
		<link>http://pnotepad.org/forums/tags/indent</link>
		<description>Programmer&#039;s Notepad Forums</description>
		<language>en-US</language>
		<pubDate>Thu, 09 Feb 2012 07:24:51 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.3</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://pnotepad.org/forums/search.php</link>
		</textInput>
		<atom:link href="http://pnotepad.org/forums/rss/tags/indent" rel="self" type="application/rss+xml" />

		<item>
                        <title>Auto-indentation with PyPN (Wiki article) (kuukkeli)</title>
			<link>http://pnotepad.org/forums/topic/423#post-1503</link>
			<pubDate>Mon, 23 Jun 2008 05:08:01 +0000</pubDate>
			<dc:creator>kuukkeli</dc:creator>
			<guid isPermaLink="false">1503@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;After finishing my first auto-indenter (for TES:Oblivion scripting language) I decided to add an article about auto-indenting to Wiki (&#60;a href=&#34;http://pnotepad.org/docs/howto/automatic_indentation&#34;&#62;http://pnotepad.org/docs/howto/automatic_indentation&#60;/a&#62;). Please, take a look and let me know if it's any good.&#60;/p&#62;
&#60;p&#62;I have a question as well:&#60;/p&#62;
&#60;p&#62;1. How can I upload a .schemedef file to Wiki? It would make sense to have a .schemedef file available for a language the example indenter is used with.
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Three example scripts (from a ex-Nedit convert) (simon)</title>
			<link>http://pnotepad.org/forums/topic/369#post-1308</link>
			<pubDate>Tue, 01 Apr 2008 22:17:21 +0000</pubDate>
			<dc:creator>simon</dc:creator>
			<guid isPermaLink="false">1308@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;The number of spaces/tabs is controlled by your settings, Tools&#124;Options&#124;Defaults:&#60;/p&#62;
&#60;p&#62;[x] Use the tab character&#60;/p&#62;
&#60;p&#62;Tab width: [4]
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Three example scripts (from a ex-Nedit convert) (koen)</title>
			<link>http://pnotepad.org/forums/topic/369#post-1305</link>
			<pubDate>Tue, 01 Apr 2008 09:47:06 +0000</pubDate>
			<dc:creator>koen</dc:creator>
			<guid isPermaLink="false">1305@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;No, I did not know that (about TAB and shift-TAB) :-)&#60;/p&#62;
&#60;p&#62;But still, it only (un-)indents by 4.&#60;/p&#62;
&#60;p&#62;/K
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Three example scripts (from a ex-Nedit convert) (simon)</title>
			<link>http://pnotepad.org/forums/topic/369#post-1304</link>
			<pubDate>Mon, 31 Mar 2008 13:08:11 +0000</pubDate>
			<dc:creator>simon</dc:creator>
			<guid isPermaLink="false">1304@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;Looks pretty impressive to me! There is a problem with the current GetLine and related methods, it'll be fixed in the next release of PyPN.&#60;/p&#62;
&#60;p&#62;Did you know you can indent/unindent text using Tab and Shift-Tab in the editor?
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Three example scripts (from a ex-Nedit convert) (koen)</title>
			<link>http://pnotepad.org/forums/topic/369#post-1303</link>
			<pubDate>Mon, 31 Mar 2008 11:36:33 +0000</pubDate>
			<dc:creator>koen</dc:creator>
			<guid isPermaLink="false">1303@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;I am a recent convert to pn; I used to use Nedit, but I could not stand the bugs it seemed to have on Cygwin anymore.&#60;/p&#62;
&#60;p&#62;In order to try out the Python script plug-in, I implemented the following three Nedit features which I use hundreds of times daily:&#60;/p&#62;
&#60;p&#62;* indent current selection (Ctrl-0 in Nedit)&#60;br /&#62;
  - moves all lines in the current selection one step to the right&#60;br /&#62;
* unindent current selection (Ctrl-9 in Nedit)&#60;br /&#62;
  - moves all lines in the current selection one step to the left&#60;br /&#62;
* format paragraph (Ctrl-J in Nedit)&#60;br /&#62;
  - spread out all words in the current paragraph using maximum line length, and as&#60;br /&#62;
    little lines as possible&#60;/p&#62;
&#60;p&#62;Some approximation of the first two exists already, namely right click on the selection and say Indent/Unindent, but (1) this goes by tab-distance, and (2) no keyboard shortcut can be added.&#60;/p&#62;
&#60;p&#62;In the implementation below, I have also added a function for formatting the current selection. Formatting the current paragraph first selects the current paragraph and then formats it. Since I use LaTeX a lot, the format paragraph implementation tries to identify obvious paragraph separators (such as \begin, \end and so forth).&#60;/p&#62;
&#60;p&#62;The reason for posting these is three-fold:&#60;/p&#62;
&#60;p&#62;1. I wanted to share these scripts with all of you, sort of a pay-back for being allowed to use this great editor :-)&#60;/p&#62;
&#60;p&#62;2. Please provide feedback on my implementation, I am not a Python programmer nor a Scintilla programmer. For example, I am not sure if this code actually works with all possible different newline encodings. (Is there one standard encoding that PN uses internally? That would make this kind of code a lot easier to write...)&#60;/p&#62;
&#60;p&#62;3. I seem not to be able to use the functions GetLine and GetCurLine, so I implemented my own. Is this a bug?&#60;/p&#62;
&#60;p&#62;/Koen&#60;/p&#62;
&#60;p&#62;----&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;import pn
import scintilla
import string
from pypn.decorators import script

def ExpandSelectionToLines():
    &#38;quot;&#38;quot;&#38;quot; Expand the first and last lines of a possibly
        partial selection to the full lines (by Koen) &#38;quot;&#38;quot;&#38;quot;
    editor = scintilla.Scintilla(pn.CurrentDoc())
    selStart = editor.SelectionStart
    selEnd = editor.SelectionEnd
    mx = editor.Length
    # find first character of first line
    while selStart &#38;gt; 0 and editor.GetText(selStart-1,selStart) != &#38;quot;\n&#38;quot;:
        selStart = selStart-1
    # find last character of last line
    while selEnd &#38;lt; mx and (editor.GetText(selEnd-1,selEnd) != &#38;quot;\n&#38;quot; or selStart == selEnd ) and editor.GetText(selEnd-1,selEnd) != &#38;quot;\r&#38;quot;:
        selEnd = selEnd+1
    editor.SetSel(selStart,selEnd)

@script(&#38;quot;Indent&#38;quot;, &#38;quot;Text&#38;quot;)
def Indent():
    &#38;quot;&#38;quot;&#38;quot; Indent the current selection with 1 space (by Koen) &#38;quot;&#38;quot;&#38;quot;
    editor = scintilla.Scintilla(pn.CurrentDoc())
    editor.BeginUndoAction()
    ExpandSelectionToLines()
    selStart = editor.SelectionStart
    selEnd = editor.SelectionEnd

    # find all lines
    lsSelection = editor.GetText(selStart, selEnd)
    laLines = lsSelection.splitlines(0)
    # add a space to the beginning of each line
    for i in range(len(laLines)):
        laLines[i] = &#38;quot; &#38;quot; + laLines[i] + &#38;quot;\n&#38;quot;
    lsReplace = string.join(laLines, &#38;quot;&#38;quot;)
    # replace and augment the selection
    editor.ReplaceSel(lsReplace)
    editor.SetSel(selStart,selEnd+len(laLines))

    editor.EndUndoAction()

@script(&#38;quot;Unindent&#38;quot;, &#38;quot;Text&#38;quot;)
def Unindent():
    &#38;quot;&#38;quot;&#38;quot; Unindent the current selection with 1 space (by Koen) &#38;quot;&#38;quot;&#38;quot;
    editor = scintilla.Scintilla(pn.CurrentDoc())
    editor.BeginUndoAction()
    ExpandSelectionToLines()
    selStart = editor.SelectionStart
    selEnd = editor.SelectionEnd

    # find all lines
    lsSelection = editor.GetText(selStart, selEnd)
    laLines = lsSelection.splitlines(0)
    # remove a space from the beginning of each line
    deleted = 0
    for i in range(len(laLines)):
        if len(laLines[i]) &#38;gt; 0 and laLines[i][0].expandtabs(1).isspace():
            deleted = deleted+1
            laLines[i] = laLines[i][1:len(laLines[i])]
        laLines[i] = laLines[i] + &#38;quot;\n&#38;quot;
    lsReplace = string.join(laLines, &#38;quot;&#38;quot;)
    # replace and shrink the selection
    editor.ReplaceSel(lsReplace)
    editor.SetSel(selStart,selEnd-deleted)

    editor.EndUndoAction()

@script(&#38;quot;Format Selection&#38;quot;, &#38;quot;Text&#38;quot;)
def FormatSelection(m = 78):
    &#38;quot;&#38;quot;&#38;quot; Format current selection (by Koen) &#38;quot;&#38;quot;&#38;quot;
    editor = scintilla.Scintilla(pn.CurrentDoc())
    editor.BeginUndoAction()
    ExpandSelectionToLines()
    selStart = editor.SelectionStart
    selEnd = editor.SelectionEnd

    # find all words
    lsSelection = editor.GetText(selStart, selEnd)
    laWords = lsSelection.rsplit()
    # spread the words out over the lines
    l=0
    laLines = [&#38;quot;&#38;quot;]
    for w in range(len(laWords)):
        if len(laLines[l]) + len(laWords[w]) + 1 &#38;gt; m and len(laLines[l]) &#38;gt; 0:
            laLines[l] = laLines[l][0:-1] + &#38;quot;\n&#38;quot;
            l = l+1
            laLines = laLines + [&#38;quot;&#38;quot;]
        laLines[l] = laLines[l] + laWords[w] + &#38;quot; &#38;quot;
    laLines[l] = laLines[l][0:-1] + &#38;quot;\n&#38;quot;
    # replace the selection with the new lines
    lsReplace = string.join(laLines, &#38;quot;&#38;quot;)
    editor.ReplaceSel(lsReplace)

    editor.EndUndoAction()

def IsSeparator(s):
    &#38;quot;&#38;quot;&#38;quot; Check if s forms a separator between two paragraphs (by Koen) &#38;quot;&#38;quot;&#38;quot;
    if s == &#38;quot;&#38;quot;:
        return True
    if s.startswith(&#38;quot;\\begin{&#38;quot;):
        return True
    if s.startswith(&#38;quot;\\end{&#38;quot;):
        return True
    if s.startswith(&#38;quot;$$&#38;quot;):
        return True
    if s.startswith(&#38;quot;\\[&#38;quot;):
        return True
    if s.startswith(&#38;quot;\\]&#38;quot;):
        return True
    if s.startswith(&#38;quot;%&#38;quot;):
        return True
    if s.expandtabs(1).isspace():
        return True
    return False

def Line(editor,line):
    &#38;quot;&#38;quot;&#38;quot; Implementation of editor.GetLine (which seems broken) (by Koen) &#38;quot;&#38;quot;&#38;quot;
    pos = editor.PositionFromLine(line)
    end = pos
    mx = editor.Length
    while end &#38;lt; mx and editor.GetText(end,end+1) != &#38;quot;\n&#38;quot; and editor.GetText(end,end+1) != &#38;quot;\r&#38;quot;:
        end = end+1
    return editor.GetText(pos,end)

def SelectCurrentParagraph():
    &#38;quot;&#38;quot;&#38;quot; Select current paragraph (By Koen) &#38;quot;&#38;quot;&#38;quot;
    editor = scintilla.Scintilla(pn.CurrentDoc())
    editor.BeginUndoAction()
    mx = editor.LineCount
    here = editor.LineFromPosition(editor.CurrentPos)

    if not IsSeparator(Line(editor,here)):
        # find start of paragraph
        while here &#38;gt; 0 and not IsSeparator(Line(editor,here-1)):
            here = here-1
        selStart = editor.PositionFromLine(here)

        # find end of paragraph
        while here &#38;lt; mx and not IsSeparator(Line(editor,here)):
            here = here+1
        selEnd = editor.PositionFromLine(here)

        editor.SetSel(selStart, selEnd)

@script(&#38;quot;Format Paragraph (width 78)&#38;quot;, &#38;quot;Text&#38;quot;)
def FormatParagraph78():
    &#38;quot;&#38;quot;&#38;quot; Format current paragraph (width 78) (By Koen) &#38;quot;&#38;quot;&#38;quot;
    SelectCurrentParagraph()
    FormatSelection(78)&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
                        <title>Indentation (simon)</title>
			<link>http://pnotepad.org/forums/topic/255#post-970</link>
			<pubDate>Tue, 14 Aug 2007 12:02:37 +0000</pubDate>
			<dc:creator>simon</dc:creator>
			<guid isPermaLink="false">970@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;Working on it ;)
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Indentation (laszlo)</title>
			<link>http://pnotepad.org/forums/topic/255#post-916</link>
			<pubDate>Thu, 19 Jul 2007 14:33:46 +0000</pubDate>
			<dc:creator>laszlo</dc:creator>
			<guid isPermaLink="false">916@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;Hello, &#60;/p&#62;
&#60;p&#62;Is there any way to have indentation like in Scite? Since you use the same control this should not be really hard work.&#60;/p&#62;
&#60;p&#62;I mean something like this:&#60;/p&#62;
&#60;p&#62;public methodName() {&#60;br /&#62;
....some code;&#60;br /&#62;
}&#60;br /&#62;
where .... represents (4 in this case) spaces.&#60;br /&#62;
The default behavior is to follow the indentation of the previous line. But I am kind of used to these kinds of facilities.&#60;/p&#62;
&#60;p&#62;In addition to that auto dedent (i.e. the closing brace to dedent as shown above) would be nice.&#60;/p&#62;
&#60;p&#62;Congratulations for giving us such a great tool!&#60;/p&#62;
&#60;p&#62;Regards,&#60;/p&#62;
&#60;p&#62;Nick
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Formatting - Wish List (simon)</title>
			<link>http://pnotepad.org/forums/topic/137#post-529</link>
			<pubDate>Thu, 23 Nov 2006 21:05:13 +0000</pubDate>
			<dc:creator>simon</dc:creator>
			<guid isPermaLink="false">529@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;I often use astyle for this purpose, a number of other tools even bundle astyle - check it out!
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Formatting - Wish List (dandersahn)</title>
			<link>http://pnotepad.org/forums/topic/137#post-519</link>
			<pubDate>Sat, 18 Nov 2006 19:16:54 +0000</pubDate>
			<dc:creator>dandersahn</dc:creator>
			<guid isPermaLink="false">519@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;It's not too hard to setup an external formatting program with via user tools to format your code.  I have a tool setup to format Java code w/ Jalopy.
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Formatting - Wish List (eepman)</title>
			<link>http://pnotepad.org/forums/topic/137#post-508</link>
			<pubDate>Thu, 09 Nov 2006 21:44:52 +0000</pubDate>
			<dc:creator>eepman</dc:creator>
			<guid isPermaLink="false">508@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;Me too.  I think that would be the perfect fit for someone to write a *ahem* plugin.  It's just waiting for someone to do it.&#60;/p&#62;
&#60;p&#62;I know PN2 gained some popularity from lifehacker. I wonder if one of them could do this?
&#60;/p&#62;</description>
		</item>
		<item>
                        <title>Formatting - Wish List (MikeDawg)</title>
			<link>http://pnotepad.org/forums/topic/137#post-507</link>
			<pubDate>Thu, 09 Nov 2006 13:24:34 +0000</pubDate>
			<dc:creator>MikeDawg</dc:creator>
			<guid isPermaLink="false">507@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;I was curious as to if PN will ever do some formatting of the code.  To make it more clear, and clean, I'd like to see a sort of built-in util that does perltidy against perl, and maybe &#34;indent&#34; against C and C++ files, etc. . .  I'd love to be able to clean up the visual appearance of my code all within PN.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>

