Diego Biurrun <[email protected]> writes:

>
> I have the following in my .emacs:
>
>   (setq c-default-style "k&r")
>   (setq-default c-basic-offset 4)
>   (setq-default indent-tabs-mode nil)
>
> I think 4 space indentation with no tabs should also be part of such
> a default emacs setup.

I added some more things to experiment a bit more.
In short now there are two spaces cleanups, the first when the file is
visited and the second before the file is saved.

If after the first cleanup the file gets modified it gets set in
read-only mode, in this way we avoid unrelated changes of spaces with
other changes.

Then when the space change is commited you can do the real work, and
the spaces will be cleaned also before saving (in this case easier).

Let me know if you problems/suggestions...

>From 9fd392d223fac6b4d2f94a57662d7e10b85f35fa Mon Sep 17 00:00:00 2001
From: Andrea Crotti <[email protected]>
Date: Mon, 25 Apr 2011 16:58:30 +0200
Subject: [PATCH] add two hooks to enable smarter spaces handling

---
 .dir-locals.el |   18 ++++++++++++++++++
 .elisp.el      |   21 +++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)
 create mode 100644 .dir-locals.el
 create mode 100644 .elisp.el

diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 0000000..e1c8ac2
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,18 @@
+;;; Directory Local Variables
+;;; See Info node `(emacs) Directory Variables' for more information.
+
+((nil .
+      ((eval . (flyspell-prog-mode))
+       (eval . (when (not (fboundp 'libav-pre-cleanup-buffer))
+                 (load-file ".elisp.el")))
+       (eval .
+             (when (file-exists-p ".custom.el")
+               (load-file ".custom.el")))))
+ (c-mode .
+         ((compile-command . "make -j2")
+          (c-basic-offset . 4)
+          (indent-tabs-mode . nil)
+          (c-indentation-style . "k&r")
+          ;; see .elisp.el for the definition of this function
+          (eval . (add-hook 'find-file-hook 'libav-pre-cleanup-buffer))
+          (eval . (add-hook 'before-save-hook 'libav-cleanup-buffer)))))
diff --git a/.elisp.el b/.elisp.el
new file mode 100644
index 0000000..203f7b1
--- /dev/null
+++ b/.elisp.el
@@ -0,0 +1,21 @@
+(defun libav-untabify-buffer ()
+  "Remove tabs from the buffer"
+  (untabify (point-min) (point-max)))
+
+(defun libav-indent-buffer ()
+  "Reindent the whole buffer"
+  (indent-region (point-min) (point-max)))
+
+(defun libav-cleanup-buffer ()
+  "Clean whitespace status"
+  (message "Cleaning up whitespaces")
+  (indent-buffer)
+  (untabify-buffer)
+  (delete-trailing-whitespace))
+
+(defun libav-pre-cleanup-buffer ()
+  "Clean the whitespaces and set it to read-only if the buffer was changed"
+  (libav-cleanup-buffer)
+  (when (buffer-modified-p)
+    (message "File modified, setting it to read-only, change it back to read-write after committing the white-space changes")
+    (toggle-read-only)))
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to