aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Williams2002-04-02 11:26:12 +0000
committerMike Williams2002-04-02 11:26:12 +0000
commitf6ab0573f9a497a7dad07a349da44750bb69d567 (patch)
tree05b65f26f1d626e38ebabfcd1d53c1ad070b5a88
parent02dfca16b129fe6573b008cc33977ec370a66aeb (diff)
downloademacs-f6ab0573f9a497a7dad07a349da44750bb69d567.tar.gz
emacs-f6ab0573f9a497a7dad07a349da44750bb69d567.zip
(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.
-rw-r--r--lisp/textmodes/sgml-mode.el62
1 files changed, 20 insertions, 42 deletions
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 8f3ba9c6a78..4b01d4d2917 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -99,6 +99,7 @@ This takes effect when first loading the `sgml-mode' library.")
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
@@ -461,7 +462,7 @@ Behaves electrically if `sgml-quick-keys' is non-nil."
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
@@ -993,8 +994,8 @@ Leave point at the beginning of the 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))
@@ -1004,13 +1005,6 @@ Leave point at the beginning of the tag."
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
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
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.
1016If FULL is `empty', return even if the context is empty (i.e. 1010If FULL is `empty', return even if the context is empty (i.e.
@@ -1047,10 +1041,6 @@ immediately enclosing the current position."
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
@@ -1095,35 +1085,23 @@ If FULL is non-nil, parse back to the beginning of the buffer."
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."