WIZARDELF
WIZARDELF

Reputation: 3895

Function to lowercase and concatenate with underscores

I want to change a marked region of text to all lower-case words concatenated by underscores. For example:

A fox caught a bird => a_fox_caught_a_bird

What is the function in Emacs 23?

Upvotes: 1

Views: 166

Answers (1)

Trey Jackson
Trey Jackson

Reputation: 74480

There is no built-in function that does what you want, but this snippet will do the trick.

(defun lower-and-concat (b e)
  (interactive "r")
  (save-restriction
    (narrow-to-region b e)
    (goto-char (point-min))
    (downcase-region b e)
    (while (re-search-forward "[ \t]+" nil t)
      (replace-match "_"))))

Upvotes: 7

Related Questions