From 5593f28fac6d2aeb909370c4daaa19f419e5d596 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Fri, 6 Mar 2015 16:36:09 -0500 Subject: [PATCH] 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. --- Auxiliary/cmake-mode.el | 58 ++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el index 6e1a23c5c..02f03855f 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