From e2c21e666f60debbc4c175bbca7c0c71c3a76bb8 Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Tue, 28 Jan 2003 00:41:35 +0000 Subject: [PATCH] (c-require-final-newline): Made this variable an alist to specify a value for each language. The default value causes `require-final-newline' to be set to t only in languages where the standard requires a final newline. --- lisp/ChangeLog | 8 ++++++++ lisp/progmodes/cc-mode.el | 10 +++++++--- lisp/progmodes/cc-vars.el | 37 ++++++++++++++++++++++++++++++++----- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d2e5ca3fcb2..76befbb5904 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2003-01-28 Martin Stjernholm + + * progmodes/cc-vars.el, progmodes/cc-mode.el + (c-require-final-newline): Made this variable an alist to + specify a value for each language. The default value causes + `require-final-newline' to be set to t only in languages where + the standard requires a final newline. + 2003-01-27 Kim F. Storm * simple.el (kill-new): Improve doc string for yank-handler. diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 5148ff72dea..2073a4a3371 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -299,7 +299,6 @@ ;; these variables should always be buffer local; they do not affect ;; indentation style. - (make-local-variable 'require-final-newline) (make-local-variable 'parse-sexp-ignore-comments) (make-local-variable 'indent-line-function) (make-local-variable 'indent-region-function) @@ -326,8 +325,7 @@ 'c-indent-new-comment-line))) ;; now set their values - (setq require-final-newline c-require-final-newline - parse-sexp-ignore-comments t + (setq parse-sexp-ignore-comments t indent-line-function 'c-indent-line indent-region-function 'c-indent-region outline-regexp "[^#\n\^M]" @@ -337,6 +335,12 @@ comment-start-skip "/\\*+ *\\|//+ *" comment-multi-line t) + ;; Set `require-final-newline' only if we should. + (let ((rfn (assq mode c-require-final-newline))) + (when rfn + (make-local-variable 'require-final-newline) + (setq require-final-newline (cdr rfn)))) + ;; Fix keyword regexps. (c-init-language-vars) diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el index f698065e24d..eb95508f2e3 100644 --- a/lisp/progmodes/cc-vars.el +++ b/lisp/progmodes/cc-vars.el @@ -704,11 +704,38 @@ space." :type 'function :group 'c) -(defcustom c-require-final-newline t - "*Controls whether a final newline is added to the file when saved. -This value is given to `require-final-newline' at mode initialization; -see that variable for details." - :type 'symbol +(defcustom c-require-final-newline + ;; C and C++ mandates that all nonempty files should end with a + ;; newline. Objective-C refers to C for all things it doesn't + ;; specify, so the same holds there. The other languages does not + ;; require it (at least not explicitly in a normative text). + '((c-mode . t) + (c++-mode . t) + (objc-mode . t)) + "*Controls whether a final newline is ensured when the file is saved. +The value is an association list that for each language mode specifies +the value to give to `require-final-newline' at mode initialization; +see that variable for details about the value. If a language isn't +present on the association list, CC Mode won't set +`require-final-newline' in buffers for that language." + :type `(set (cons :format "%v" + (const :format "C " c-mode) + (symbol :format "%v" :value ,require-final-newline)) + (cons :format "%v" + (const :format "C++ " c++-mode) + (symbol :format "%v" :value ,require-final-newline)) + (cons :format "%v" + (const :format "ObjC " objc-mode) + (symbol :format "%v" :value ,require-final-newline)) + (cons :format "%v" + (const :format "Java " java-mode) + (symbol :format "%v" :value ,require-final-newline)) + (cons :format "%v" + (const :format "IDL " idl-mode) + (symbol :format "%v" :value ,require-final-newline)) + (cons :format "%v" + (const :format "Pike " pike-mode) + (symbol :format "%v" :value ,require-final-newline))) :group 'c) (defcustom c-electric-pound-behavior nil -- 2.39.5