I like format all my code using tab instead of space, but I just want to convert spaces to tabs at the beginning of each lines.
Can tabify just convert space to tabs at the beging of lines?
The documentation for tabify
mentions a suitable value for operating on line-leading whitespace only. I used it to write this function which I find handy, but you could just set it in your init file and forego a separate function:
(defun tabify-leading (start end)
"Call `tabify' with `tabify-regexp' set so that only leading
spaces are treated."
(interactive "r")
(setq tabify-regexp-old tabify-regexp)
(unwind-protect
(progn
(setq tabify-regexp "^\t* [ \t]+")
(tabify start end))
(setq tabify-regexp tabify-regexp-old)))
Take a look at SmartTabs
It'll add onto several modes (for several languages) and make it so code indentation are tabs only, while ensuring the display of code is correct regardless of the viewer's tab width.
Excerpt:
- Tabs are only used at the beginning of lines. Everything else, like ASCII art and tables, should be formatted with spaces.
- Tabs are only used for expressing the indentation level. One tab per “block” – any remaining whitespace is spaces only.
Together with this, you can "tabify" existing code using the tabify
command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With