diff --git a/lib/howl/buffer.moon b/lib/howl/buffer.moon index aee11d34..c5df827a 100644 --- a/lib/howl/buffer.moon +++ b/lib/howl/buffer.moon @@ -248,7 +248,7 @@ class Buffer extends PropertyObject @_associate_with_file file @save! - rename: (file) => + rename_file: (file) => old_file = @file @_associate_with_file file @save! @@ -257,6 +257,13 @@ class Buffer extends PropertyObject if not status log.warn "Failed to delete old alias #{old_file} for #{@file}: #{err}" + delete_file: (file) => + if @file + status, err = pcall @file\delete + if not status + log.warn "Failed to delete #{@file}: #{err}" + @_associate_with_file nil + as_one_undo: (f) => @_buffer\as_one_undo f undo: => diff --git a/lib/howl/commands/file_commands.moon b/lib/howl/commands/file_commands.moon index 23e6058e..b9dd6497 100644 --- a/lib/howl/commands/file_commands.moon +++ b/lib/howl/commands/file_commands.moon @@ -173,11 +173,32 @@ command.register command.run 'save-as' return - buffer\rename file + buffer\rename_file file buffer.mode = mode.for_file file log.info ("%s: %d lines, %d bytes written")\format buffer.file.basename, #buffer.lines, #buffer +command.register + name: 'delete', + description: 'Delete the file associated with the current buffer' + handler: -> + buffer = app.editor.buffer + if not buffer.file + log.info "Not deleting; buffer not associated with a file" + return + + if buffer.modified_on_disk + overwrite = interact.yes_or_no + prompt: "Buffer '#{buffer}' has changed on disk, delete anyway? " + default: false + unless overwrite + log.info "Not deleting; buffer not saved" + return + + old_name = buffer.file.basename + buffer\delete_file! + log.info ("%s has been deleted")\format old_name + command.register name: 'buffer-close', description: 'Close the current buffer'