 
   selectCmd: ->
     console.log 'Executing command list-edit-select'
-    editor = atom.workspace.getActiveTextEditor()
-    if editor?
-      textBuffer = editor.getBuffer()
-      bufferText = textBuffer.getText()
+    @withSelectedList (editor, textBuffer, bufferText, selectionIxRange, listElements) ->
+      if listElements.length == 0
+        atom.notifications.addWarning 'List selection in empty list.'
+      else
+        [selStart,selEnd] = TextManipulation.getSelectionForRange listElements, selectionIxRange
 
-      selectionIxRange = TextManipulation.getIxRangeForRange textBuffer, (editor.getSelectedBufferRange())
-      listElements = TextManipulation.getListElements bufferText, selectionIxRange[0]
+        if selEnd >= listElements.length
+          atom.notifications.addWarning 'List selection end outside list.'
+          # won't happen for start, since we use this to select the list in the first place
+          # TODO: maybe make this less strict, as selection in sublists is now asymmetric:
+          #       in "[1,[a,b],2]": "[a," selects entire sublist element, but ",b]" fails with warning.
+        else
+          console.log 'selection: ' + selStart + ' <-> ' + selEnd
+          console.log (TextManipulation.getRangeForIxRange textBuffer, [listElements[selStart].eltStart, listElements[selEnd].eltEnd])
 
-      if not listElements?
-        atom.notifications.addWarning 'List selection outside list.'
-      else
-        if listElements.length == 0
-          atom.notifications.addWarning 'List selection in empty list.'
-        else
-          [selStart,selEnd] = TextManipulation.getSelectionForRange listElements, selectionIxRange
-
-          if selEnd >= listElements.length
-            atom.notifications.addWarning 'List selection end outside list.'
-            # won't happen for start, since we use this to select the list in the first place
-            # TODO: maybe make this less strict, as selection in sublists is now asymmetric:
-            #       in "[1,[a,b],2]": "[a," selects entire sublist element, but ",b]" fails with warning.
-          else
-            console.log 'selection: ' + selStart + ' <-> ' + selEnd
-            console.log (TextManipulation.getRangeForIxRange textBuffer, [listElements[selStart].eltStart, listElements[selEnd].eltEnd])
-
-            editor.setSelectedBufferRange(TextManipulation.getRangeForIxRange textBuffer,
-                                          [listElements[selStart].eltStart, listElements[selEnd].eltEnd])
+          editor.setSelectedBufferRange(TextManipulation.getRangeForIxRange textBuffer,
+                                        [listElements[selStart].eltStart, listElements[selEnd].eltEnd])
 
   cutCmd: ->
     console.log 'Executing command list-edit-cut'

  deleteCmd: ->
    console.log 'Executing command list-edit-delete'

# for testing in console:
# Activation from console does not seem to work anymore: > atom.packages.activatePackage('list-edit')
# Access active package (need to activate package manually first)

    #         if last, put post whitespace on previous element

    # Not cut, but some test code to easily visualize ranges
    @withSelectedList (editor, textBuffer, bufferText, selectionIxRange, listElements) ->
      cursorPos = editor.getCursorBufferPosition()
      console.log 'cursor row ' + cursorPos.row + ' col ' + cursorPos.column

      bufferRanges = _.map listElements, (elt) ->
        TextManipulation.getRangeForIxRange textBuffer, [elt.eltStart, elt.eltEnd]
