Sublime Forum

Field markers in plugins development


Hi guys,
First of all this forum has been of the best help for a new sublime developer. Have gained immense knowledge here.

I had a new query. Just like sublime snippets do we have any option to create field markers in plugins.
I have a plugin where I use a value which I need the user to change as per his/her requirement.

import datetime, getpass
import sublime, sublime_plugin
class LogcurrentCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		rg = self.view.line(self.view.sel()[0])
		self.view.insert(edit, rg.end(), "\n""/**""\n""Task : Task Description")

Please ignore my coding as i am new to this. Let me know if i could improve further as well…

My query is if I can change the Task Description wording as per user requirement just like we can do in snippets.



I’m not entirely sure to have understand your question but it looks like you want to have some constant definition that the user can change …
If this the case then have a look at the Settings documentation : sublime-text-unofficial-document … tings.html

And check this very detailed post: viewtopic.php?f=6&t=9076#p36601



Thanks for your reply.

Well, my query is as below:

After the user runs my code, the output will be as

Now just like snippets where we can use field markers using ‘$’ before Task Description in order for highlighting the text for amendment, do we have a field marker in plugins as well?

Or the other work around could be if I can prompt the user to input the task description information and then i could pass this user value in this code… But i am not sure if this could be done. I was trying the below but wasnt successful.

import datetime, getpass
import sublime, sublime_plugin

class InputtertoolCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		allcontent = sublime.Region(0, self.view.size())
		rg = self.view.line(self.view.sel()[0])
		def callback_function(user_input):
			self.view.insert(edit, rg.end(), {"\n""/**""\n""Task : ": user_input})
		self.view.window().show_input_panel('Enter the Task Description:', 'input', callback_function, None, None)

The above gives an error

Not sure how i could fix this

Hope i am making sense now…



Ok I think I get, you just want to move the cursor after an insert ? This can be done with:

self.view.sel().clear() self.view.sel().add(sublime.Region(rg.a+x1,rg.a+x2)

In your specific case I would use directly the insert_snippet command instead of self.view.insert:

And about why your second run does not run: due to asynch process the edit object is not valid and cannot be passed around function like that (inside your callback here. You need to use a run_command, either an existing one like insert_snippet or one you write yourself where you will have access to a valid edit object.



Great… that worked…

Just a query, would it be possible to have this inserted at a specific line.

eg: if i have an existing piece of information on sublime and i want the plugin to run after the last line, would it be possible to insert this run command at the end of the page???



view.sel().clear() view.sel().add(sublime.Region(view.size(), view.size()) view.run_command("insert_snippet", {"contents": "Your ${1:Snippet} here"})

Or you could use the “move_to” command.



Awesome FichteFoll, that worked like a charm… Thanks all for your help and support