comparison lisp/textmodes/sgml-mode.el @ 44333:efbd9e76f0a4

(sgml-close-tag): Rename from sgml-insert-end-tag. Simplify by using sgml-lexical-context. (sgml-get-context): Remove use of sgml-inside-tag-p. (sgml-inside-tag-p): Remove.
author Mike Williams <mdub@bigfoot.com>
date Tue, 02 Apr 2002 11:26:12 +0000
parents 96c839b7b4c2
children 1a7be1d554f5
comparison
equal deleted inserted replaced
44332:bdf6c2baa447 44333:efbd9e76f0a4
97 (define-key map "\C-c\C-f" 'sgml-skip-tag-forward) 97 (define-key map "\C-c\C-f" 'sgml-skip-tag-forward)
98 (define-key map [?\C-c right] 'sgml-skip-tag-forward) 98 (define-key map [?\C-c right] 'sgml-skip-tag-forward)
99 (define-key map "\C-c\C-d" 'sgml-delete-tag) 99 (define-key map "\C-c\C-d" 'sgml-delete-tag)
100 (define-key map "\C-c\^?" 'sgml-delete-tag) 100 (define-key map "\C-c\^?" 'sgml-delete-tag)
101 (define-key map "\C-c?" 'sgml-tag-help) 101 (define-key map "\C-c?" 'sgml-tag-help)
102 (define-key map "\C-c/" 'sgml-close-tag)
102 (define-key map "\C-c8" 'sgml-name-8bit-mode) 103 (define-key map "\C-c8" 'sgml-name-8bit-mode)
103 (define-key map "\C-c\C-v" 'sgml-validate) 104 (define-key map "\C-c\C-v" 'sgml-validate)
104 (when sgml-quick-keys 105 (when sgml-quick-keys
105 (define-key map "&" 'sgml-name-char) 106 (define-key map "&" 'sgml-name-char)
106 (define-key map "<" 'sgml-tag) 107 (define-key map "<" 'sgml-tag)
459 ((eq sgml-quick-keys 'indent) 460 ((eq sgml-quick-keys 'indent)
460 (insert-char ?/ 1) 461 (insert-char ?/ 1)
461 (indent-according-to-mode)) 462 (indent-according-to-mode))
462 ((eq sgml-quick-keys 'close) 463 ((eq sgml-quick-keys 'close)
463 (delete-backward-char 1) 464 (delete-backward-char 1)
464 (sgml-insert-end-tag)) 465 (sgml-close-tag))
465 (t 466 (t
466 (sgml-slash-matching arg)))) 467 (sgml-slash-matching arg))))
467 468
468 (defun sgml-slash-matching (arg) 469 (defun sgml-slash-matching (arg)
469 "Insert `/' and display any previous matching `/'. 470 "Insert `/' and display any previous matching `/'.
991 (setq tag-type 'pi)) 992 (setq tag-type 'pi))
992 (?/ ; close-tag 993 (?/ ; close-tag
993 (forward-char 1) 994 (forward-char 1)
994 (setq tag-type 'close 995 (setq tag-type 'close
995 name (sgml-parse-tag-name))) 996 name (sgml-parse-tag-name)))
996 ((?% ?#) ; JSP tags etc 997 (?% ; JSP tags
997 (setq tag-type 'unknown)) 998 (setq tag-type 'jsp))
998 (t ; open or empty tag 999 (t ; open or empty tag
999 (setq tag-type 'open 1000 (setq tag-type 'open
1000 name (sgml-parse-tag-name)) 1001 name (sgml-parse-tag-name))
1001 (if (or (eq ?/ (char-before (- tag-end 1))) 1002 (if (or (eq ?/ (char-before (- tag-end 1)))
1002 (sgml-empty-tag-p name)) 1003 (sgml-empty-tag-p name))
1003 (setq tag-type 'empty)))))) 1004 (setq tag-type 'empty))))))
1004 (goto-char tag-start) 1005 (goto-char tag-start)
1005 (sgml-make-tag tag-type tag-start tag-end name))) 1006 (sgml-make-tag tag-type tag-start tag-end name)))
1006
1007 (defsubst sgml-inside-tag-p (tag-info &optional point)
1008 "Return true if TAG-INFO contains the POINT."
1009 (let ((end (sgml-tag-end tag-info))
1010 (point (or point (point))))
1011 (or (null end)
1012 (> end point))))
1013 1007
1014 (defun sgml-get-context (&optional full) 1008 (defun sgml-get-context (&optional full)
1015 "Determine the context of the current position. 1009 "Determine the context of the current position.
1016 If FULL is `empty', return even if the context is empty (i.e. 1010 If FULL is `empty', return even if the context is empty (i.e.
1017 we just skipped over some element and got to a beginning of line). 1011 we just skipped over some element and got to a beginning of line).
1045 (sgml-tag-end (car context)))) 1039 (sgml-tag-end (car context))))
1046 (setq context (cdr context))) 1040 (setq context (cdr context)))
1047 1041
1048 (cond 1042 (cond
1049 1043
1050 ;; inside a tag ...
1051 ((sgml-inside-tag-p tag-info here)
1052 (push tag-info context))
1053
1054 ;; start-tag 1044 ;; start-tag
1055 ((eq (sgml-tag-type tag-info) 'open) 1045 ((eq (sgml-tag-type tag-info) 'open)
1056 (cond 1046 (cond
1057 ((null ignore) 1047 ((null ignore)
1058 (if (and context 1048 (if (and context
1093 (pp (save-excursion (sgml-get-context full))))) 1083 (pp (save-excursion (sgml-get-context full)))))
1094 1084
1095 1085
1096 ;; Editing shortcuts 1086 ;; Editing shortcuts
1097 1087
1098 (defun sgml-insert-end-tag () 1088 (defun sgml-close-tag ()
1099 "Insert an end-tag for the current element." 1089 "Insert an close-tag for the current element."
1100 (interactive) 1090 (interactive)
1101 (let* ((context (save-excursion (sgml-get-context))) 1091 (case (car (sgml-lexical-context))
1102 (tag-info (car (last context))) 1092 (comment (insert " -->"))
1103 (type (and tag-info (sgml-tag-type tag-info)))) 1093 (cdata (insert "]]>"))
1104 1094 (pi (insert " ?>"))
1105 (cond 1095 (jsp (insert " %>"))
1106 1096 (tag (insert " />"))
1107 ((null context) 1097 (text
1108 (error "Nothing to close")) 1098 (let ((context (save-excursion (sgml-get-context))))
1109 1099 (if context
1110 ;; inside a tag 1100 (progn
1111 ((sgml-inside-tag-p tag-info) 1101 (insert "</" (sgml-tag-name (car (last context))) ">")
1112 (insert (cond 1102 (indent-according-to-mode)))))
1113 ((eq type 'empty) " />") 1103 (otherwise
1114 ((eq type 'comment) " -->") 1104 (error "Nothing to close"))))
1115 ((eq type 'cdata) "]]>")
1116 ((eq type 'jsp) "%>")
1117 ((eq type 'pi) "?>")
1118 (t ">"))))
1119
1120 ;; inside an element
1121 ((eq type 'open)
1122 (insert "</" (sgml-tag-name tag-info) ">")
1123 (indent-according-to-mode))
1124
1125 (t
1126 (error "Nothing to close")))))
1127 1105
1128 (defun sgml-empty-tag-p (tag-name) 1106 (defun sgml-empty-tag-p (tag-name)
1129 "Return non-nil if TAG-NAME is an implicitly empty tag." 1107 "Return non-nil if TAG-NAME is an implicitly empty tag."
1130 (and (not sgml-xml-mode) 1108 (and (not sgml-xml-mode)
1131 (member-ignore-case tag-name sgml-empty-tags))) 1109 (member-ignore-case tag-name sgml-empty-tags)))