Guest User

Untitled

a guest
Jan 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. def foo(bar):
  2. return bar * 2
  3.  
  4. # def foo(bar):
  5. # return bar * 2
  6.  
  7. $<
  8. lines = $PLUMA_SELECTED_TEXT.split("n");
  9. output = "";
  10. for line in lines:
  11. output += "#" + line + "n";
  12.  
  13. return output
  14. >
  15.  
  16. $<
  17. selected_txt = $PLUMA_SELECTED_TEXT
  18. output = ""
  19. for line in selected_txt.split("n"):
  20. line = "#" + line
  21. output = output + line+ "n"
  22.  
  23. return output
  24. >
  25.  
  26. from requests import post # cursor currently here or this line selected
  27. from collections import defaultdict
  28.  
  29. #from requests import post
  30. from collections import defaultdict
  31.  
  32. #from requests import post # both lines selected
  33. from collections import defaultdict
  34.  
  35. from requests import post # both lines selected
  36. #from collections import defaultdict
  37.  
  38. $<
  39. lines = $PLUMA_SELECTED_TEXT.split("n")
  40. if lines == ['']:
  41. # Already commented line ...
  42. if $PLUMA_CURRENT_LINE.startswith("#"):
  43. return $PLUMA_CURRENT_LINE[1:]
  44. else: # ... then uncomment it
  45. return "#" + $PLUMA_CURRENT_LINE
  46. else:
  47. output = "";
  48. for line in lines:
  49. if line.startswith("#"):
  50. output += line[1:] + "n"
  51. else:
  52. output += "#" + line + "n"
  53. return output.rstrip()
  54. >
  55.  
  56. $<
  57. import re
  58.  
  59. def get_lines():
  60. selected = $PLUMA_SELECTED_TEXT
  61. if selected:
  62. return selected
  63. else:
  64. return $PLUMA_CURRENT_LINE
  65.  
  66. def toggle(selected_txt):
  67. lines = []
  68. for line in selected_txt.split("n"):
  69. if not line:
  70. lines.append(line)
  71. continue
  72. try:
  73. spaces, content = re.findall(r'^s+|.+', line)
  74. except:
  75. spaces = ""
  76. content = line
  77.  
  78. if content.startswith("#"):
  79. lines.append("{}{}".format(spaces, content[1:]))
  80. else:
  81. lines.append("{}#{}".format(spaces, content))
  82.  
  83. return "n".join(lines)
  84.  
  85. return toggle(get_lines())
  86. >
Add Comment
Please, Sign In to add comment