import sublime, sublime_plugin

class SumCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    new_view = self.view.window().new_file()
    new_view.set_name('Sum')
    new_view.insert(edit, 0, '42')
    new_view.set_scratch(True)

import sublime, sublime_plugin

class SumCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    new_view = self.view.window().new_file()
    new_view.set_name('Sum')
    new_view.insert(edit, 0, '42')
    new_view.set_read_only(True)
    new_view.set_scratch(True)

Set new file to read-only
Set new file to read-only

Since the new file does not prompt about file changes when closed, if
the user were to edit the new file and close without saving, their
changes would be lost forever. By setting the new file to be read-only,
the user will not be able to make changes to it that may be lost.

  import sublime, sublime_plugin
  
  class SumCommand(sublime_plugin.TextCommand):
    def run(self, edit):
      new_view = self.view.window().new_file()
      new_view.set_name('Sum')
      new_view.insert(edit, 0, '42')
+     new_view.set_read_only(True)
      new_view.set_scratch(True)
  
Set new file to read-only
## Code Before:
import sublime, sublime_plugin

class SumCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    new_view = self.view.window().new_file()
    new_view.set_name('Sum')
    new_view.insert(edit, 0, '42')
    new_view.set_scratch(True)

## Instruction:
Set new file to read-only
## Code After:
import sublime, sublime_plugin

class SumCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    new_view = self.view.window().new_file()
    new_view.set_name('Sum')
    new_view.insert(edit, 0, '42')
    new_view.set_read_only(True)
    new_view.set_scratch(True)
