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.

Dodgie
  • 462
  • 2
  • 14

1 Answers1

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))))
xuchunyang
  • 14,302
  • 1
  • 18
  • 39