Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

##Info: I'm having some issues with a plugin I'm working on. The plugin is for executing functions from macros.

So far; I'm able to open multiple files & manipulate text at each of them, alternating between them arbitrarily by storing view & edit objects at a variable class.

I didn't have any issues until I implemented nested macro calls today. Most functions still work, but it appears that using an edit object will cause an error.

##Resources:

For additional context, see this abbreviated Code Sample.

I also have a pretty detailed post prepared with some pre-release info, but I want to get the nested macros functional & record some demo screencasts before I post it.

##Error Log:

This error log shows the outcome of the following macro sequence:

@ initial document:

  • select all text & copy
  • create new document

@ new document:

  • paste text
  • call inner macro
  • find & select first instance of word_1
  • delete to the end of the document
  • replace all instances of word_2 <------- ERROR_1 Here
  • insert a new line @ end of document
  • return to outer macro
  • replace all instances of word_3 <------- ERROR_2 Here
#▐▌▒▓▒▐▌═══════════════════════▐▌▒▓▒▐▌▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄#
#▐▌▓▒▓▐▌      Start Macro      ▐▌▓▒▓▐▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓#
#▐▌▒▓▒▐▌═══════════════════════▐▌▒▓▒▐▌▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀#

START:  MyCommand.initialize_MacroScript    <sublime.Edit object at 0x000001E546051518>
END:    MyCommand.initialize_MacroScript
START:  MyCommand.select_All                <sublime.Edit object at 0x000001E546051390>
END:    MyCommand.select_All
START:  MyCommand.edit_Copy                 <sublime.Edit object at 0x000001E546051358>
END:    MyCommand.edit_Copy
START:  MyCommand.file_New                  <sublime.Edit object at 0x000001E546051390>
END:    MyCommand.file_New
START:  MyCommand.edit_Paste                <sublime.Edit object at 0x000001E5472D69E8>
END:    MyCommand.edit_Paste

	#▐▌▒▓▒▐▌══════════════════════════════════▐▌▒▓▒▐▌▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄#
	#▐▌▓▒▓▐▌      •   Enter Nested Macro      ▐▌▓▒▓▐▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓#
	#▐▌▒▓▒▐▌══════════════════════════════════▐▌▒▓▒▐▌▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀#

START:  MyCommand.run_Macro                 <sublime.Edit object at 0x000001E545EC5470>

	START:  MyCommand.find_Instance             <sublime.Edit object at 0x000001E545F0A048>
	END:    MyCommand.find_Instance
	START:  MyCommand.delete_Document_Start     <sublime.Edit object at 0x000001E545F0A048>
	END:    MyCommand.delete_Document_Start
	START:  MyCommand.replace_All               <sublime.Edit object at 0x000001E545D18CF8>

	#┌─────┬─────────────────────┬─────┐_____________________________________________________________________________________#
	#│! ! !│    •   ERROR_1      │! ! !│ ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! #
	#└─────┴─────────────────────┴─────┘‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾#

		START:  Functions.ReplaceAll

		Traceback (most recent call last):

			File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 568, in run_
			return self.run(edit, **args)

			File "C:\Users\Fico\AppData\Roaming\Sublime Text 3\Packages\MacroScript\MacroScript.py", line 89, in run
			elif MODE == "replace_All": Functions.replace_All ( QUERY, TEXT, REGEX_ENABLED, IGNORE_CASE )

			File "C:\Users\Fico\AppData\Roaming\Sublime Text 3\Packages\MacroScript\MacroScript.py", line 683, in replace_All
			view.replace ( edit, queryRegion, TEXT )

			File "C:\Program Files\Sublime Text 3\sublime.py", line 707, in replace
			raise ValueError("Edit objects may not be used after the MyCommand's run method has returned")

	# ! ! !     •   "END:  Functions.ReplaceAll" is never reached due to the error      ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !#

	START:  MyCommand.move_Document_End         <sublime.Edit object at 0x000001E54640F7F0>
	END:    MyCommand.move_Document_End
	START:  MyCommand.insert_Line_After         <sublime.Edit object at 0x000001E5465C5CF8>
	END:    MyCommand.insert_Line_After

#▐▌▒▓▒▐▌═════════════════════════════════▐▌▒▓▒▐▌▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄#
#▐▌▓▒▓▐▌      Return To Outer Macro      ▐▌▓▒▓▐▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓#
#▐▌▒▓▒▐▌═════════════════════════════════▐▌▒▓▒▐▌▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀#

END:    MyCommand.runMacro
START:  MyCommand.replace_All               <sublime.Edit object at 0x000001E545D18E48>

#┌─────┬─────────────────┬─────┐_____________________________________________________________________________________________#
#│! ! !│    ERROR_2      │! ! !│ ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! #
#└─────┴─────────────────┴─────┘‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾#

START:  Functions.ReplaceAll

Traceback (most recent call last):

	File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 568, in run_
	return self.run(edit, **args)

	File "C:\Users\Fico\AppData\Roaming\Sublime Text 3\Packages\MacroScript\MacroScript.py", line 89, in run
	elif MODE == "replace_All": Functions.replace_All ( QUERY, TEXT, REGEX_ENABLED, IGNORE_CASE )

	File "C:\Users\Fico\AppData\Roaming\Sublime Text 3\Packages\MacroScript\MacroScript.py", line 683, in replace_All
	view.replace ( edit, queryRegion, TEXT )

	File "C:\Program Files\Sublime Text 3\sublime.py", line 707, in replace
	raise ValueError("Edit objects may not be used after the MyCommand's run method has returned")

# ! ! !     "END:  Functions.ReplaceAll" is never reached due to the error      ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment