/[auctex]/auctex/texmathp.el
ViewVC logotype

Diff of /auctex/texmathp.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5.17 by angeli, Sun Oct 2 11:22:30 2005 UTC revision 5.18 by angeli, Tue Nov 29 14:01:42 2005 UTC
# Line 1  Line 1 
1  ;; texmathp.el -- Code to check if point is inside LaTeX math environment  ;; texmathp.el -- Code to check if point is inside LaTeX math environment
2  ;; Copyright (c) 1998 Carsten Dominik  ;; Copyright (c) 1998 Carsten Dominik
3  ;; Copyright (C) 2004 Free Software Foundation, Inc.  ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4    
5  ;; texmathp.el,v 1.28 1998/11/23 15:19:44 dominik Exp  ;; texmathp.el,v 1.28 1998/11/23 15:19:44 dominik Exp
6    
# Line 310  See the variable `texmathp-tex-commands' Line 310  See the variable `texmathp-tex-commands'
310                    (cdr match)))                    (cdr match)))
311      (and math-on t)))      (and math-on t)))
312    
313    ;; Could be replaced by `TeX-in-commented-line'.
314    (defun texmathp-in-commented-line ()
315      "Return non-nil if point is in a line constisting only of a comment."
316      (save-excursion
317        (beginning-of-line)
318        (skip-chars-forward " \t")
319        (string= (buffer-substring-no-properties
320                  (point) (min (point-max)
321                               (+ (point) (length comment-start))))
322                 comment-start)))
323    
324    ;; Could be replaced by `TeX-in-comment'.
325    (defun texmathp-in-comment ()
326      "Return non-nil if point is in a comment."
327      (save-match-data
328        (re-search-backward comment-start-skip (line-beginning-position) t)))
329    
330  (defun texmathp-match-environment (bound)  (defun texmathp-match-environment (bound)
331    "Find out if point is inside any of the math environments.    "Find out if point is inside any of the math environments.
332  Limit searched to BOUND.  The return value is like (\"equation\" . (point))."  Limit searched to BOUND.  The return value is like (\"equation\" . (point))."
# Line 317  Limit searched to BOUND.  The return val Line 334  Limit searched to BOUND.  The return val
334      (save-excursion      (save-excursion
335        (and (null texmathp-environments) (throw 'exit nil))        (and (null texmathp-environments) (throw 'exit nil))
336        ;; Check if the line we are starting with is a commented one.        ;; Check if the line we are starting with is a commented one.
337        (let ((orig-comment-flag        (let ((orig-comment-flag (texmathp-in-commented-line))
              ;; Could be replaced by `TeX-in-commented-line'.  
              (progn  
                (save-excursion  
                  (beginning-of-line)  
                  (skip-chars-forward " \t")  
                  (string= (buffer-substring-no-properties  
                            (point) (min (point-max)  
                                         (+ (point) (length comment-start))))  
                           comment-start))))  
338              end-list env)              end-list env)
339          (while (re-search-backward "\\\\\\(begin\\|end\\)[ \t]*{\\([^}]+\\)}"          (while (re-search-backward "\\\\\\(begin\\|end\\)[ \t]*{\\([^}]+\\)}"
340                                     bound t)                                     bound t)
341            ;; Check if the match found is inside of a comment.            ;; Check if the match found is inside of a comment.
342            (let ((current-comment-flag            (let ((current-comment-flag (texmathp-in-comment)))
                  ;; Could be replaced by `TeX-in-comment'.  
                  (when (save-match-data  
                          (re-search-backward comment-start-skip  
                                              (line-beginning-position) t))  
                    ;; We need a t for comparison with `orig-comment-flag',  
                    ;; not a number.  
                    t)))  
343              ;; Only consider matching alternatives with respect to              ;; Only consider matching alternatives with respect to
344              ;; "in-commentness", i.e. if we started with a comment              ;; "in-commentness", i.e. if we started with a comment
345              ;; only consider matches which are in comments as well and              ;; only consider matches which are in comments as well and
346              ;; vice versa.              ;; vice versa.
347              (when (eq orig-comment-flag current-comment-flag)              (when (or (and orig-comment-flag current-comment-flag)
348                          (and (not orig-comment-flag) (not current-comment-flag)))
349                (setq env (buffer-substring-no-properties                (setq env (buffer-substring-no-properties
350                           (match-beginning 2) (match-end 2)))                           (match-beginning 2) (match-end 2)))
351                (cond ((string= (match-string 1) "end")                (cond ((string= (match-string 1) "end")
# Line 414  Limit searches to BOUND.  The return val Line 416  Limit searches to BOUND.  The return val
416    "Search backward for any of the math switches.    "Search backward for any of the math switches.
417  Limit searched to BOUND."  Limit searched to BOUND."
418    ;; The return value is like ("\\(" . (point)).    ;; The return value is like ("\\(" . (point)).
419    (save-excursion    (let ((orig-comment-flag (texmathp-in-commented-line)))
420      (if (re-search-backward texmathp-onoff-regexp bound t)      (catch 'found
421          (cons (buffer-substring-no-properties (match-beginning 1) (match-end 1))        (save-excursion
422                (match-beginning 1))          (while (re-search-backward texmathp-onoff-regexp bound t)
423        nil)))            (let ((current-comment-flag (or (texmathp-in-comment)
424                                              ;; Catch cases where point is at
425                                              ;; the start of a commented line.
426                                              (texmathp-in-commented-line))))
427                (when (or (and orig-comment-flag current-comment-flag)
428                          (and (not orig-comment-flag) (not current-comment-flag)))
429                  (throw 'found (cons (buffer-substring-no-properties
430                                       (match-beginning 1) (match-end 1))
431                                      (match-beginning 1))))))))))
432    
433  (provide 'texmathp)  (provide 'texmathp)
434    

Legend:
Removed from v.5.17  
changed lines
  Added in v.5.18

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26