Sublime Forum

Read-only Instruction out of the cmd line

#1

Hi Guys,

I am new to sublime text 3. I recently achieved a license and have to say: Keep up the good work.

At the moment, I try to replace an old text editor in a few development tool chains.

Everything works fine so far, because sublime supports to open files and jump to certain column or/and line.

For example: sublime my_file.txt:3

It is possible to jump into the file lines out of the compilation error log.

At the moment, one thing is missing or I didn’t figure it out:

In some cases, I need to open a file read-only out of the console.

Is there any instruction which is similar to the following one:

Sublime –ro my_file:3

Is there way to add this feature.

The editor is used on red hat and linux mint machines (64-Bit).

I am thankful for any advice and

I am looking forward for your answer.

Best regards,

Danny

0 Likes

#2

https://www.sublimetext.com/docs/3/api_reference.html

Example:

    def run(self):
        settings_read_only = sublime.load_resource('Packages/LaTeXTools/LaTeXTools.sublime-settings')
        v = sublime.active_window().new_file()
        v.run_command('append', {'characters': settings_read_only})
        v.set_name('LaTeXTools Settings - Default (read-only)')
        v.set_syntax_file('Packages/JavaScript/JSON.sublime-syntax')
        v.set_scratch(True)
        v.set_read_only(True)
0 Likes

#3

as you have seen, there is no command line option for opening a file in read-only mode. But it is possible to execute ST commands from the command line.

Unfortunately, no built in command exists (that I know of) to make a file read-only, so you’ll need to write/use a plugin to do this. Something like https://packagecontrol.io/packages/ReadonlyProtect may help, and you could then open a file as read-only using:

subl my_file:3 --command toggle_readonly

but due to the way ST works, custom plugin commands run from the commandline may not always work if ST wasn’t already running, because ST might try to execute them before all the plugins have finished loading…

1 Like

#4

Hi,
thanks for the replies.
I used the readonlyprotect package and added a setReadOnly instruction. The toggle commands sometimes caused sublime to jump back into edit mode.
I managed the delay in c-shell in a kind of dirty way:

subl --command ‘set_read_only’ file.txt:line_number
sleep 1
subl --command ‘set_read_only’ file.txt:line_number

It worked for me, but it is not quite a good solution.

Thanks for the replies. I really appreciate it.

Best regards,
danny

0 Likes