From: Michael Orlitzky Date: Sat, 21 Aug 2010 03:51:11 +0000 (-0400) Subject: Updated the last-opening-brace, last-closing-brace, and nagios-calculate-indent funct... X-Git-Tag: v0.3~6 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=nagios-mode.git;a=commitdiff_plain;h=f999f09ae6e3ce6ff8bce49cd40cab6248ca0360 Updated the last-opening-brace, last-closing-brace, and nagios-calculate-indent functions to ignore braces which are commented out. --- diff --git a/nagios-mode.el b/nagios-mode.el index 3774001..22535b5 100644 --- a/nagios-mode.el +++ b/nagios-mode.el @@ -115,12 +115,36 @@ ) +(defun char-is-commented(pos) + "True if the character at position pos is commented, nil otherwise." + (save-excursion + (goto-char pos) + (re-search-backward "#" (beginning-of-line-pos) t) + ) +) + +(defun char-is-commented-and-valid(pos) + "True if the character at position pos is commented and non-nil. + Nil otherwise." + (if (eq nil pos) + nil + (char-is-commented pos) + ) +) + (defun last-opening-brace() - ;; Get the position of the last opening brace, with - ;; respect to the current point. + "Returns the position of the last opening brace, with + respect to the current point. Ignores braces which + are commented out." (save-excursion (let ((lob (re-search-backward "{" nil t))) + + (while (char-is-commented-and-valid lob) + (goto-char lob) + (setq lob (re-search-backward "{" nil t)) + ) + (if lob lob -1) @@ -128,11 +152,19 @@ ) ) + (defun last-closing-brace() - ;; Get the position of the last closing brace, with - ;; respect to the current point. + "Get the position of the last closing brace, with + respect to the current point. Ignores braces which + are commented out." (save-excursion (let ((lcb (re-search-backward "}" nil t))) + + (while (char-is-commented-and-valid lcb) + (goto-char lcb) + (setq lcb (re-search-backward "}" nil t)) + ) + (if lcb lcb -1) @@ -173,12 +205,11 @@ ) ;; Set the indentation level to 0 if we find either brace on this - ;; line. - (if (brace-on-line) - (setq indent 0) + ;; line and. + (if (and (brace-on-line) (not (char-is-commented (brace-on-line)))) + 0 + indent ) - - indent ) )