aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2010-07-18 20:28:00 +0000
committerAlan Mackenzie2010-07-18 20:28:00 +0000
commit00af0b67f8a98f8bc11465636eb85451151f5025 (patch)
tree9351053fd345b009f06ca66fcea2662818058fba
parent30c4d8dcb8354549c7de86a827427d0fe96d508e (diff)
downloademacs-00af0b67f8a98f8bc11465636eb85451151f5025.tar.gz
emacs-00af0b67f8a98f8bc11465636eb85451151f5025.zip
Enhance `c-file-style' in file/directory local variables.
cc-mode.el (c-count-cfss): New function. (c-before-hack-hook): Call `c-set-style' differently according to whether c-file-style was set in file or directory local variables.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/progmodes/cc-mode.el21
2 files changed, 28 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7d071d06e6b..c8acb06aba1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12010-07-18 Alan Mackenzie <acm@muc.de>
2
3 Enhance `c-file-style' in file/directory local variables.
4 * cc-mode.el (c-count-cfss): New function.
5 (c-before-hack-hook): Call `c-set-style' differently according to
6 whether c-file-style was set in file or directory local
7 variables.
8
12010-07-18 Michael R. Mauger <mmaug@yahoo.com> 92010-07-18 Michael R. Mauger <mmaug@yahoo.com>
2 10
3 * progmodes/sql.el: Version 2.2. 11 * progmodes/sql.el: Version 2.2.
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index ed769158a50..070d044c199 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -662,6 +662,17 @@ compatible with old code; callers should always specify it."
662 (and (cdr rfn) 662 (and (cdr rfn)
663 (setq require-final-newline mode-require-final-newline))))) 663 (setq require-final-newline mode-require-final-newline)))))
664 664
665(defun c-count-cfss (lv-alist)
666 ;; LV-ALIST is an alist like `file-local-variables-alist'. Count how many
667 ;; elements with the key `c-file-style' there are in it.
668 (let ((elt-ptr lv-alist) elt (cownt 0))
669 (while elt-ptr
670 (setq elt (car elt-ptr)
671 elt-ptr (cdr elt-ptr))
672 (when (eq (car elt) 'c-file-style)
673 (setq cownt (1+ cownt))))
674 cownt))
675
665(defun c-before-hack-hook () 676(defun c-before-hack-hook ()
666 "Set the CC Mode style and \"offsets\" when in the buffer's local variables. 677 "Set the CC Mode style and \"offsets\" when in the buffer's local variables.
667They are set only when, respectively, the pseudo variables 678They are set only when, respectively, the pseudo variables
@@ -678,7 +689,15 @@ This function is called from the hook `before-hack-local-variables-hook'."
678 (delq mode-cons file-local-variables-alist))) 689 (delq mode-cons file-local-variables-alist)))
679 (when stile 690 (when stile
680 (or (stringp stile) (error "c-file-style is not a string")) 691 (or (stringp stile) (error "c-file-style is not a string"))
681 (c-set-style stile)) 692 (if (boundp 'dir-local-variables-alist)
693 ;; Determine whether `c-file-style' was set in the file's local
694 ;; variables or in a .dir-locals.el (a directory setting).
695 (let ((cfs-in-file-and-dir-count
696 (c-count-cfss file-local-variables-alist))
697 (cfs-in-dir-count (c-count-cfss dir-local-variables-alist)))
698 (c-set-style stile
699 (= cfs-in-file-and-dir-count cfs-in-dir-count)))
700 (c-set-style stile)))
682 (when offsets 701 (when offsets
683 (mapc 702 (mapc
684 (lambda (langentry) 703 (lambda (langentry)