https://packagecontrol.io/packages/Insert%20Nums
or in recent dev builds, you could try using Arithmetic from the Command Palette, but you’ll probably want to look for usage instructions on the relevant build’s thread
You can also do this with XCodeMapper ( requires CodeMap to be installed first )…
Basically you’d type your code or plain-text as you see fit, and in the right / left ( your choice ) side will be the Code - Map panel with the output…
The easiest way to do this is to modify the OnProcessLine callback - basically don’t add any self.AddSyntax calls and only create the class with OnProcessLine which is called for each line… Basically you’d simply return True but use ( may be a different function - I’d need to double check I didn’t remove the global text output otherwise you’d use self.AddEntry into a category and OnCalcDepth return -1 so the text is all left-most ) self.AddOutput( str( _line_number ) + '. ’ + code ) before it… Then disable the CFG var in the file in custom_mappers which displays the “mapping file name with n entries and x lines” code so the only output is your text with line-numbers added…
This option leaves your file unaltered meaning there is no mistake possible…
Instructions on install are here -
It does require some Python knowledge but it should be straight forward…
There are other ways to do what you’re looking for - this way leaves your file sterile and it also caches the file so the file is only processed if the mapper, your file, the configuration files, or the base files have been altered meaning you can go into Packages\User\CodeMap\Cache\ and grab the file directly from there or simply copy and paste from the panel itself…
If you want, I could write up a simple txt extension class which does this and upload it as a default mapper… then you’d only need to install CodeMap then install XCM ( which is a manual install as of now - I’m working on changing that )…
The other options listed by kingkeith will work, but it also means the file is edited and I’m not sure if they will automatically remove / update the line number if a line moves up or down… If it does, it is possible a logic flaw exists which could remove other data - for example if you add a list with numbered items using the same format it is output - they may remove it… With mine there is no chance of that because the code is taken as it is and never changes your default file…
I’ll go ahead and create the .txt variant and upload it today sometime… I’ll try to come back and post a picture when I get to it ( I have some other things to do today ).
CodeMap, by default, adds numbering to the lines… it uses 1: 2: 3: formatting - but it also skips lines which are empty ( that may be what you want or it may not )…
You can easily modify the : to a . by editing the settings file for CodeMap ( Universal Mapper config ) - worst case editing the code_map.py - although that’s unlikely as the settings file does have some of the rules defined there…
I’ll still create a new mapper to replace the default universal mapper one because it provides more control.
##
## Class Callbacks - This is an extension to XCodeMapper which only houses the Callback functions which are meant to be manipulated / edited for each language, or implementation...
##
class XCodeMapper_PlainText_Simple( XCodeMapper_PlainText ):
##
## Important Declarations
##
## Class Name
__name__ = 'XCodeMapper_PlainText_Simple'
##
## Initialize the object - we're adding raw_output_data to the object and that's all - we call super because we want all of the other features enabled ( Caching, etc.. ) without the category system being used...
##
def __init__( self ):
## Contains the output data for this override...
self.raw_output_data = ''
## Fallthrough to the parent so their syntax can be added to our own...
super( ).__init__( )
##
## Callback - Used on each line for the rule-set...
## Note: This is a simple callback so basic info is available only such as the line-number, the code for that line, and the depth of any contents of that line. It is called regardless of comment-status so comment-status is also provided..
##
## Task:
##
def OnProcessLine( self, _line_number, _code, _depth, _in_comment, _in_comment_block ):
##
_code_entry = str( _line_number ) + '. ' + _code
## Only add a new-line when it's needed... ie after the first entry..
if ( self.raw_output_data != '' ):
self.raw_output_data = self.raw_output_data + CFG_NEW_LINE
## Add the data...
self.raw_output_data = self.raw_output_data + _code_entry
## return True to prevent any categorized entries from being used - this is the simple mapper for a reason...
return True
##
## Override the back-end data-processing system - this means instead of using the default system, this will prevent anything from AddSyntax, etc.. from being used - the only text being output is that in __output_data__.. this is essentially a devolution of the system...
##
def ProcessOutput( self, _file, _count, _entries ):
return self.raw_output_data
Never modifies original text so there is never any important text at risk of being deleted or altered - meaning the original file remains sterile
Caches the text-file alterations so the data is only reprocessed when the file data changes, or the back-end files or configuration changes
Cached data is available in: %AppData%\Sublime Text 3\Packages\User\CodeMap\Cache\
Example FileName: C_Users_%UserName%_AppData_Roaming_Sublime_Text_3_Packages_User_CodeMap_examples_TextDocument.txt
Note: I will be adding a method to shorten the file names later - this cached file is what appears in the RIGHT panel and the unaltered / original text is in the left which is available in %AppData%\Sublime Text 3\Packages\User\CodeMap\examples\TextDocument.txt
If the other options don’t work for you - consider this one. Other examples may not require as much for installation, but this addon can do a lot more. Other mods may contaminate the original file by editing it to add the line-numbers and when it comes time to remove them, it may be possible through a typo to lose data which is similar ( unlikely but possible because the original file is being changed )… Additionally, because the original file is altered, editing the file may be cumbersome because new lines added won’t have the numbering so it can be odd to the eyes to look at… With my solution the gutter is always there showing you what will be the result and that can be hidden and can show other information and won’t get in the way when typing or altering a file and if you need to edit data across multiple lines you don’t need to worry about the line-numbers added to the file moving into other lines…