Sublime Forum

SublimeBufmod: Simple operations on the text selection

#1

Hey guys,

This package mainly consists of a single convenience command that I created for myself that I have been using daily. Activate the command and an input window pops up, into it you type a python function which takes the variable ‘s’ as the current text selection and returns a string. It then runs the function on all of your active text selections and replaces them.

So, in essence you would type something like this:

return s.strip().upper().center(80)

The command is a little bit hacky as it uses exec() so don’t expect this to be terribly robust :smile:

I also added a simple command to decorate text with a border…

###########
#         #
# Like so #
#         #
###########

The package is available here: github.com/minism/SublimeBufmod

Should be on PackageControl shortly.

0 Likes

#2

I was actually really excited about this because I was hoping to use it for block comments in ASP (vbscript). The problem is Sublime thinks ASP uses html comments () which is totally wrong. Instead, a comment in ASP is just an apostrophe. There are also actually no “block” comments and every line you want to comment out must be prepended with a single quote ’

Your addon helps a lot in that I can execute the bufmod_apply_function_lines function and add in ’ + to comment out several lines. I have to do this a lot though and it will be really useful if you could somehow setup python functions ahead of time and then simply have the appropriate keyboard shortcut fire the command. If you know of any other package that would let me do this or could update yours to have that functionality it would be awesome! I imagine you could even just have like 10 commands that link to custom python functions and they could be mapped at will to whatever keyboard shortcuts the user wants.

Thanks for this addon, for now it at least makes multiple line commenting in ASP possible! I just hope to get it more streamlined.

0 Likes

#3

[quote=“danield”]I was actually really excited about this because I was hoping to use it for block comments in ASP (vbscript). The problem is Sublime thinks ASP uses html comments () which is totally wrong. Instead, a comment in ASP is just an apostrophe. There are also actually no “block” comments and every line you want to comment out must be prepended with a single quote ’

Your addon helps a lot in that I can execute the bufmod_apply_function_lines function and add in ’ + to comment out several lines. I have to do this a lot though and it will be really useful if you could somehow setup python functions ahead of time and then simply have the appropriate keyboard shortcut fire the command. If you know of any other package that would let me do this or could update yours to have that functionality it would be awesome! I imagine you could even just have like 10 commands that link to custom python functions and they could be mapped at will to whatever keyboard shortcuts the user wants.

Thanks for this addon, for now it at least makes multiple line commenting in ASP possible! I just hope to get it more streamlined.[/quote]

Agreed, I find myself doing common operations quite a lot. Perhaps they could be specified in a configuration file for the plugin? Like a list of functions with key mappings? I will have to think about this

0 Likes