1

Called with an active region, it will replace all spaces in that region with the character corresponding to the subsequent key press. E.g., if cover-active-region is bound to C-c /, then C-c / h will replace all spaces (not newlines or anything) in the active region with the letter h.

I suppose this is a simple extension of a command that replace all characters in active region (not just whitespace).

In any case, I'm sure there is a function or idiom for this in Emacs, but I can't seem to find it.

5
  • You're right, @Drew. I've updated the question.
    – Dodgie
    Jan 27, 2018 at 3:07
  • Please explain why the question has been voted down if you're going to vote down.
    – Dodgie
    Jan 27, 2018 at 4:40
  • @Drew, I figured, otherwise you would have voted down before I made the correction. Unless you really hated my correction??
    – Dodgie
    Jan 27, 2018 at 17:57
  • The question is clear now. Thx.
    – Drew
    Jan 28, 2018 at 0:33
  • I was kidding :)
    – Dodgie
    Jan 28, 2018 at 0:33

1 Answer 1

3
(defun cover-active-region (beg end char)
  "Replace space with CHAR in the region."
  (interactive
   (if (use-region-p)
       (list
        (region-beginning)
        (region-end)
        (read-char))
     (user-error "No useable region")))
  (insert
   (replace-regexp-in-string
    " "
    (string char)
    (delete-and-extract-region beg end))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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