5

Is there an Emacs function to delete (forward or backwards) until the first whitespace? For example, I have the following line, and the cursor is marked by the caret:

someword ?(&)!* morewords
               ^

I want to delete the backwards the sequence of non-alphanumeric characters, but not the word someword. Using backward-delete-word will wipe out the word as well. The same is with the cursor before the weird characters and kill-word.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Little Bobby Tables
  • 5,261
  • 2
  • 39
  • 49
  • You know, you have the same happening in almost every text area, try the search field here on Stack for instance... – Patrick Dec 14 '10 at 15:05
  • 1
    True, but I don't write thousands of code and prose lines in search fields. – Little Bobby Tables Dec 14 '10 at 15:11
  • @Little: Well no, I just wanted to point it out. I think it's an interesting question. But the question is if emacs just doesn't conform to "what everyone else does" and as such doesn't provide a logical `kill-word` function. :) – Patrick Dec 14 '10 at 15:15
  • 1
    @Patrick: Obviously it does, but I want it also to do something else, and Emacs has more options than a text field. – Little Bobby Tables Dec 14 '10 at 16:07
  • 2
    The best thing about Emacs -- and this is what the IDE-loving Emacs-haters fail to grasp -- is that you can make Emacs work the way you want instead of having to conform to what is available. – scottfrazer Dec 14 '10 at 17:12
  • @scottfrazer: Of course you can, you can make create functions with lisp, i.e. do anything. It's like extensions or macros to VS, only easier. I didn't say it was impossible, I was just pointing out ...oh, never mind. – Patrick Dec 15 '10 at 09:50
  • @Patrick: My comment wasn't directed at you, just making a general observation :) – scottfrazer Dec 15 '10 at 12:08

2 Answers2

20

emacs has the function zap-to-char which will delete everything up to a specific character. So, this won't work for all whitespace but if your specific problem is everything up to a space you can use this function. Give the function a negative argument to zap backwards.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
3

I don't know of any function, but it's easy enough to make one:

(defun my-delete-backward-to-ws ()
  (interactive)
  (delete-region (point) (save-excursion (skip-syntax-backward "^ ") (point))))
scottfrazer
  • 17,079
  • 4
  • 51
  • 49