Mercurial > emacs
comparison lisp/textmodes/sgml-mode.el @ 44460:45c30120001e
(sgml-lexical-context): Use sgml-parse-tag-backward to find start point.
(sgml-looking-back-at): Doc fix.
author | Mike Williams <mdub@bigfoot.com> |
---|---|
date | Tue, 09 Apr 2002 12:26:44 +0000 |
parents | 25c3c51b0375 |
children | 4067d1e7f884 |
comparison
equal
deleted
inserted
replaced
44459:25c3c51b0375 | 44460:45c30120001e |
---|---|
861 (defun sgml-lexical-context (&optional limit) | 861 (defun sgml-lexical-context (&optional limit) |
862 "Return the lexical context at point as (TYPE . START). | 862 "Return the lexical context at point as (TYPE . START). |
863 START is the location of the start of the lexical element. | 863 START is the location of the start of the lexical element. |
864 TYPE is one of `string', `comment', `tag', `cdata', or `text'. | 864 TYPE is one of `string', `comment', `tag', `cdata', or `text'. |
865 | 865 |
866 If non-nil LIMIT is a nearby position before point outside of any tag." | 866 Optional argument LIMIT is the position to start parsing from. |
867 ;; As usual, it's difficult to get a reliable answer without parsing the | 867 If nil, start from a preceding tag at indentation." |
868 ;; whole buffer. We'll assume that a tag at indentation is outside of | |
869 ;; any string or tag or comment or ... | |
870 (save-excursion | 868 (save-excursion |
871 (let ((pos (point)) | 869 (let ((pos (point)) |
872 text-start state) | 870 text-start state) |
873 (if limit (goto-char limit) | 871 (if limit |
874 ;; Hopefully this regexp will match something that's not inside | 872 (goto-char limit) |
875 ;; a tag and also hopefully the match is nearby. | 873 ;; Skip tags backwards until we find one at indentation |
876 (re-search-backward "^[ \t]*<[_:[:alpha:]/%!?#]" nil 'move)) | 874 (while (and (ignore-errors (sgml-parse-tag-backward)) |
875 (not (sgml-at-indentation-p))))) | |
877 (with-syntax-table sgml-tag-syntax-table | 876 (with-syntax-table sgml-tag-syntax-table |
878 (while (< (point) pos) | 877 (while (< (point) pos) |
879 ;; When entering this loop we're inside text. | 878 ;; When entering this loop we're inside text. |
880 (setq text-start (point)) | 879 (setq text-start (point)) |
881 (skip-chars-forward "^<" pos) | 880 (skip-chars-forward "^<" pos) |
964 (defsubst sgml-parse-tag-name () | 963 (defsubst sgml-parse-tag-name () |
965 "Skip past a tag-name, and return the name." | 964 "Skip past a tag-name, and return the name." |
966 (buffer-substring-no-properties | 965 (buffer-substring-no-properties |
967 (point) (progn (skip-syntax-forward "w_") (point)))) | 966 (point) (progn (skip-syntax-forward "w_") (point)))) |
968 | 967 |
969 (defsubst sgml-looking-back-at (s) | 968 (defsubst sgml-looking-back-at (str) |
970 (let ((start (- (point) (length s)))) | 969 "Return t if the test before point matches STR." |
970 (let ((start (- (point) (length str)))) | |
971 (and (>= start (point-min)) | 971 (and (>= start (point-min)) |
972 (equal s (buffer-substring-no-properties start (point)))))) | 972 (equal str (buffer-substring-no-properties start (point)))))) |
973 | 973 |
974 (defun sgml-parse-tag-backward () | 974 (defun sgml-parse-tag-backward () |
975 "Parse an SGML tag backward, and return information about the tag. | 975 "Parse an SGML tag backward, and return information about the tag. |
976 Assume that parsing starts from within a textual context. | 976 Assume that parsing starts from within a textual context. |
977 Leave point at the beginning of the tag." | 977 Leave point at the beginning of the tag." |