summaryrefslogtreecommitdiffstats
path: root/Auxiliary/cmake-mode.el
diff options
context:
space:
mode:
authorRoy Crihfield <rscrihf@gmail.com>2015-03-06 21:36:09 (GMT)
committerBrad King <brad.king@kitware.com>2015-07-27 13:40:54 (GMT)
commit5593f28fac6d2aeb909370c4daaa19f419e5d596 (patch)
treead3d4641d7d41fe427ea82533b30a00b316afa6a /Auxiliary/cmake-mode.el
parent41d6044bcfed908a6197502b038bea86a5ad3526 (diff)
downloadCMake-5593f28fac6d2aeb909370c4daaa19f419e5d596.zip
CMake-5593f28fac6d2aeb909370c4daaa19f419e5d596.tar.gz
CMake-5593f28fac6d2aeb909370c4daaa19f419e5d596.tar.bz2
cmake-mode.el: Derive cmake-mode from prog-mode
Emacs 24 and above support a generic "prog-mode" to simplify definition of programming modes. Derive "cmake-mode" from it since we are a programming mode.
Diffstat (limited to 'Auxiliary/cmake-mode.el')
-rw-r--r--Auxiliary/cmake-mode.el58
1 files changed, 23 insertions, 35 deletions
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el
index 6e1a23c..02f0385 100644
--- a/Auxiliary/cmake-mode.el
+++ b/Auxiliary/cmake-mode.el
@@ -207,12 +207,18 @@ the indentation. Otherwise it retains the same position on the line"
;------------------------------------------------------------------------------
-;;
-;; Syntax table for this mode. Initialize to nil so that it is
-;; regenerated when the cmake-mode function is called.
-;;
-(defvar cmake-mode-syntax-table nil "Syntax table for cmake-mode.")
-(setq cmake-mode-syntax-table nil)
+;; Syntax table for this mode.
+(defvar cmake-mode-syntax-table nil
+ "Syntax table for CMake mode.")
+(or cmake-mode-syntax-table
+ (setq cmake-mode-syntax-table
+ (let ((table (make-syntax-table)))
+ (modify-syntax-entry ?\( "()" table)
+ (modify-syntax-entry ?\) ")(" table)
+ (modify-syntax-entry ?# "<" table)
+ (modify-syntax-entry ?\n ">" table)
+ (modify-syntax-entry ?$ "'" table)
+ table)))
;;
;; User hook entry point.
@@ -226,41 +232,23 @@ the indentation. Otherwise it retains the same position on the line"
;------------------------------------------------------------------------------
-;;
-;; CMake mode startup function.
+;; For compatibility with Emacs < 24
+(defalias 'cmake--parent-mode
+ (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
+
+;;------------------------------------------------------------------------------
+;; Mode definition.
;;
;;;###autoload
-(defun cmake-mode ()
- "Major mode for editing CMake listfiles."
- (interactive)
- (kill-all-local-variables)
- (setq major-mode 'cmake-mode)
- (setq mode-name "CMAKE")
-
- ; Create the syntax table
- (setq cmake-mode-syntax-table (make-syntax-table))
- (set-syntax-table cmake-mode-syntax-table)
- (modify-syntax-entry ?\( "()" cmake-mode-syntax-table)
- (modify-syntax-entry ?\) ")(" cmake-mode-syntax-table)
- (modify-syntax-entry ?# "<" cmake-mode-syntax-table)
- (modify-syntax-entry ?\n ">" cmake-mode-syntax-table)
+(define-derived-mode cmake-mode cmake--parent-mode "CMake"
+ "Major mode for editing CMake source files."
; Setup font-lock mode.
- (make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults '(cmake-font-lock-keywords))
-
+ (set (make-local-variable 'font-lock-defaults) '(cmake-font-lock-keywords))
; Setup indentation function.
- (make-local-variable 'indent-line-function)
- (setq indent-line-function 'cmake-indent)
-
+ (set (make-local-variable 'indent-line-function) 'cmake-indent)
; Setup comment syntax.
- (make-local-variable 'comment-start)
- (setq comment-start "#")
-
- ; Run user hooks.
- (if (boundp 'prog-mode-hook)
- (run-hooks 'prog-mode-hook 'cmake-mode-hook)
- (run-hooks 'cmake-mode-hook)))
+ (set (make-local-variable 'comment-start) "#"))
; Help mode starts here