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.
This commit is contained in:
parent
41d6044bcf
commit
5593f28fac
|
@ -207,12 +207,18 @@ the indentation. Otherwise it retains the same position on the line"
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
|
|
||||||
;;
|
;; Syntax table for this mode.
|
||||||
;; Syntax table for this mode. Initialize to nil so that it is
|
(defvar cmake-mode-syntax-table nil
|
||||||
;; regenerated when the cmake-mode function is called.
|
"Syntax table for CMake mode.")
|
||||||
;;
|
(or cmake-mode-syntax-table
|
||||||
(defvar cmake-mode-syntax-table nil "Syntax table for cmake-mode.")
|
(setq cmake-mode-syntax-table
|
||||||
(setq cmake-mode-syntax-table nil)
|
(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.
|
;; User hook entry point.
|
||||||
|
@ -226,41 +232,23 @@ the indentation. Otherwise it retains the same position on the line"
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
|
|
||||||
;;
|
;; For compatibility with Emacs < 24
|
||||||
;; CMake mode startup function.
|
(defalias 'cmake--parent-mode
|
||||||
|
(if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
|
||||||
|
|
||||||
|
;;------------------------------------------------------------------------------
|
||||||
|
;; Mode definition.
|
||||||
;;
|
;;
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun cmake-mode ()
|
(define-derived-mode cmake-mode cmake--parent-mode "CMake"
|
||||||
"Major mode for editing CMake listfiles."
|
"Major mode for editing CMake source files."
|
||||||
(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)
|
|
||||||
|
|
||||||
; Setup font-lock mode.
|
; Setup font-lock mode.
|
||||||
(make-local-variable 'font-lock-defaults)
|
(set (make-local-variable 'font-lock-defaults) '(cmake-font-lock-keywords))
|
||||||
(setq font-lock-defaults '(cmake-font-lock-keywords))
|
|
||||||
|
|
||||||
; Setup indentation function.
|
; Setup indentation function.
|
||||||
(make-local-variable 'indent-line-function)
|
(set (make-local-variable 'indent-line-function) 'cmake-indent)
|
||||||
(setq indent-line-function 'cmake-indent)
|
|
||||||
|
|
||||||
; Setup comment syntax.
|
; Setup comment syntax.
|
||||||
(make-local-variable 'comment-start)
|
(set (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)))
|
|
||||||
|
|
||||||
; Help mode starts here
|
; Help mode starts here
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue