How to override core:save and modified indicator?


#1

Hi Guys,

How would I write a plugin that when active overrides core:save? I want to be notified when the user calls core:save but I don’t want Atom to actually write the file to disk, I want to do that myself

On a similar topic: how would I control the little blue circle that indicates that the file has been modified. I want Atom to ask me if the it should draw a little circle or a little X?

Thank you very much.

Carlos


How to override 'save', 'save as' and 'undo' for image editor?
#2

You can use this to disable core from saving the file:

mySaveFile = ->
  # save file to disk

atom.commands.add 'atom-text-editor', 'core:save', (e) ->
  e.preventDefault()
  e.stopPropagation()
  mySaveFile()

Commands are very similar to events, you can read about them in the docs.


#3

That’s done with CSS. When a file is modified, the .modified class is added to the tab element, that’s done here.


#4

Thanks! That is excellent!

I was able to save using the code you posted. I was able to suppress the little blue circle also using the code you linked. Now one final detail that I was not able to figure out is how do I tell Atom to not ask if it should save the file when I close the tab (and my code considers the file saved)?


#5

I’m kind of curious why you’re trying to override the save functionality? What’s wrong with the way it is?


#6

I’m working on a plugin which is Atom a viewport for vim: https://github.com/carlosdcastillo/vim-mode

The handling of the lines that exceed 80 columns differs between both and Atom feels strongly that there has been modification to the file when in fact there hasn’t (long lines is one of many such examples). If I ask Atom to save it will truncate the number of columns, and therefore the save request (and the modified indicators) need to be handled by vim.