help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Tip: ide-fix: an IDE formatting fixup function


From: Steinar Bang
Subject: Tip: ide-fix: an IDE formatting fixup function
Date: Tue, 23 Jun 2015 16:28:21 +0200
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (windows-nt)

IDEs are nice in that they can easily navigate code, generate code and
move, copy and reorganize code on a structural basis.

However, they typically suck at formatting.  Formatting is inconsistent
across IDEs, different versions of the same IDE and different modules
inside a particular IDE.

So I've written this small function that I use before committing files
to version control systems.

My workflow, is:
 - Code, refactor and test in an IDE
 - Before committing go to the magit status buffer of the project (I
   mostly just use git these days) and visit all files with changes,
   and:
    - Do `M-x ide-fix RET'
    - If the files get modified, save them

Here's the definition of ide-fix:

(defun ide-fix ()
  "Remove trailing spaces and fix indentation"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (replace-regexp "[ \t]+$" "")
    (indent-region (point-min) (point-max))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]