Permalink
Browse files

sync w/ kate.git

  • Loading branch information...
1 parent bd26af9 commit 495e3a0d95b16235402a5aec8ad4581025d8a437 @zaufi committed Jan 24, 2013
Showing with 70 additions and 113 deletions.
  1. +20 −45 block.py
  2. +29 −53 commentar.py
  3. +11 −14 format.py
  4. +10 −1 tools.py
View
@@ -17,37 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
#
-#
-# Here is a short list of plugins in this file:
-#
-# Insert Char From Line Above (Meta+E)
-# add the same char to the current cursor position as in the line above
-#
-# Insert Char From Line Below (Meta+W)
-# add the same char to the current cursor position as in the line below
-#
-# Kill Text After Cursor (Meta+K)
-# remove text from cursor position to the end of the current line
-#
-# Kill Text Before Cursor (Meta+U)
-# remove text from cursor position to the start of the current line
-# but keep leading spaces (to avoid breaking indentation)
-#
-# Wrap into Braces (Ctrl+'(')
-# wrap current word (identifier) or selection into pair of '(' and ')' characters
-#
-# Wrap into Brackets (Ctrl+{')
-# wrap current word (identifier) or selection into pair of '[' and ']' characters
-#
-# Wrap into Curve Brackets (Meta+{')
-# wrap current word (identifier) or selection into pair of '{' and '}' characters
-#
-# Wrap into Angle Brackets (Ctrl+<')
-# wrap current word (identifier) or selection into pair of '<' and '>' characters
-#
-# Wrap into Quotes (Ctrl+')
-# wrap current word (identifier) or selection into pair of '"' characters
-#
+
+'''Plugins to work with code blocks'''
import kate
import kate.gui
@@ -58,7 +29,7 @@
@kate.action('Insert Char From Line Above', shortcut='Meta+E')
def insertCharFromLineAbove():
- '''add the same char to the current cursor position as in the line above'''
+ '''Add the same char to the current cursor position as at the line above'''
doc = kate.activeDocument()
view = kate.activeView()
pos = view.cursorPosition()
@@ -78,7 +49,7 @@ def insertCharFromLineAbove():
@kate.action('Insert Char From Line Below', shortcut='Meta+W')
def insertCharFromLineBelow():
- '''add the same char to the current cursor position as in the line below'''
+ '''Add the same char to the current cursor position as at the line below'''
doc = kate.activeDocument()
view = kate.activeView()
pos = view.cursorPosition()
@@ -98,7 +69,7 @@ def insertCharFromLineBelow():
@kate.action('Kill Text After Cursor', shortcut='Meta+K')
def killRestOfLine():
- '''remove text from cursor position to the end of the current line'''
+ '''Remove text from cursor position to the end of the current line'''
doc = kate.activeDocument()
view = kate.activeView()
pos = view.cursorPosition()
@@ -113,7 +84,8 @@ def killRestOfLine():
@kate.action('Kill Text Before Cursor', shortcut='Meta+U')
def killLeadOfLine():
- ''' Remove text from a start of a line to the current crsor position
+ ''' Remove text from a start of a line to the current cursor position
+ but keep leading spaces (to avoid breaking indentation)
NOTE This function suppose spaces as indentation character!
TODO Get indent character from config
@@ -142,7 +114,7 @@ def _wrapRange(rangeToWrap, openCh, closeCh, doc = None):
def _wrapBlockWithChar(openCh, closeCh, indentMultiline = True):
- '''Wrap next word or selection (if any) into given open and close chars
+ '''Wrap a current word or selection (if any) into given open and close chars
If current selection is multiline, add one indentation level and put
open/close chars on separate lines
@@ -151,9 +123,6 @@ def _wrapBlockWithChar(openCh, closeCh, indentMultiline = True):
view = kate.activeView()
pos = view.cursorPosition()
- # Try to extend selection to be started from 0 columns at both ends
- common.extendSelectionToWholeLine(view)
-
selectedRange = view.selectionRange()
if selectedRange.isEmpty():
# No text selected. Ok, lets wrap a word where cursor positioned
@@ -173,9 +142,14 @@ def _wrapBlockWithChar(openCh, closeCh, indentMultiline = True):
selectedRange.end().setColumn(selectedRange.end().column() + len(openCh) + len(closeCh))
view.setSelection(selectedRange)
else:
+ # Try to extend selection to be started from 0 columns at both ends
+ common.extendSelectionToWholeLine(view)
+ selectedRange = view.selectionRange()
+
# multiline selection
# 0) extend selection to capture whole lines
gap = ' ' * common.getLineIndentation(selectedRange.start().line(), doc)
+ # TODO Get indent width (and char) from config (get rid of hardcocded '4')
text = gap + openCh + '\n' \
+ '\n'.join([' ' * 4 + line for line in doc.text(selectedRange).split('\n')[:-1]]) \
+ '\n' + gap + closeCh + '\n'
@@ -184,32 +158,33 @@ def _wrapBlockWithChar(openCh, closeCh, indentMultiline = True):
doc.endEditing()
# extend current selection
- selectedRange.end().setColumn(selectedRange.end().column() + len(openCh) + len(closeCh))
r = KTextEditor.Range(selectedRange.start().line(), 0, selectedRange.end().line() + 2, 0)
view.setSelection(r)
@kate.action('Wrap into Braces', shortcut='Ctrl+(')
def wrapBlockWithBraces():
- '''wrap current word (identifier) or selection into pair of '(' and ')' characters'''
+ '''Wrap current word (identifier) or selection into pair of '(' and ')' characters'''
_wrapBlockWithChar('(', ')')
@kate.action('Wrap into Brackets', shortcut='Ctrl+{')
def wrapBlockWithBraces():
- '''wrap current word (identifier) or selection into pair of '[' and ']' characters'''
+ '''Wrap current word (identifier) or selection into pair of '[' and ']' characters'''
_wrapBlockWithChar('[', ']')
@kate.action('Wrap into Curve Brackets', shortcut='Meta+{')
def wrapBlockWithBraces():
- '''wrap current word (identifier) or selection into pair of '{' and '}' characters'''
+ '''Wrap current word (identifier) or selection into pair of '{' and '}' characters'''
_wrapBlockWithChar('{', '}')
@kate.action('Wrap into Angle Brackets', shortcut='Ctrl+<')
def wrapBlockWithBraces():
- '''wrap current word (identifier) or selection into pair of '<' and '>' characters'''
+ '''Wrap current word (identifier) or selection into pair of '<' and '>' characters'''
_wrapBlockWithChar('<', '>')
@kate.action('Wrap into Quotes', shortcut='Ctrl+\'')
def wrapBlockWithBraces():
- '''wrap current word (identifier) or selection into pair of '"' characters'''
+ '''Wrap current word (identifier) or selection into pair of '"' characters'''
_wrapBlockWithChar('"', '"', False)
+
+# kate: indent-width 4;
View
@@ -17,50 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
#
-#
-# Here is a short list of plugins in this file:
-#
-# Inline Comment (Alt+D)
-# put a comment (//) after a code line (at position 60)
-# or just move cursor at comment if already present.
-# If there wasn't any comment aside of #else/#endif put
-# corresponding #if condition as default comment
-#
-# Move Comment Above (Meta+Left)
-# move on-same-line comment (if presnt) to the line above the current
-#
-# Move Comment Inline (Meta+Right)
-# move comment from current line to the line below as
-# on-same-line comment
-#
-# Comment Block (Meta+D)
-# wrap selected text (or current line) into a #if0/#endif block
-#
-# Toggle Comment Block (Meta+Shift+D)
-# switch current code block to ON(#if1)/OFF(#if0) state.
-# Current means that cursor located inside of it.
-#
-# Remove Commented Block (Meta+R)
-# remove #if0 or #if1 and closing #endif around current code block
-# leaving #else part as is
-#
-# Select Current #if0/#if1 Block (Meta+S)
-# set selection of current (where cursor positioned) #if0/#endif block
-#
-# Transform Doxygen Comments (Meta+X)
-# turn block of '///' doxygen comments into
-# /**
-# *
-# */
-# and vise versa
-#
-# Shrink Comment Paragraph (Meta+[)
-# shrink a text paragraph width, whithing a comment, around a current cursor position
-#
-# Extend Comment Paragraph (Meta+])
-# extend a text paragraph width, whithing a comment, around a current cursor position
-#
-#
+
+'''Plugins to work with C++ comments'''
import kate
import kate.gui
@@ -75,7 +33,7 @@
from libkatepate import pred
from libkatepate.pred import neg, all_of, any_of
-
+# TODO Make a configuration page for the following two parameters
COMMENT_POS = 60
COMMENT_THRESHOLD = 50
BLOCK_ANY_START_SEARCH_RE = re.compile('^\s*#\s*if.*$')
@@ -90,12 +48,12 @@ def isApplicableMime():
return str(kate.activeDocument().mimeType()).find('c++') != -1
-#
-# Build a list of tuples (start, end, elseif, is_comment) for all #if/#elseif/#endif blocks
-# in a document. If block contains #endif 3rd element will point its line, -1 otherwise.
-# For blocks #if1/#if0 4th element is True, otherwise False.
-#
def buildIfEndifMap(document):
+ '''
+ Build a list of tuples (start, end, elseif, is_comment) for all #if/#elseif/#endif blocks
+ in a document. If block contains #endif 3rd element will point its line, -1 otherwise.
+ For blocks #if1/#if0 4th element is True, otherwise False.
+ '''
# Make list of ranges of #if*/#endif blocks
openBlockStack = list()
blockRanges = list()
@@ -215,9 +173,11 @@ def processLine(line, commentCh):
@comment_char_must_be_known()
@selection_mode(selection.NORMAL)
def commentar():
- '''Append or align an inlined comment to COMMENT_POS for the current line or the selection.
+ ''' Append or align an inlined comment at position 60 for the current line or the selection.
Move cursor to the start of a comment, if nothing has changed.
+ If there wasn't any comment aside of #else/#endif put corresponding #if condition as default
+ comment text
'''
document = kate.activeDocument()
view = kate.activeView()
@@ -272,8 +232,7 @@ def commentar():
@check_constraints
@comment_char_must_be_known()
def moveAbove():
- '''Move inlined comment before the current line at same align
- '''
+ '''Move an inlined comment before the current line w/ same indentation level'''
document = kate.activeDocument()
view = kate.activeView()
pos = view.cursorPosition()
@@ -399,6 +358,7 @@ def moveInline():
@check_constraints
@restrict_doc_type('C++', 'C++11', 'C++11/Qt4', 'C')
def commentBlock():
+ '''Wrap selected text (or current line) into a #if0/#endif block'''
view = kate.activeView()
# This operation have no sense for partly selected lines
@@ -428,6 +388,10 @@ def commentBlock():
@check_constraints
@restrict_doc_type('C++', 'C++11', 'C++11/Qt4', 'C')
def toggleBlock():
+ ''' Switch a current code block to ON(#if1) or OFF(#if0) state.
+
+ Current means that cursor placed inside of it.
+ '''
document = kate.activeDocument()
view = kate.activeView()
@@ -462,6 +426,7 @@ def toggleBlock():
@check_constraints
@restrict_doc_type('C++', 'C++11', 'C++11/Qt4', 'C')
def removeBlock():
+ ''' Remove a block of code commented with #if0 or #if1-#else'''
document = kate.activeDocument()
view = kate.activeView()
@@ -508,6 +473,7 @@ def removeBlock():
@check_constraints
@restrict_doc_type('C++', 'C++11', 'C++11/Qt4', 'C')
def selectBlock():
+ '''Set selection of a current (where cursor positioned) #if0/#endif block'''
document = kate.activeDocument()
view = kate.activeView()
@@ -626,6 +592,12 @@ def turnFromBlockComment():
@restrict_doc_type('C++', 'C++11', 'C++11/Qt4', 'JavaScript')
@has_selection(False)
def toggleDoxyComment():
+ ''' Turn block of '///' doxygen comments into
+ /**
+ *
+ */
+ and vise versa
+ '''
document = kate.activeDocument()
view = kate.activeView()
pos = view.cursorPosition()
@@ -725,13 +697,15 @@ def changeParagraphWidth(step):
@check_constraints
@restrict_doc_type('C++', 'C++11', 'C++11/Qt4', 'JavaScript')
def shrinkParagraph():
+ '''Shrink a text paragraph width, whithing a comment, around the current cursor position'''
changeParagraphWidth(-1)
@kate.action('Extend Comment Paragraph', shortcut='Meta+]', menu='Edit')
@check_constraints
@restrict_doc_type('C++', 'C++11', 'C++11/Qt4', 'JavaScript')
def extendParagraph():
+ '''Extend a text paragraph width, whithing a comment, around the current cursor position'''
changeParagraphWidth(1)
@@ -750,3 +724,5 @@ def extendParagraph():
#@kate.unload
#def vc4():
#kate.gui.popup("On unload: " + kate.activeDocument().mimeType(), 10)
+
+# kate: indent-width 4;
View
@@ -17,19 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
#
-# Here is a short list of plugins in this file:
-#
-#
-# Boost-like Format Params (Meta+F)
-# Format function's/template's parameters list (or `for`'s) in a boost-like style
-# I.e. when 2nd and the rest parameters has leading comma/semicolon
-# and closing ')' or '>' on a separate line.
-# THIS IS REALLY BETTER TO HAVE SUCH STYLE WHEN U HAVE A LONG PARAMETERS LIST!
-#
-# Unformat Function Params (Meta+Shift+F)
-# merge everything between '(' and ')' into a single line
-#
-#
+
+'''Plugins to work with C++ code formatting'''
import kate
@@ -303,6 +292,11 @@ def boostFormatText(textRange, indent, breakPositions):
@has_selection(False)
@selection_mode(selection.NORMAL)
def boostFormat():
+ '''Format function's/template's parameters list (or `for`'s) in a boost-like style
+ I.e. when 2nd and the rest parameters has leading comma/semicolon
+ and closing ')' or '>' on a separate line.
+ THIS IS REALLY BETTER TO HAVE SUCH STYLE WHEN U HAVE A LONG PARAMETERS LIST!
+ '''
document = kate.activeDocument()
view = kate.activeView()
@@ -357,7 +351,8 @@ def boostUnformatText(textRange, breakPositions):
@check_constraints
@has_selection(False)
@selection_mode(selection.NORMAL)
-def boostFormat():
+def boostUnformat():
+ '''Merge everything between '(' and ')' into a single line'''
document = kate.activeDocument()
view = kate.activeView()
@@ -385,3 +380,5 @@ def boostFormat():
# Going to unformat a text whithin a selected range
text = boostUnformatText(r, breakPositions)
+
+# kate: indent-width 4;
Oops, something went wrong.

0 comments on commit 495e3a0

Please sign in to comment.