PascalVKooten
PascalVKooten

Reputation: 21471

Easiest Regexp for words-with-dashes-but-no-whitespace

What is the most convenient regexp for selecting text like "words-with-dashes-but-no-whitespace", when the goal is to select just this but no whitespace?

I used (search-forward-regexp "\\s-") but I believe this could be easier.

I mainly would like this for selecting the word at point including dashes, and using buffer-substring-no-properties to set it as a variable.

EDIT: Answer was given by artscan in a comment. Using (current-word) solves this.

But now this: how to delete this (current-word) including-dashes-that-is?

I use so far (delete-backward-char (string-width (current-word))

Upvotes: 0

Views: 111

Answers (1)

Dmitry
Dmitry

Reputation: 3665

To answer the second question, try:

(let ((bounds (bounds-of-thing-at-point 'symbol)))
   (when bounds
     (delete-region (car bounds) (cdr bounds))))

It's less dependent on point location than (delete-backward-char ...).

Upvotes: 2

Related Questions