comparison lisp/textmodes/tex-mode.el @ 78842:675e2e2bd67c

(tex-validate-buffer): Use paragraph motion functions, rather than hard-coding "\n\n". (tex-validate-region): Check for eobp, to speed up. (tex-next-unmatched-end): Doc fix.
author Glenn Morris <rgm@gnu.org>
date Thu, 20 Sep 2007 03:06:38 +0000
parents f4f2cb314448
children 50711e81a122
comparison
equal deleted inserted replaced
78841:39ce41a319b4 78842:675e2e2bd67c
1161 ;; This won't actually work...Really, this whole thing should 1161 ;; This won't actually work...Really, this whole thing should
1162 ;; be rewritten instead of being a hack on top of occur. 1162 ;; be rewritten instead of being a hack on top of occur.
1163 (setq occur-revert-arguments (list nil 0 (list buffer)))) 1163 (setq occur-revert-arguments (list nil 0 (list buffer))))
1164 (save-excursion 1164 (save-excursion
1165 (goto-char (point-max)) 1165 (goto-char (point-max))
1166 (while (and (not (bobp))) 1166 ;; Do a little shimmy to place point at the end of the last
1167 (let ((end (point)) 1167 ;; "real" paragraph. Need to avoid validating across an \end,
1168 prev-end) 1168 ;; because that blows up latex-forward-sexp.
1169 ;; Scan the previous paragraph for invalidities. 1169 (backward-paragraph)
1170 ;; FIXME this should be using something like backward-paragraph. 1170 (forward-paragraph)
1171 (if (search-backward "\n\n" nil t) 1171 (while (not (bobp))
1172 (progn 1172 ;; Scan the previous paragraph for invalidities.
1173 (setq prev-end (point)) 1173 (backward-paragraph)
1174 (forward-char 2)) 1174 (save-excursion
1175 (goto-char (setq prev-end (point-min)))) 1175 (or (tex-validate-region (point) (save-excursion
1176 (or (tex-validate-region (point) end) 1176 (forward-paragraph)
1177 (let* ((end (line-beginning-position 2)) 1177 (point)))
1178 start tem) 1178 (let ((end (line-beginning-position 2))
1179 start tem)
1179 (beginning-of-line) 1180 (beginning-of-line)
1180 (setq start (point)) 1181 (setq start (point))
1181 ;; Keep track of line number as we scan, 1182 ;; Keep track of line number as we scan,
1182 ;; in a cumulative fashion. 1183 ;; in a cumulative fashion.
1183 (if linenum 1184 (if linenum
1184 (setq linenum (- linenum (count-lines prevpos (point)))) 1185 (setq linenum (- linenum
1186 (count-lines prevpos (point))))
1185 (setq linenum (1+ (count-lines 1 start)))) 1187 (setq linenum (1+ (count-lines 1 start))))
1186 (setq prevpos (point)) 1188 (setq prevpos (point))
1187 ;; Mention this mismatch in *Occur*. 1189 ;; Mention this mismatch in *Occur*.
1188 ;; Since we scan from end of buffer to beginning, 1190 ;; Since we scan from end of buffer to beginning,
1189 ;; add each mismatch at the beginning of *Occur*. 1191 ;; add each mismatch at the beginning of *Occur*.
1200 (setq text-beg (point-marker)) 1202 (setq text-beg (point-marker))
1201 (insert (format "%3d: " linenum)) 1203 (insert (format "%3d: " linenum))
1202 (add-text-properties 1204 (add-text-properties
1203 text-beg (- text-end 1) 1205 text-beg (- text-end 1)
1204 '(mouse-face highlight 1206 '(mouse-face highlight
1205 help-echo "mouse-2: go to this invalidity")) 1207 help-echo
1208 "mouse-2: go to this invalidity"))
1206 (put-text-property text-beg (- text-end 1) 1209 (put-text-property text-beg (- text-end 1)
1207 'occur-target tem))))) 1210 'occur-target tem))))))))
1208 (goto-char prev-end))))
1209 (with-current-buffer standard-output 1211 (with-current-buffer standard-output
1210 (let ((no-matches (zerop num-matches))) 1212 (let ((no-matches (zerop num-matches)))
1211 (if no-matches 1213 (if no-matches
1212 (insert "None!\n")) 1214 (insert "None!\n"))
1213 (if (interactive-p) 1215 (if (interactive-p)
1226 (condition-case () 1228 (condition-case ()
1227 (save-restriction 1229 (save-restriction
1228 (narrow-to-region start end) 1230 (narrow-to-region start end)
1229 ;; First check that the open and close parens balance in numbers. 1231 ;; First check that the open and close parens balance in numbers.
1230 (goto-char start) 1232 (goto-char start)
1231 (while (<= 0 (setq max-possible-sexps (1- max-possible-sexps))) 1233 (while (and (not (eobp))
1234 (<= 0 (setq max-possible-sexps
1235 (1- max-possible-sexps))))
1232 (forward-sexp 1)) 1236 (forward-sexp 1))
1233 ;; Now check that like matches like. 1237 ;; Now check that like matches like.
1234 (goto-char start) 1238 (goto-char start)
1235 (while (re-search-forward "\\s(" nil t) 1239 (while (re-search-forward "\\s(" nil t)
1236 (save-excursion 1240 (save-excursion
1365 (looking-at "\\\\end")) 1369 (looking-at "\\\\end"))
1366 (tex-last-unended-begin)) 1370 (tex-last-unended-begin))
1367 (search-failed (error "Couldn't find unended \\begin")))) 1371 (search-failed (error "Couldn't find unended \\begin"))))
1368 1372
1369 (defun tex-next-unmatched-end () 1373 (defun tex-next-unmatched-end ()
1370 "Leave point at the end of the next `\\end' that is unended." 1374 "Leave point at the end of the next `\\end' that is unmatched."
1371 (while (and (tex-search-noncomment 1375 (while (and (tex-search-noncomment
1372 (re-search-forward "\\\\\\(begin\\|end\\)\\s *{[^}]+}")) 1376 (re-search-forward "\\\\\\(begin\\|end\\)\\s *{[^}]+}"))
1373 (save-excursion (goto-char (match-beginning 0)) 1377 (save-excursion (goto-char (match-beginning 0))
1374 (looking-at "\\\\begin"))) 1378 (looking-at "\\\\begin")))
1375 (tex-next-unmatched-end))) 1379 (tex-next-unmatched-end)))