Vitor Sessak <[email protected]> writes:
>
> Can you also add an ASM mode? An example of FFmpeg asm formatting can
> be found at libavcodec/x86/fft_mmx.asm.

I'm quite sure that something can be done, but actual the asm-mode tha
is selected by default is not derived from cc-mode.
This implies that all the magic used above (styles and so on) is not
applicable to asm syntax as well.

I'll ask around what can be done anyway, but I guess that a more
powerful mode is necessary to have something better...

I think I fixed the patch I sent before, so please discard it and try
these settings.

I had to introduce a sentinel since the hooks are not so easy to
"localize", I tried in emacs -Q and it seems to work well...

>From 8e83ece5e660fc327eca8a8451904ee5cd92f108 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 |   17 +++++++++++++++++
 .elisp.el      |   27 +++++++++++++++++++++++++++
 2 files changed, 44 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..6fb6d3c
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,17 @@
+;;; 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)
+          ;; sentinel variable
+          (libav-c-mode . t)
+          (c-indentation-style . "k&r"))))
diff --git a/.elisp.el b/.elisp.el
new file mode 100644
index 0000000..9e494c0
--- /dev/null
+++ b/.elisp.el
@@ -0,0 +1,27 @@
+(setq libav-c-mode nil)
+
+(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"
+  (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"
+  (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)))
+
+(add-hook 'find-file-hook 'libav-pre-cleanup-buffer)
+(add-hook 'before-save-hook 'libav-cleanup-buffer)
-- 
1.7.1

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

Reply via email to