1

In my config I have

(bind-keys*
  ("C-<backspace>" . (lambda () (interactive) (kill-line 0))))

which deletes the entire line backwards until column position 0. I would like to only delete backwards until the indentation. How do I have to change this command then?

1 Answer 1

0
(bind-keys* ("C-" . (lambda () (interactive) (back-to-indentation) (kill-line 1))))

Or maybe this is what you really want:

(bind-keys* ("C-" . (lambda ()
                      (interactive)
                      (back-to-indentation)
                      (delete-region (point) (line-end-position)))))

There are several possibilities, depending on whether you want to remove whitespace, newline at the line end, etc., and whether you want to kill or just delete.


(I don't use bind-key*, so I'd use global-set-key or define-key. And I'd define a named command and bind that.)


UPDATE after your comment that says what really you want is to delete only the text from indentation up to the original cursor position:

(bind-keys* ("C-" . (lambda ()
                      (interactive)
                      (let ((opoint  (point)))
                        (back-to-indentation)
                        (delete-region (point) opoint)))))

I don't use bind-keys*. But this is it with normal binding (and naming the command):

(defun my-delete-back-to-indent ()
  (interactive)
  (let ((opoint  (point)))
    (back-to-indentation)
    (delete-region (point) opoint)))

(global-set-key (kbd "C-<backspace>") 'my-delete-back-to-indent)
6
  • had that in use too found it too wordy imho, thanks though
    – CD86
    Dec 18, 2022 at 11:04
  • Maybe I misspoke I want the stuff right of point to persist and not be deleted. How can I achieve this?
    – CD86
    Dec 19, 2022 at 10:32
  • If you want the opposite of what you requested ("delete backwards until the indentation"), this removes the (whitespace) text from bol to the indentation: (delete-region (line-beginning-position) (point)). Is that really what you want, i.e., just to remove all of the indentation?
    – Drew
    Dec 19, 2022 at 15:38
  • what I want is: ----some text and point is here x some more text then if I hit C-<backspace> I want the following result ----x some more text
    – CD86
    Dec 19, 2022 at 17:16
  • I added an example for that.
    – Drew
    Dec 19, 2022 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.