From: Michael Orlitzky Date: Fri, 20 Aug 2010 20:54:12 +0000 (-0400) Subject: Simplify the nagios-in-block function and eliminate some byte-compiler warnings as... X-Git-Tag: v0.3~18 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=2ecf92ea2cab2a75ac0b620a5efb3ab468c7f528;p=nagios-mode.git Simplify the nagios-in-block function and eliminate some byte-compiler warnings as a side-effect. --- diff --git a/nagios-mode.el b/nagios-mode.el index b9c5faa..5dd7274 100644 --- a/nagios-mode.el +++ b/nagios-mode.el @@ -74,33 +74,39 @@ +(defun last-opening-brace() + ;; Get the position of the last opening brace, with + ;; respect to the current point. + (save-excursion + (let ((lob (re-search-backward "{" nil t))) + (if lob + lob + -1) + ) + ) +) + +(defun last-closing-brace() + ;; Get the position of the last closing brace, with + ;; respect to the current point. + (save-excursion + (let ((lcb (re-search-backward "}" nil t))) + (if lcb + lcb + -1) + ) + ) +) + (defun nagios-in-block() "Determine if the point is inside of a {} block." - (setq pos (point)) - - ;; Get the position of the last opening and closing braces, with - ;; respect to the current point - (setq last-opening-brace (re-search-backward "{" nil t)) - (goto-char pos) - - (setq last-closing-brace (re-search-backward "}" nil t)) - (goto-char pos) - - ;; If either is nil (not found) just set it to -1, so the comparison - ;; doesn't die. - (if (not last-opening-brace) - (setq last-opening-brace -1)) - - (if (not last-closing-brace) - (setq last-closing-brace -1)) - ;; If the last brace seen in the buffer is an opening brace, we're ;; in a block. Otherwise, we aren't. - (if (>= last-closing-brace last-opening-brace) + (if (>= (last-closing-brace) (last-opening-brace)) nil - t) - ) + t) +)