1

Is there a way to configure emacs, so that when I hit M-backspace it would actually remove the whole variable? If I have a variable like my_dummy_variable I need to hit M-backspace three times in order to remove the name?

PythonNut
  • 10,243
  • 2
  • 29
  • 75
eof
  • 91
  • 1

2 Answers2

2

You can use the built-in backward-kill-sexp.

(global-set-key (kbd "M-DEL") 'backward-kill-sexp)

This has the unwanted effect of adding whatever was deleted to the kill ring.

To fix this you can try:

(defun backward-delete-sexp (arg)
     (interactive "P")
     (delete-region (point)
            (progn (backward-sexp arg) (point))))
erjoalgo
  • 853
  • 1
  • 5
  • 18
1

I think you're looking for superword-mode. From its documentation:

Superword mode is a buffer-local minor mode. Enabling it remaps word-based editing commands to superword-based commands that treat symbols as words, e.g. "this_is_a_symbol".

The superword oriented commands activated in this minor mode recognize symbols as superwords to move between superwords and to edit them as words.

Aaron Harris
  • 2,664
  • 17
  • 22