1

How may I call untabify against a rectangular region?

This screenshot illustrates what I am trying to accomplish. I have a messy mixture of tabs and spaces in the region I have circled. untabify will fix it, but I don't want to eliminate the tabs on the left of each line. Those are fine.

enter image description here

  • 1
    Can you elaborate? For instance, you could show an example, and what you'd expect as the result. – user12563 Jun 4 '19 at 20:27
  • @DoMiNeLa10, done. – daveloyall Jun 5 '19 at 15:17
1

The builtin untabify command doesn't support the rectangular region. Here is a new command:

(defun my-untabify (b e)
  "Like `untabify' but support both ordinary and rectangular region."
  (interactive "*r")
  (if (region-noncontiguous-p)
      (apply-on-rectangle
       (lambda (startcol endcol)
         (untabify (progn (move-to-column startcol) (point))
                   (progn (move-to-column endcol) (point))))
       b e)
    (untabify b e current-prefix-arg)))
| improve this answer | |
  • You could contribute your code to Emacs (even better, using region-boundaries so it can even work on non-rectangular non-contiguous regions). – Stefan Jun 4 '19 at 21:15
  • @Stefan How to create a non-rectangular non-contiguous region as a user? Any other emacs commands support such region? In Emacs 26.2, region-bounds is called only two times. – xuchunyang Jun 5 '19 at 3:22
  • region-bounds is new. User-level commands to create a non-contiguous region are still waiting for someone to implement them (presumably the zones.el package in GNU ELPA could be a good starting point). – Stefan Jun 5 '19 at 14:02
  • I finally got around to testing this and LGTM. I'll now go search around to find out how to replace a builtin. Incidentally, I was not aware of the difference between C-SPC and C-x SPC until today. (all the rectangle command I'd tried so far work with regular regions, except the visuals don't match.) – daveloyall Jun 13 '19 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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