comparison lisp/progmodes/octave-mod.el @ 79070:b5a52e129c97

John W. Eaton <jwe at octave.org> (octave-looking-at-kw) (octave-re-search-forward-kw, octave-re-search-backward-kw): New functions. (octave-in-defun-p, calculate-octave-indent) (octave-blink-matching-block-open, octave-beginning-of-defun) (octave-auto-fill): Use octave-looking-at-kw instead of looking-at, to search for regexps that contain case-sensitive keywords. (octave-beginning-of-defun): Likewise, for octave-re-search-backward-kw. (octave-scan-blocks): Likewise, for octave-re-search-forward-kw.
author Glenn Morris <rgm@gnu.org>
date Sat, 13 Oct 2007 20:00:45 +0000
parents 419c5c316b51
children c766bbd72b1d
comparison
equal deleted inserted replaced
79069:f38764fb0146 79070:b5a52e129c97
596 (octave-forward-block) 596 (octave-forward-block)
597 t) 597 t)
598 (error nil)) 598 (error nil))
599 (< pos (point))))) 599 (< pos (point)))))
600 600
601 (defun octave-looking-at-kw (regexp)
602 (let ((case-fold-search nil))
603 (looking-at regexp)))
604
605 (defun octave-re-search-forward-kw (regexp)
606 (let ((case-fold-search nil))
607 (re-search-forward regexp nil 'move inc)))
608
609 (defun octave-re-search-backward-kw (regexp)
610 (let ((case-fold-search nil))
611 (re-search-backward regexp nil 'move inc)))
612
601 (defun octave-in-defun-p () 613 (defun octave-in-defun-p ()
602 "Return t if point is inside an Octave function declaration. 614 "Return t if point is inside an Octave function declaration.
603 The function is taken to start at the `f' of `function' and to end after 615 The function is taken to start at the `f' of `function' and to end after
604 the end keyword." 616 the end keyword."
605 (let ((pos (point))) 617 (let ((pos (point)))
606 (save-excursion 618 (save-excursion
607 (or (and (looking-at "\\<function\\>") 619 (or (and (octave-looking-at-kw "\\<function\\>")
608 (octave-not-in-string-or-comment-p)) 620 (octave-not-in-string-or-comment-p))
609 (and (octave-beginning-of-defun) 621 (and (octave-beginning-of-defun)
610 (condition-case nil 622 (condition-case nil
611 (progn 623 (progn
612 (octave-forward-block) 624 (octave-forward-block)
673 (let ((bot (point)) 685 (let ((bot (point))
674 (eol (line-end-position))) 686 (eol (line-end-position)))
675 (while (< (point) eol) 687 (while (< (point) eol)
676 (if (octave-not-in-string-or-comment-p) 688 (if (octave-not-in-string-or-comment-p)
677 (cond 689 (cond
678 ((looking-at "\\<switch\\>") 690 ((octave-looking-at-kw "\\<switch\\>")
679 (setq icol (+ icol (* 2 octave-block-offset)))) 691 (setq icol (+ icol (* 2 octave-block-offset))))
680 ((looking-at octave-block-begin-regexp) 692 ((octave-looking-at-kw octave-block-begin-regexp)
681 (setq icol (+ icol octave-block-offset))) 693 (setq icol (+ icol octave-block-offset)))
682 ((looking-at octave-block-else-regexp) 694 ((octave-looking-at-kw octave-block-else-regexp)
683 (if (= bot (point)) 695 (if (= bot (point))
684 (setq icol (+ icol octave-block-offset)))) 696 (setq icol (+ icol octave-block-offset))))
685 ((looking-at octave-block-end-regexp) 697 ((octave-looking-at-kw octave-block-end-regexp)
686 (if (not (= bot (point))) 698 (if (not (= bot (point)))
687 (setq icol (- icol 699 (setq icol (- icol
688 (octave-block-end-offset))))))) 700 (octave-block-end-offset)))))))
689 (forward-char))) 701 (forward-char)))
690 (if is-continuation-line 702 (if is-continuation-line
691 (setq icol (+ icol octave-continuation-offset))))))) 703 (setq icol (+ icol octave-continuation-offset)))))))
692 (save-excursion 704 (save-excursion
693 (back-to-indentation) 705 (back-to-indentation)
694 (cond 706 (cond
695 ((and (looking-at octave-block-else-regexp) 707 ((and (octave-looking-at-kw octave-block-else-regexp)
696 (octave-not-in-string-or-comment-p)) 708 (octave-not-in-string-or-comment-p))
697 (setq icol (- icol octave-block-offset))) 709 (setq icol (- icol octave-block-offset)))
698 ((and (looking-at octave-block-end-regexp) 710 ((and (octave-looking-at-kw octave-block-end-regexp)
699 (octave-not-in-string-or-comment-p)) 711 (octave-not-in-string-or-comment-p))
700 (setq icol (- icol (octave-block-end-offset)))) 712 (setq icol (- icol (octave-block-end-offset))))
701 ((or (looking-at "\\s<\\s<\\s<\\S<") 713 ((or (looking-at "\\s<\\s<\\s<\\S<")
702 (octave-before-magic-comment-p)) 714 (octave-before-magic-comment-p))
703 (setq icol (list 0 icol))) 715 (setq icol (list 0 icol)))
869 (let ((min-depth (if (> depth 0) 0 depth)) 881 (let ((min-depth (if (> depth 0) 0 depth))
870 (inc (if (> count 0) 1 -1))) 882 (inc (if (> count 0) 1 -1)))
871 (save-excursion 883 (save-excursion
872 (while (/= count 0) 884 (while (/= count 0)
873 (catch 'foo 885 (catch 'foo
874 (while (or (re-search-forward 886 (while (or (octave-re-search-forward-kw
875 octave-block-begin-or-end-regexp nil 'move inc) 887 octave-block-begin-or-end-regexp)
876 (if (/= depth 0) 888 (if (/= depth 0)
877 (error "Unbalanced block"))) 889 (error "Unbalanced block")))
878 (if (octave-not-in-string-or-comment-p) 890 (if (octave-not-in-string-or-comment-p)
879 (progn 891 (progn
880 (cond 892 (cond
989 (let (bb-keyword bb-arg eb-keyword pos eol) 1001 (let (bb-keyword bb-arg eb-keyword pos eol)
990 (if (and (octave-not-in-string-or-comment-p) 1002 (if (and (octave-not-in-string-or-comment-p)
991 (looking-at "\\>") 1003 (looking-at "\\>")
992 (save-excursion 1004 (save-excursion
993 (skip-syntax-backward "w") 1005 (skip-syntax-backward "w")
994 (looking-at octave-block-else-or-end-regexp))) 1006 (octave-looking-at-kw octave-block-else-or-end-regexp)))
995 (save-excursion 1007 (save-excursion
996 (cond 1008 (cond
997 ((match-end 1) 1009 ((match-end 1)
998 (setq eb-keyword 1010 (setq eb-keyword
999 (buffer-substring-no-properties 1011 (buffer-substring-no-properties
1036 (interactive "p") 1048 (interactive "p")
1037 (let* ((arg (or arg 1)) 1049 (let* ((arg (or arg 1))
1038 (inc (if (> arg 0) 1 -1)) 1050 (inc (if (> arg 0) 1 -1))
1039 (found)) 1051 (found))
1040 (and (not (eobp)) 1052 (and (not (eobp))
1041 (not (and (> arg 0) (looking-at "\\<function\\>"))) 1053 (not (and (> arg 0) (octave-looking-at-kw "\\<function\\>")))
1042 (skip-syntax-forward "w")) 1054 (skip-syntax-forward "w"))
1043 (while (and (/= arg 0) 1055 (while (and (/= arg 0)
1044 (setq found 1056 (setq found
1045 (re-search-backward "\\<function\\>" nil 'move inc))) 1057 (octave-re-search-backward-kw "\\<function\\>")))
1046 (if (octave-not-in-string-or-comment-p) 1058 (if (octave-not-in-string-or-comment-p)
1047 (setq arg (- arg inc)))) 1059 (setq arg (- arg inc))))
1048 (if found 1060 (if found
1049 (progn 1061 (progn
1050 (and (< inc 0) (goto-char (match-beginning 0))) 1062 (and (< inc 0) (goto-char (match-beginning 0)))
1093 (let (fc give-up) 1105 (let (fc give-up)
1094 (if (or (null (setq fc (current-fill-column))) 1106 (if (or (null (setq fc (current-fill-column)))
1095 (save-excursion 1107 (save-excursion
1096 (beginning-of-line) 1108 (beginning-of-line)
1097 (and auto-fill-inhibit-regexp 1109 (and auto-fill-inhibit-regexp
1098 (looking-at auto-fill-inhibit-regexp)))) 1110 (octave-looking-at-kw auto-fill-inhibit-regexp))))
1099 nil ; Can't do anything 1111 nil ; Can't do anything
1100 (if (and (not (octave-in-comment-p)) 1112 (if (and (not (octave-in-comment-p))
1101 (> (current-column) fc)) 1113 (> (current-column) fc))
1102 (setq fc (- fc (+ (length octave-continuation-string) 1)))) 1114 (setq fc (- fc (+ (length octave-continuation-string) 1))))
1103 (while (and (not give-up) (> (current-column) fc)) 1115 (while (and (not give-up) (> (current-column) fc))