I'm editing tab separated file with Emacs and csv-mode.el. When the document is open, I can align the columns with M-x csv-align-mode. How to make it automatically aligned when I open the file?

Both ~/.emacs and .dir-locals.el based solutions are fine.

I'm pretty new with Emacs so this might be generic elisp question but I'm not sure.

PS. An example of .tsv file


Add (add-hook 'csv-mode-hook 'csv-align-mode) to ~/.emacs and it works. Note: It's csv, not tsv, even though editing .tsv files.

My skills don't yet suffice to make it in .dir-locals.el.

  • 2
    "Note: It's csv, not tsv, even though editing .tsv files." - tsv-mode is derived from csv-mode, which means it will run the hooks in both csv-mode-hook as well as tsv-mode-hook. This means you could also just add it to tsv-mode-hook if you didn't want this to apply to csv files.
    – kfoley
    Sep 15 at 14:58

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.