;============================================================================= ; ; Program: CMake - Cross-Platform Makefile Generator ; Module: $RCSfile$ ; ; Copyright (c) 2000-$Date$ Kitware, Inc., Insight Consortium. All rights reserved. ; See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. ; ; This software is distributed WITHOUT ANY WARRANTY; without even ; the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ; PURPOSE. See the above copyright notices for more information. ; ;============================================================================= ;;; cmake-mode.el --- major-mode for editing CMake sources ;------------------------------------------------------------------------------ ;;; Commentary: ;; Provides syntax highlighting and indentation for CMakeLists.txt and ;; *.cmake source files. ;; ;; Add this code to your .emacs file to use the mode: ;; ;; (setq load-path (cons (expand-file-name "/dir/with/cmake-mode") load-path)) ;; (require 'cmake-mode) ;; (setq auto-mode-alist ;; (append '(("CMakeLists\\.txt\\'" . cmake-mode) ;; ("\\.cmake\\'" . cmake-mode)) ;; auto-mode-alist)) ;------------------------------------------------------------------------------ ;;; Code: ;; ;; Regular expressions used by line indentation function. ;; (defconst cmake-regex-blank "^[ \t]*$") (defconst cmake-regex-comment "#.*") (defconst cmake-regex-paren-left "(") (defconst cmake-regex-paren-right ")") (defconst cmake-regex-argument-quoted "\"\\([^\"\\\\]\\|\\\\\\(.\\|\n\\)\\)*\"") (defconst cmake-regex-argument-unquoted "\\([^ \t\r\n()#\"\\\\]\\|\\\\.\\)\\([^ \t\r\n()#\\\\]\\|\\\\.\\)*") (defconst cmake-regex-token (concat "\\(" cmake-regex-comment "\\|" cmake-regex-paren-left "\\|" cmake-regex-paren-right "\\|" cmake-regex-argument-unquoted "\\|" cmake-regex-argument-quoted "\\)")) (defconst cmake-regex-indented (concat "^\\(" cmake-regex-token "\\|" "[ \t\r\n]" "\\)*")) (defconst cmake-regex-block-open "^\\(IF\\|MACRO\\|FOREACH\\|ELSE\\|WHILE\\)$") (defconst cmake-regex-block-close "^[ \t]*\\(ENDIF\\|ENDFOREACH\\|ENDMACRO\\|ELSE\\|ENDWHILE\\)[ \t]*(") ;------------------------------------------------------------------------------ ;; ;; Helper functions for line indentation function. ;; (defun cmake-line-starts-inside-string () "Determine whether the beginning of the current line is in a string." (if (save-excursion (beginning-of-line) (let ((parse-end (point))) (beginning-of-buffer) (nth 3 (parse-partial-sexp (point) parse-end)) ) ) t nil ) ) (defun cmake-find-last-indented-line () "Move to the beginning of the last line that has meaningful indentation." (let ((point-start (point)) region) (forward-line -1) (setq region (buffer-substring-no-properties (point) point-start)) (while (and (not (bobp)) (or (looking-at cmake-regex-blank) (not (and (string-match cmake-regex-indented region) (= (length region) (match-end 0)))))) (forward-line -1) (setq region (buffer-substring-no-properties (point) point-start)) ) float LibC1Func() { return 2.0; }