diff options
author | Brad King <brad.king@kitware.com> | 2009-02-26 18:28:01 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-02-26 18:28:01 (GMT) |
commit | 8597f01acd94df1287ef9507541bd2c431daf772 (patch) | |
tree | 119bef8f514b0587e67fb31277b718a17749ea2c /Docs | |
parent | 3829be4ca66e79310ef19750e877634169c64431 (diff) | |
download | CMake-8597f01acd94df1287ef9507541bd2c431daf772.zip CMake-8597f01acd94df1287ef9507541bd2c431daf772.tar.gz CMake-8597f01acd94df1287ef9507541bd2c431daf772.tar.bz2 |
BUG: Fix cmake-mode.el indentation cursor motion
This makes cursor motion in the indent function consistent with emacs
conventions. Patch from Mike Wittman. See issue #8625.
Diffstat (limited to 'Docs')
-rw-r--r-- | Docs/cmake-mode.el | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/Docs/cmake-mode.el b/Docs/cmake-mode.el index 624740e..33c2204 100644 --- a/Docs/cmake-mode.el +++ b/Docs/cmake-mode.el @@ -102,54 +102,70 @@ (defun cmake-indent () "Indent current line as CMAKE code." (interactive) - (beginning-of-line) (if (cmake-line-starts-inside-string) () (if (bobp) - (indent-line-to 0) - (let ((point-start (point)) - token cur-indent) + (cmake-indent-line-to 0) + (let (cur-indent) (save-excursion - ; Search back for the last indented line. - (cmake-find-last-indented-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)) - (if (string-match (concat "^" cmake-regex-paren-left "$") token) - (setq cur-indent (+ cur-indent cmake-tab-width)) + (beginning-of-line) + + (let ((point-start (point)) + token) + + ; Search back for the last indented line. + (cmake-find-last-indented-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)) + (if (string-match (concat "^" cmake-regex-paren-left "$") token) + (setq cur-indent (+ cur-indent cmake-tab-width)) + ) + (if (string-match (concat "^" cmake-regex-paren-right "$") token) + (setq cur-indent (- cur-indent cmake-tab-width)) + ) + (if (and + (string-match cmake-regex-block-open token) + (looking-at (concat "[ \t]*" cmake-regex-paren-left)) + ) + (setq cur-indent (+ cur-indent cmake-tab-width)) + ) ) - (if (string-match (concat "^" cmake-regex-paren-right "$") token) + (goto-char point-start) + + ; If this is the end of a block, decrease indentation. + (if (looking-at cmake-regex-block-close) (setq cur-indent (- cur-indent cmake-tab-width)) ) - (if (and - (string-match cmake-regex-block-open token) - (looking-at (concat "[ \t]*" cmake-regex-paren-left)) - ) - (setq cur-indent (+ cur-indent cmake-tab-width)) - ) ) ) - ; If this is the end of a block, decrease indentation. - (if (looking-at cmake-regex-block-close) - (setq cur-indent (- cur-indent cmake-tab-width)) - ) - ; Indent this line by the amount selected. (if (< cur-indent 0) - (indent-line-to 0) - (indent-line-to cur-indent) + (cmake-indent-line-to 0) + (cmake-indent-line-to cur-indent) ) ) ) ) ) +(defun cmake-point-in-indendation () + (string-match "^[ \\t]*$" (buffer-substring (point-at-bol) (point)))) + +(defun cmake-indent-line-to (column) + "Indent the current line to COLUMN. +If point is within the existing indentation it is moved to the end of +the indentation. Otherwise it retains the same position on the line" + (if (cmake-point-in-indendation) + (indent-line-to column) + (save-excursion (indent-line-to column)))) + ;------------------------------------------------------------------------------ ;; |