[Cmake-commits] [cmake-commits] king committed cmake-mode.el 1.33 1.34

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Feb 26 13:28:03 EST 2009


Update of /cvsroot/CMake/CMake/Docs
In directory public:/mounts/ram/cvs-serv7082/Docs

Modified Files:
	cmake-mode.el 
Log Message:
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.


Index: cmake-mode.el
===================================================================
RCS file: /cvsroot/CMake/CMake/Docs/cmake-mode.el,v
retrieving revision 1.33
retrieving revision 1.34
diff -C 2 -d -r1.33 -r1.34
*** cmake-mode.el	11 Mar 2008 14:54:40 -0000	1.33
--- cmake-mode.el	26 Feb 2009 18:28:01 -0000	1.34
***************
*** 103,148 ****
    "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)
  
          (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))
                )
!             (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 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)
            )
          )
--- 103,153 ----
    "Indent current line as CMAKE code."
    (interactive)
    (if (cmake-line-starts-inside-string)
        ()
      (if (bobp)
!         (cmake-indent-line-to 0)
!       (let (cur-indent)
  
          (save-excursion
!           (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))
!                 )
                )
!             (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))
                )
              )
            )
  
          ; Indent this line by the amount selected.
          (if (< cur-indent 0)
!             (cmake-indent-line-to 0)
!           (cmake-indent-line-to cur-indent)
            )
          )
***************
*** 151,154 ****
--- 156,170 ----
    )
  
+ (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))))
+ 
  ;------------------------------------------------------------------------------
  



More information about the Cmake-commits mailing list