Removing extra whitespaces on bunch of PHP files using Ack-grep and EmacsAs a follow up to my own post on Indentations: Tabs vs. Spaces, I wanted to cleanup a number of files that contained a lot of extra and useless whitespaces that were getting on my nerves. I did not want to spend too much time on this so, here is what I did. First, here is what I have in my .emacs files that is needed for this to work: (require 'whitespace) (setq-default global-whitespace-mode t) (setq-default whitespace-modes (quote (php-mode c-mode))) (setq whitespace-style (quote (indentation::space trailing lines-tail))) Then I used ack-grep (you can use find . -name '*.php' -exec) and xargs with emacs to clean it all up: ack -f --php project/lib | xargs -L1 -I{} emacs -q -batch {} -eval '(progn(load-file "~/.emacs")(php-mode)(setq c-basic-offset 4)(whitespace-cleanup)(save-buffer))' Here is the explanation: ack -f --php project/lib Finds all files endind with .php .phpt .php3 .php4 .php5 or .phtml (or more if you set it up) and print the file names from the project/lib folder. | xargs -L1 -I{} For every file outputed by ack, one by one execute the command (see below) and replace {} with the filename you get. emacs -q -batch {} The command being executed is emacs which is told NOT to load any init files but run a command in a batch mode (does not start the full editor). -eval '(progn(load-file "~/.emacs")(php-mode)(whitespace-cleanup)(save-buffer))' The emacs command being executed is in fact a set of commands. The first one is to load my .emacs files, then enter in php-mode, remove all the whitespaces and saves the file. DONE References:
|
SearchDrupal ContributionsMake a Payment to Christian Roy |
Post new comment