Skip to content

Commit

Permalink
Added file delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Barretto committed Apr 26, 2024
1 parent 2b9c40b commit 584b165
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/howl/buffer.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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: =>
Expand Down
23 changes: 22 additions & 1 deletion lib/howl/commands/file_commands.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 584b165

Please sign in to comment.