module Amun::Behaviours::Erasing

erasing, killing and deleting text from buffer and Emacs keymap for it

Public Instance Methods

backward_delete_char(*) click to toggle source
# File lib/amun/behaviours/erasing.rb, line 23
def backward_delete_char(*)
  return true if buffer.point.zero?

  buffer.point -= 1
  buffer.slice!(buffer.point)
  true
end
backward_kill_word(*) click to toggle source

This should be bound to M-BACKSPACE or M-DEL but I think the terminal doesn't send it So the implementation will remain there until we find a way to catch this key

TODO: should move text to kill ring

# File lib/amun/behaviours/erasing.rb, line 59
def backward_kill_word(*)
  first_letter_backward = buffer.rindex(/\p{L}/, buffer.point) || 0
  first_non_letter_before_word = buffer.rindex(/\P{L}/, first_letter_backward) || -1
  buffer.slice!(first_non_letter_before_word + 1..buffer.point)
  true
end
delete_char(*) click to toggle source
# File lib/amun/behaviours/erasing.rb, line 18
def delete_char(*)
  buffer.slice!(buffer.point)
  true
end
erasing_keymap_initialize() click to toggle source
# File lib/amun/behaviours/erasing.rb, line 5
def erasing_keymap_initialize
  bind "\C-d", self, :delete_char

  # this doesn't work, check linux
  bind Curses::Key::BACKSPACE, self, :backward_delete_char
  # C-? is backspace on mac terminal for some reason
  bind "\C-?", self, :backward_delete_char

  bind Curses::Key::DC, self, :forward_delete_char
  bind "\C-k", self, :kill_line
  bind "\M-d", self, :kill_word
end
forward_delete_char(*) click to toggle source
# File lib/amun/behaviours/erasing.rb, line 31
def forward_delete_char(*)
  delete_char
end
kill_line(*) click to toggle source

TODO: should move text to kill ring

# File lib/amun/behaviours/erasing.rb, line 36
def kill_line(*)
  if buffer[buffer.point] == "\n"
    buffer.slice!(buffer.point)
    return true
  end

  line_end = buffer.index(/$/, buffer.point)
  buffer.slice!(buffer.point, line_end - buffer.point)
  true
end
kill_word(*) click to toggle source

TODO: should move text to kill ring

# File lib/amun/behaviours/erasing.rb, line 48
def kill_word(*)
  first_non_letter = buffer.index(/\P{L}/, buffer.point) || buffer.length
  word_beginning = buffer.index(/\p{L}/, first_non_letter) || buffer.length
  buffer.slice!(buffer.point, word_beginning - buffer.point)
  true
end