"Ronald S. Bultje" <rsbul...@gmail.com> writes:
> Yeah it's still interesting, I like this patch a lot more. :-).

I'm glad it's better now, since there aren't other comments yet I send
another version, c-indentation-style had to be c-file-style.

I also added a couple more variables and commented much more.
I tested it with emacs24 and 23 on ubuntu 10.4 and everything seems to
work as expected, but if anyone tries it and has problems let me know..

>From b856b8b735cc9378d416bd81cfb003639c12d727 Mon Sep 17 00:00:00 2001
From: Andrea Crotti <andrea.crott...@gmail.com>
Date: Thu, 28 Apr 2011 13:17:27 +0200
Subject: [PATCH] suitable default settings for emacs, and a few useful functions to
 manipulate white spaces

---
 tools/emacs/.dir-locals.el |   38 ++++++++++++++++++++++++++++++++++++++
 tools/emacs/elisp.el       |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 0 deletions(-)
 create mode 100644 tools/emacs/.dir-locals.el
 create mode 100644 tools/emacs/elisp.el

diff --git a/tools/emacs/.dir-locals.el b/tools/emacs/.dir-locals.el
new file mode 100644
index 0000000..cd58469
--- /dev/null
+++ b/tools/emacs/.dir-locals.el
@@ -0,0 +1,38 @@
+;; This file contains some compatible setting to the libav policies.
+;; To enable this create a link to this file from the libav root directory:
+;; $ ln -s tools/emacs/.dir-locals.el .dir-locals.el
+;;
+;; After that the first time you visit a buffer in the libav directory
+;; press "!" to allow the settings of these variables without
+;; prompting every time.
+;;
+;; To enable a correct compile command set the LIBAV_DIR to the path
+;; of the libav root directory, and set the MAKEOPTS variable if you
+;; want to pass extra arguments to make. (for example "-jNPROCESSORS")
+;;
+;; load the file tools/emacs/elisp.el for a few additional functions
+
+((c-mode .
+         ((compile-command . (concat "cd $LIBAV_DIR && make -k " (getenv "MAKEOPTS")))
+          (c-basic-offset . 4)
+          (c-file-style . "k&r")
+          ;; don't use tabs
+          (indent-tabs-mode . nil)
+          ;; sentinel variable
+          (libav-c-mode . t)
+          ;; show the trailing whitespaces
+          (show-trailing-whitespace . t)))
+ (asm-mode .
+           ((tab-width . 4)
+            ;; trick to make it indent by 4 on the default asm-mode,
+            ;; gas-mode or asm86-mode are more powerful but not
+            ;; included by default
+            (tab-stop-list . '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80))
+            (indent-tabs-mode . nil)))
+ (diff-mode .
+            ;; enable whitespace minor mode
+            ((mode . whitespace))))
+
+;; evaluate this line or add it to your .emacs to recompile the whole
+;; project with only one key
+;; (global-set-key [f5] 'recompile)
diff --git a/tools/emacs/elisp.el b/tools/emacs/elisp.el
new file mode 100644
index 0000000..e2ad018
--- /dev/null
+++ b/tools/emacs/elisp.el
@@ -0,0 +1,33 @@
+(defun libav-untabify-buffer ()
+  "Remove tabs from the buffer"
+  (interactive)
+  (untabify (point-min) (point-max)))
+
+(defun libav-indent-buffer ()
+  "Reindent the whole buffer"
+  (interactive)
+  (indent-region (point-min) (point-max)))
+
+(defun libav-cleanup-buffer ()
+  "Clean whitespace status"
+  (interactive)
+  (when libav-c-mode
+    (message "Cleaning up whitespaces")
+    (libav-indent-buffer)
+    (libav-untabify-buffer)
+    (delete-trailing-whitespace)))
+
+(defun libav-pre-cleanup-buffer ()
+  "Clean the whitespaces and set it to read-only if the buffer was changed"
+  (interactive)
+  (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)))
+
+;; !! emacs automatic indentation does not give always a desired result, but it's
+;; a good way to start fixing some wrongly indented code
+
+;; uncomment this to enable automatic space cleanup when visiting and before saving
+;; (add-hook 'find-file-hook 'libav-pre-cleanup-buffer)
+;; (add-hook 'before-save-hook 'libav-cleanup-buffer)
-- 
1.7.1

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to