Read-only editor


#1

Is there any way to make an editor read-only?


How do I add syntax highlighting to a custom view?
Disabling mini editor
#2

Not that I know of, but that sounds like a good idea …


#3

It is absolutely necessary when opening a read-only file although I need it for a different reason.


#4

Cool idea. It’d be cool if you could get to this from all or any:

  • Tree View
  • Context Menu
  • A button on the tab

#5

Well, no, it’s useful to be able to edit read-only files and save them somewhere else (or elevate your permissions and save over the read-only file anyway).

I actually can’t think of a reason why editing should ever be absolutely forbidden… not that you don’t have one. :slight_smile:


#6

You are right. And actually my need has gone away since my package design
changed.

So ignore this thread.


#7

Are there any updates on this thread or maybe a third party package built to support this?
Would love to have a feature to mark a whole project as read only or making individual editor tabs as readonly by having an option to rightclick on the tab and change its mode.


#8

+1
Read-only tabs are really useful.
Especially when you work with lots of windows - sometimes focus is not where you’re expecting it to be.

Example usage:

  • log viewing
  • peaking on some important configuration file
  • viewing a diff file or diff output (from a plugin?)

…Generally viewing any file that you don’t want to mess in (big files, important files), like sudoers - one mistake and your locked out of sudo.

It is important though to allow turning this on/off for the tab.
While working on an important configuration file I frequently block edition, search, unblock and change a thing, then block again not to mess anything.


#9

You can add the following to your init.coffee or init.js. It adds a command, custom:make-active-editor-readonly, that will turn the active editor into a readonly editor. No option to turn it back off, you’ll have to close the editor. Or hack some more on this :smile:

atom.commands.add('atom-workspace', 'custom:make-active-editor-readonly', () =>
  editor = atom.workspace.getActiveTextEditor()
  editor.onDidChange(() =>
    atom.commands.dispatch(atom.views.getView(editor), 'core:undo');
  )
)

#10

Here’s my case for read-only mode: When working with transpiled languages (CoffeeScript, Moonscript) I often keep the output file side by side with source so I can see the code that’s generated. In the heat of development, It’s all too easy to make changes in the output file resulting in momentary confusion and wasted time.


#11

That’s a great example.


#12

+1
Such a great syntax highlighting editor would be a perfect file viewer for me (to be used with Total Commander)


#13

I needed a way to make editors read-only for a package I’m working on.
I moved the relevant code to a package, so if anyone is still looking for a way to make editors read-only: toggle-read-only.


#14

Another use case is commands like “bundle open”. It’d be really nice to be able to “bundle open faraday” and read the source code without an accidental keystroke changing one of the files in the gem. There are myriad use cases in OSS (both contribution and learning) that could be a little better with a flag on the the command line that would make a window or buffer read-only.