comparison lisp/textmodes/sgml-mode.el @ 44335:1a7be1d554f5

(sgml-looking-back-at): Short-circuit at beg of buffer. (sgml-lexical-context,sgml-calculate-indent): Add support for CDATA sections.
author Mike Williams <mdub@bigfoot.com>
date Tue, 02 Apr 2002 12:06:26 +0000
parents efbd9e76f0a4
children 2480de7648c8
comparison
equal deleted inserted replaced
44334:3aa56f622b1b 44335:1a7be1d554f5
870 ;; As usual, it's difficult to get a reliable answer without parsing the 870 ;; As usual, it's difficult to get a reliable answer without parsing the
871 ;; whole buffer. We'll assume that a tag at indentation is outside of 871 ;; whole buffer. We'll assume that a tag at indentation is outside of
872 ;; any string or tag or comment or ... 872 ;; any string or tag or comment or ...
873 (save-excursion 873 (save-excursion
874 (let ((pos (point)) 874 (let ((pos (point))
875 (state nil) 875 text-start cdata-start state)
876 textstart)
877 (if limit (goto-char limit) 876 (if limit (goto-char limit)
878 ;; Hopefully this regexp will match something that's not inside 877 ;; Hopefully this regexp will match something that's not inside
879 ;; a tag and also hopefully the match is nearby. 878 ;; a tag and also hopefully the match is nearby.
880 (re-search-backward "^[ \t]*<[_:[:alpha:]/%!?#]" nil 'move)) 879 (re-search-backward "^[ \t]*<[_:[:alpha:]/%!?#]" nil 'move))
881 (setq textstart (point)) 880 ;; (setq text-start (point))
882 (with-syntax-table sgml-tag-syntax-table 881 (with-syntax-table sgml-tag-syntax-table
883 (while (< (point) pos) 882 (while (< (point) pos)
884 ;; When entering this loop we're inside text. 883 ;; When entering this loop we're inside text.
885 (setq textstart (point)) 884 (setq text-start (point))
886 (skip-chars-forward "^<" pos) 885 (skip-chars-forward "^<" pos)
887 ;; We skipped text and reached a tag. Parse it. 886 (setq cdata-start (if (looking-at "<!\\[CDATA\\[") (point)))
888 ;; FIXME: Handle net-enabling start-tags and <![CDATA[ ...]]>. 887 ;; We skipped text and reached a tag. Parse it.
889 (setq state (parse-partial-sexp (point) pos 0))) 888 ;; FIXME: Handle net-enabling start-tags
889 (if cdata-start
890 (search-forward "]]>" pos 'limit)
891 (setq state (parse-partial-sexp (point) pos 0))))
890 (cond 892 (cond
893 (cdata-start (cons 'cdata cdata-start))
891 ((nth 3 state) (cons 'string (nth 8 state))) 894 ((nth 3 state) (cons 'string (nth 8 state)))
892 ((nth 4 state) (cons 'comment (nth 8 state))) 895 ((nth 4 state) (cons 'comment (nth 8 state)))
893 ((and state (> (nth 0 state) 0)) (cons 'tag (nth 1 state))) 896 ((and state (> (nth 0 state) 0)) (cons 'tag (nth 1 state)))
894 (t (cons 'text textstart))))))) 897 (t (cons 'text text-start)))))))
895 898
896 (defun sgml-beginning-of-tag (&optional top-level) 899 (defun sgml-beginning-of-tag (&optional top-level)
897 "Skip to beginning of tag and return its name. 900 "Skip to beginning of tag and return its name.
898 If this can't be done, return nil." 901 If this can't be done, return nil."
899 (let ((context (sgml-lexical-context))) 902 (let ((context (sgml-lexical-context)))
959 "Skip past a tag-name, and return the name." 962 "Skip past a tag-name, and return the name."
960 (buffer-substring-no-properties 963 (buffer-substring-no-properties
961 (point) (progn (skip-syntax-forward "w_") (point)))) 964 (point) (progn (skip-syntax-forward "w_") (point))))
962 965
963 (defsubst sgml-looking-back-at (s) 966 (defsubst sgml-looking-back-at (s)
964 (let ((limit (max (- (point) (length s)) (point-min)))) 967 (let ((start (- (point) (length s))))
965 (equal s (buffer-substring-no-properties limit (point))))) 968 (and (>= start (point-min))
969 (equal s (buffer-substring-no-properties start (point))))))
966 970
967 (defun sgml-parse-tag-backward () 971 (defun sgml-parse-tag-backward ()
968 "Parse an SGML tag backward, and return information about the tag. 972 "Parse an SGML tag backward, and return information about the tag.
969 Assume that parsing starts from within a textual context. 973 Assume that parsing starts from within a textual context.
970 Leave point at the beginning of the tag." 974 Leave point at the beginning of the tag."
1148 (skip-chars-forward " \t") 1152 (skip-chars-forward " \t")
1149 (goto-char (cdr lcon))) 1153 (goto-char (cdr lcon)))
1150 (when (and (not mark) (looking-at "--")) 1154 (when (and (not mark) (looking-at "--"))
1151 (forward-char 2) (skip-chars-forward " \t")) 1155 (forward-char 2) (skip-chars-forward " \t"))
1152 (current-column))) 1156 (current-column)))
1157
1158 (cdata
1159 (current-column))
1153 1160
1154 (tag 1161 (tag
1155 (goto-char (1+ (cdr lcon))) 1162 (goto-char (1+ (cdr lcon)))
1156 (skip-chars-forward "^ \t\n") ;Skip tag name. 1163 (skip-chars-forward "^ \t\n") ;Skip tag name.
1157 (skip-chars-forward " \t") 1164 (skip-chars-forward " \t")