diff options
Diffstat (limited to 'Auxiliary')
-rw-r--r-- | Auxiliary/cmake-mode.el | 56 | ||||
-rw-r--r-- | Auxiliary/vim/indent/cmake.vim | 48 | ||||
-rw-r--r-- | Auxiliary/vim/syntax/cmake.vim | 4 |
3 files changed, 71 insertions, 37 deletions
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el index ddc7b409bf..8224d9e0b1 100644 --- a/Auxiliary/cmake-mode.el +++ b/Auxiliary/cmake-mode.el @@ -53,6 +53,9 @@ set the path with these commands: (defconst cmake-regex-comment "#.*") (defconst cmake-regex-paren-left "(") (defconst cmake-regex-paren-right ")") +(defconst cmake-regex-closing-parens-line (concat "^[[:space:]]*\\(" + cmake-regex-paren-right + "+\\)[[:space:]]*$")) (defconst cmake-regex-argument-quoted (rx ?\" (* (or (not (any ?\" ?\\)) (and ?\\ anything))) ?\")) (defconst cmake-regex-argument-unquoted @@ -74,6 +77,8 @@ set the path with these commands: (defconst cmake-regex-close (rx-to-string `(and bol (* space) (regexp ,cmake-regex-block-close) (* space) (regexp ,cmake-regex-paren-left)))) +(defconst cmake-regex-token-paren-left (concat "^" cmake-regex-paren-left "$")) +(defconst cmake-regex-token-paren-right (concat "^" cmake-regex-paren-right "$")) ;------------------------------------------------------------------------------ @@ -130,30 +135,47 @@ set the path with these commands: (save-excursion (beginning-of-line) (let ((point-start (point)) + (closing-parens-only (looking-at cmake-regex-closing-parens-line)) (case-fold-search t) ;; case-insensitive token) - ; Search back for the last indented line. + ;; Search back for the last indented line. (cmake-find-last-indented-line) - ; Start with the indentation on this line. + ;; Start with the indentation on this line. (setq cur-indent (current-indentation)) - ; Search forward counting tokens that adjust indentation. - (while (re-search-forward cmake-regex-token point-start t) - (setq token (match-string 0)) - (when (or (string-match (concat "^" cmake-regex-paren-left "$") token) - (and (string-match cmake-regex-block-open token) - (looking-at (concat "[ \t]*" cmake-regex-paren-left)))) - (setq cur-indent (+ cur-indent cmake-tab-width))) - (when (string-match (concat "^" cmake-regex-paren-right "$") token) - (setq cur-indent (- cur-indent cmake-tab-width))) - ) - (goto-char point-start) - ;; If next token closes the block, decrease indentation - (when (looking-at cmake-regex-close) - (setq cur-indent (- cur-indent cmake-tab-width)) + (if closing-parens-only + (let ((open-parens 0)) + (while (re-search-forward cmake-regex-token point-start t) + (setq token (match-string 0)) + (cond + ((string-match cmake-regex-token-paren-left token) + (setq open-parens (+ open-parens 1))) + ((string-match cmake-regex-token-paren-right token) + (setq open-parens (- open-parens 1))))) + ;; Don't outdent if last indented line has open parens + (unless (> open-parens 0) + (setq cur-indent (- cur-indent cmake-tab-width)))) + ;; Skip detailed analysis if last indented line is a 'closing + ;; parens only line' + (unless (looking-at cmake-regex-closing-parens-line) + ;; Search forward counting tokens that adjust indentation. + (while (re-search-forward cmake-regex-token point-start t) + (setq token (match-string 0)) + (when (or (string-match cmake-regex-token-paren-left token) + (and (string-match cmake-regex-block-open token) + (looking-at (concat "[ \t]*" cmake-regex-paren-left)))) + (setq cur-indent (+ cur-indent cmake-tab-width))) + (when (string-match cmake-regex-token-paren-right token) + (setq cur-indent (- cur-indent cmake-tab-width))) + )) + (goto-char point-start) + ;; If next token closes the block, decrease indentation + (when (looking-at cmake-regex-close) + (setq cur-indent (- cur-indent cmake-tab-width)) + ) ) ) ) - ; Indent this line by the amount selected. + ;; Indent this line by the amount selected. (cmake-indent-line-to (max cur-indent 0)) ) ) diff --git a/Auxiliary/vim/indent/cmake.vim b/Auxiliary/vim/indent/cmake.vim index f7ab24a5d0..672bdccc46 100644 --- a/Auxiliary/vim/indent/cmake.vim +++ b/Auxiliary/vim/indent/cmake.vim @@ -3,7 +3,7 @@ " Author: Andy Cedilnik <andy.cedilnik@kitware.com> " Maintainer: Dimitri Merejkowsky <d.merej@gmail.com> " Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com> -" Last Change: 2017 Aug 30 +" Last Change: 2022 Mar 22 " " License: The CMake license applies to this file. See " https://cmake.org/licensing @@ -14,9 +14,6 @@ if exists("b:did_indent") endif let b:did_indent = 1 -let s:keepcpo= &cpo -set cpo&vim - setlocal indentexpr=CMakeGetIndent(v:lnum) setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE( @@ -24,6 +21,8 @@ setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE( if exists("*CMakeGetIndent") finish endif +let s:keepcpo= &cpo +set cpo&vim fun! CMakeGetIndent(lnum) let this_line = getline(a:lnum) @@ -54,32 +53,41 @@ fun! CMakeGetIndent(lnum) let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier . \ '\s*(' . cmake_regex_arguments . \ '\(' . cmake_regex_comment . '\)\?$' - let cmake_indent_close_regex = '^' . cmake_regex_arguments . \ ')\s*' . \ '\(' . cmake_regex_comment . '\)\?$' + let cmake_closing_parens_line = '^\s*\()\+\)\s*$' + let cmake_indent_begin_regex = '^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*(' let cmake_indent_end_regex = '^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*(' - " Add - if previous_line =~? cmake_indent_comment_line " Handle comments - let ind = ind - else - if previous_line =~? cmake_indent_begin_regex - let ind = ind + shiftwidth() + if this_line =~? cmake_closing_parens_line + if previous_line !~? cmake_indent_open_regex + let ind = ind - shiftwidth() endif - if previous_line =~? cmake_indent_open_regex - let ind = ind + shiftwidth() + else + " Add + if previous_line =~? cmake_indent_comment_line " Handle comments + let ind = ind + else + if previous_line =~? cmake_indent_begin_regex + let ind = ind + shiftwidth() + endif + if previous_line =~? cmake_indent_open_regex + let ind = ind + shiftwidth() + endif endif - endif - " Subtract - if this_line =~? cmake_indent_end_regex - let ind = ind - shiftwidth() - endif - if previous_line =~? cmake_indent_close_regex - let ind = ind - shiftwidth() + " Subtract + if this_line =~? cmake_indent_end_regex + let ind = ind - shiftwidth() + endif + if previous_line !~? cmake_closing_parens_line + if previous_line =~? cmake_indent_close_regex + let ind = ind - shiftwidth() + endif + endif endif return ind diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim index d5361bd326..877344661a 100644 --- a/Auxiliary/vim/syntax/cmake.vim +++ b/Auxiliary/vim/syntax/cmake.vim @@ -370,6 +370,7 @@ syn keyword cmakeProperty contained \ VS_DOTNET_DOCUMENTATION_FILE \ VS_DOTNET_REFERENCES \ VS_DOTNET_REFERENCES_COPY_LOCAL + \ VS_DOTNET_STARTUP_OBJECT \ VS_DOTNET_TARGET_FRAMEWORK_VERSION \ VS_DPI_AWARE \ VS_GLOBAL_KEYWORD @@ -381,6 +382,7 @@ syn keyword cmakeProperty contained \ VS_JUST_MY_CODE_DEBUGGING \ VS_KEYWORD \ VS_MOBILE_EXTENSIONS_VERSION + \ VS_NO_COMPILE_BATCHING \ VS_NO_SOLUTION_DEPLOY \ VS_PACKAGE_REFERENCES \ VS_PLATFORM_TOOLSET @@ -704,6 +706,7 @@ syn keyword cmakeVariable contained \ CMAKE_CODEBLOCKS_COMPILER_ID \ CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES \ CMAKE_CODELITE_USE_TARGETS + \ CMAKE_COLOR_DIAGNOSTICS \ CMAKE_COLOR_MAKEFILE \ CMAKE_COMMAND \ CMAKE_COMPILER_2005 @@ -1572,6 +1575,7 @@ syn keyword cmakeVariable contained \ CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS \ CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS \ CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE + \ CTEST_CUSTOM_TEST_OUTPUT_TRUNCATION \ CTEST_CUSTOM_MEMCHECK_IGNORE \ CTEST_CUSTOM_POST_MEMCHECK \ CTEST_CUSTOM_POST_TEST |