Mercurial > emacs
comparison lisp/textmodes/sgml-mode.el @ 17545:c67787f92aea
(sgml-value): Use 'identity as default value.
(sgml-mode): Doc fix.
(sgml-name-8bit-mode): Tell the user if set or reset.
(sgml-tag): Doc fix.
(sgml-tag): Protect "<" from skeleton-transformation.
(sgml-attributes): Doc fix.
(sgml-attributes): Square brackets removed from prompt.
(sgml-attributes): Arg ALIST renamed to TAG.
(sgml-attributes): Apply skeleton-transformation when necessary.
(sgml-value): Doc added.
(sgml-value): Square brackets removed from prompt.
(html-tag-alist): New variable 1-7, variable `list' changed.
(html-tag-alist)<dir>, <menu>: Use new value of `list'.
(html-tag-alist)<font>: Fixed (doc of sgml-tag-alist needs fixing).
(html-tag-alist)<ol>, <ul>: Fixed.
(html-tag-alist)<fn>: Commented out.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 23 Apr 1997 18:58:33 +0000 |
parents | 9fb83ef40566 |
children | 2738b57e4704 |
comparison
equal
deleted
inserted
replaced
17544:9ba1f7641826 | 17545:c67787f92aea |
---|---|
34 | 34 |
35 (defgroup sgml nil | 35 (defgroup sgml nil |
36 "SGML editing mode" | 36 "SGML editing mode" |
37 :group 'languages) | 37 :group 'languages) |
38 | 38 |
39 (defcustom sgml-transformation nil | 39 (defcustom sgml-transformation 'identity |
40 "*Default value for `skeleton-transformation' (which see) in SGML mode." | 40 "*Default value for `skeleton-transformation' (which see) in SGML mode." |
41 :type 'function | 41 :type 'function |
42 :group 'sgml) | 42 :group 'sgml) |
43 | 43 |
44 (put 'sgml-transformation 'variable-interactive | 44 (put 'sgml-transformation 'variable-interactive |
356 | 356 |
357 An argument of N to a tag-inserting command means that the next N | 357 An argument of N to a tag-inserting command means that the next N |
358 words should be wrapped. When the region is highlighted, N defaults | 358 words should be wrapped. When the region is highlighted, N defaults |
359 to -1, which means the current region. | 359 to -1, which means the current region. |
360 | 360 |
361 If you like upcased tags, put (setq skeleton-transformation 'upcase) in | 361 If you like upcased tags, put (setq sgml-transformation 'upcase) in |
362 sgml-mode-hook. | 362 your .emacs file. |
363 | 363 |
364 Use \\[sgml-validate] to validate your document with an SGML parser. | 364 Use \\[sgml-validate] to validate your document with an SGML parser. |
365 | 365 |
366 Do \\[describe-variable] sgml- SPC to see available variables. | 366 Do \\[describe-variable] sgml- SPC to see available variables. |
367 Do \\[describe-key] on the following bindings to discover what they do. | 367 Do \\[describe-key] on the following bindings to discover what they do. |
462 | 462 |
463 | 463 |
464 (defun sgml-name-8bit-mode () | 464 (defun sgml-name-8bit-mode () |
465 "Toggle insertion of 8 bit characters." | 465 "Toggle insertion of 8 bit characters." |
466 (interactive) | 466 (interactive) |
467 (setq sgml-name-8bit-mode (not sgml-name-8bit-mode))) | 467 (setq sgml-name-8bit-mode (not sgml-name-8bit-mode)) |
468 | 468 (message "sgml name 8 bit mode is now %" |
469 | 469 (if sgml-name-8bit-mode "ON" "OFF"))) |
470 | |
471 | |
472 ; When an element of a skeleton is a string "str", it is passed | |
473 ; through skeleton-transformation and inserted. If "str" is to be | |
474 ; inserted literally, one should obtain it as the return value of a | |
475 ; function, e.g. (identity "str"). | |
470 | 476 |
471 (define-skeleton sgml-tag | 477 (define-skeleton sgml-tag |
472 "Insert a tag you are prompted for, optionally with attributes. | 478 "Insert a tag you are prompted for, optionally with attributes. |
473 Completion and configuration is according to `sgml-tag-alist'. | 479 Completion and configuration is done according to `sgml-tag-alist'. |
474 If you like tags and attributes in uppercase set `skeleton-transformation' | 480 If you like tags and attributes in uppercase do \\[set-variable] |
475 to `upcase'." | 481 skeleton-transformation RET upcase RET, or put this in your .emacs |
482 (setq sgml-transformation 'upcase)." | |
476 (funcall skeleton-transformation | 483 (funcall skeleton-transformation |
477 (completing-read "Tag: " sgml-tag-alist)) | 484 (completing-read "Tag: " sgml-tag-alist)) |
478 ?< (setq v1 (eval str)) | | 485 ?< (setq v1 (eval str)) | |
479 (("") -1 '(undo-boundary) "<") | | 486 (("") -1 '(undo-boundary) (identity "<")) | ; see comment above |
480 (("") '(setq v2 (sgml-attributes v1 t)) ?> | 487 (("") '(setq v2 (sgml-attributes v1 t)) ?> |
481 (if (string= "![" v1) | 488 (if (string= "![" v1) |
482 (prog1 '(("") " [ " _ " ]]") | 489 (prog1 '(("") " [ " _ " ]]") |
483 (backward-char)) | 490 (backward-char)) |
484 (if (or (eq v2 t) | 491 (if (or (eq v2 t) |
492 (cdr v2) | 499 (cdr v2) |
493 '(resume: (car v2) _ "</" v1 ?>)))))))) | 500 '(resume: (car v2) _ "</" v1 ?>)))))))) |
494 | 501 |
495 (autoload 'skeleton-read "skeleton") | 502 (autoload 'skeleton-read "skeleton") |
496 | 503 |
497 (defun sgml-attributes (alist &optional quiet) | 504 (defun sgml-attributes (tag &optional quiet) |
498 "When at toplevel of a tag, interactively insert attributes." | 505 "When at toplevel of a tag, interactively insert attributes. |
506 | |
507 Completion and configuration of TAG is done according to `sgml-tag-alist'. | |
508 If QUIET, does not print a message when there are no attributes for TAG." | |
499 (interactive (list (save-excursion (sgml-beginning-of-tag t)))) | 509 (interactive (list (save-excursion (sgml-beginning-of-tag t)))) |
500 (or (stringp alist) (error "Wrong context for adding attribute")) | 510 (or (stringp tag) (error "Wrong context for adding attribute")) |
501 (if alist | 511 (if tag |
502 (let ((completion-ignore-case t) | 512 (let ((completion-ignore-case t) |
513 (alist (cdr (assoc (downcase tag) sgml-tag-alist))) | |
503 car attribute i) | 514 car attribute i) |
504 (setq alist (cdr (assoc (downcase alist) sgml-tag-alist))) | |
505 (if (or (symbolp (car alist)) | 515 (if (or (symbolp (car alist)) |
506 (symbolp (car (car alist)))) | 516 (symbolp (car (car alist)))) |
507 (setq car (car alist) | 517 (setq car (car alist) |
508 alist (cdr alist))) | 518 alist (cdr alist))) |
509 (or quiet | 519 (or quiet |
510 (message "No attributes configured.")) | 520 (message "No attributes configured.")) |
511 (if (stringp (car alist)) | 521 (if (stringp (car alist)) |
512 (progn | 522 (progn |
513 (insert (if (eq (preceding-char) ? ) "" ? ) (car alist)) | 523 (insert (if (eq (preceding-char) ? ) "" ? ) |
524 (funcall skeleton-transformation (car alist))) | |
514 (sgml-value alist)) | 525 (sgml-value alist)) |
515 (setq i (length alist)) | 526 (setq i (length alist)) |
516 (while (> i 0) | 527 (while (> i 0) |
517 (insert ? ) | 528 (insert ? ) |
518 (insert (funcall skeleton-transformation | 529 (insert (funcall skeleton-transformation |
519 (setq attribute | 530 (setq attribute |
520 (skeleton-read '(completing-read | 531 (skeleton-read '(completing-read |
521 "[Attribute]: " | 532 "Attribute: " |
522 alist))))) | 533 alist))))) |
523 (if (string= "" attribute) | 534 (if (string= "" attribute) |
524 (setq i 0) | 535 (setq i 0) |
525 (sgml-value (assoc attribute alist)) | 536 (sgml-value (assoc attribute alist)) |
526 (setq i (1- i)))) | 537 (setq i (1- i)))) |
769 (1+ (point)) | 780 (1+ (point)) |
770 (match-end 0)) | 781 (match-end 0)) |
771 t))) | 782 t))) |
772 | 783 |
773 (defun sgml-value (alist) | 784 (defun sgml-value (alist) |
785 "Interactively insert value taken from ALIST, which is an | |
786 `attributerule' as described in sgml-tag-alist." | |
774 (setq alist (cdr alist)) | 787 (setq alist (cdr alist)) |
775 (if (stringp (car alist)) | 788 (if (stringp (car alist)) |
776 (insert "=\"" (car alist) ?\") | 789 (insert "=\"" (car alist) ?\") |
777 (if (eq (car alist) t) | 790 (if (eq (car alist) t) |
778 (if (cdr alist) | 791 (if (cdr alist) |
779 (progn | 792 (progn |
780 (insert "=\"") | 793 (insert "=\"") |
781 (setq alist (skeleton-read '(completing-read | 794 (setq alist (skeleton-read '(completing-read |
782 "[Value]: " (cdr alist)))) | 795 "Value: " (cdr alist)))) |
783 (if (string< "" alist) | 796 (if (string< "" alist) |
784 (insert alist ?\") | 797 (insert alist ?\") |
785 (delete-backward-char 2)))) | 798 (delete-backward-char 2)))) |
786 (insert "=\"") | 799 (insert "=\"") |
787 (if alist | 800 (if alist |
893 "Value of `sgml-display-text' for HTML mode.") | 906 "Value of `sgml-display-text' for HTML mode.") |
894 | 907 |
895 | 908 |
896 ; should code exactly HTML 3 here when that is finished | 909 ; should code exactly HTML 3 here when that is finished |
897 (defvar html-tag-alist | 910 (defvar html-tag-alist |
898 (let* ((1-9 '(("8") ("9") | 911 (let* ((1-7 '(("1") ("2") ("3") ("4") ("5") ("6") ("7"))) |
899 ("1") ("2") ("3") ("4") ("5") ("6") ("7"))) | 912 (1-9 '(,@1-7 ("8") ("9"))) |
900 (align '(("align" ("left") ("center") ("right")))) | 913 (align '(("align" ("left") ("center") ("right")))) |
901 (valign '(("top") ("middle") ("bottom") ("baseline"))) | 914 (valign '(("top") ("middle") ("bottom") ("baseline"))) |
902 (rel '(("next") ("previous") ("parent") ("subdocument") ("made"))) | 915 (rel '(("next") ("previous") ("parent") ("subdocument") ("made"))) |
903 (href '("href" ("ftp:") ("file:") ("finger:") ("gopher:") ("http:") | 916 (href '("href" ("ftp:") ("file:") ("finger:") ("gopher:") ("http:") |
904 ("mailto:") ("news:") ("rlogin:") ("telnet:") ("tn3270:") | 917 ("mailto:") ("news:") ("rlogin:") ("telnet:") ("tn3270:") |
906 (name '("name")) | 919 (name '("name")) |
907 (link `(,href | 920 (link `(,href |
908 ("rel" ,@rel) | 921 ("rel" ,@rel) |
909 ("rev" ,@rel) | 922 ("rev" ,@rel) |
910 ("title"))) | 923 ("title"))) |
911 (list '((nil \n | 924 (list '((nil \n ( "List item: " |
912 ( "List item: " | 925 "<li>" str \n)))) |
913 "<li>" str \n)) | |
914 ("type" ("A") ("a") ("I") ("i") ("1")))) | |
915 (cell `(t | 926 (cell `(t |
916 ,align | 927 ,align |
917 ("valign" ,@valign) | 928 ("valign" ,@valign) |
918 ("colspan" ,@1-9) | 929 ("colspan" ,@1-9) |
919 ("rowspan" ,@1-9) | 930 ("rowspan" ,@1-9) |
921 ;; put ,-expressions first, else byte-compile chokes (as of V19.29) | 932 ;; put ,-expressions first, else byte-compile chokes (as of V19.29) |
922 ;; and like this it's more efficient anyway | 933 ;; and like this it's more efficient anyway |
923 `(("a" ,name ,@link) | 934 `(("a" ,name ,@link) |
924 ("base" t ,@href) | 935 ("base" t ,@href) |
925 ("dir" ,@list) | 936 ("dir" ,@list) |
926 ("font" ("size" ("-1") ("+1") ("-2") ("+2") ,@(cdr (cdr 1-9)))) | 937 ("font" nil "size" ("-1") ("+1") ("-2") ("+2") ,@1-7) |
927 ("form" (\n _ \n "<input type=\"submit\" value=\"\">") | 938 ("form" (\n _ \n "<input type=\"submit\" value=\"\">") |
928 ("action" ,@(cdr href)) ("method" ("get") ("post"))) | 939 ("action" ,@(cdr href)) ("method" ("get") ("post"))) |
929 ("h1" ,@align) | 940 ("h1" ,@align) |
930 ("h2" ,@align) | 941 ("h2" ,@align) |
931 ("h3" ,@align) | 942 ("h3" ,@align) |
940 ("type" ("text") ("password") ("checkbox") ("radio") | 951 ("type" ("text") ("password") ("checkbox") ("radio") |
941 ("submit") ("reset")) | 952 ("submit") ("reset")) |
942 ("value")) | 953 ("value")) |
943 ("link" t ,@link) | 954 ("link" t ,@link) |
944 ("menu" ,@list) | 955 ("menu" ,@list) |
945 ("ol" ,@list) | 956 ("ol" ,@list ("type" ("A") ("a") ("I") ("i") ("1"))) |
946 ("p" t ,@align) | 957 ("p" t ,@align) |
947 ("select" (nil \n | 958 ("select" (nil \n |
948 ("Text: " | 959 ("Text: " |
949 "<option>" str \n)) | 960 "<option>" str \n)) |
950 ,name ("size" ,@1-9) ("multiple" t)) | 961 ,name ("size" ,@1-9) ("multiple" t)) |
954 "<tr><" str ?> _ \n)) | 965 "<tr><" str ?> _ \n)) |
955 ("border" t ,@1-9) ("width" "10") ("cellpadding")) | 966 ("border" t ,@1-9) ("width" "10") ("cellpadding")) |
956 ("td" ,@cell) | 967 ("td" ,@cell) |
957 ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9)) | 968 ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9)) |
958 ("th" ,@cell) | 969 ("th" ,@cell) |
959 ("ul" ,@list) | 970 ("ul" ,@list ("type" ("disc") ("circle") ("square"))) |
960 | 971 |
961 ,@sgml-tag-alist | 972 ,@sgml-tag-alist |
962 | 973 |
963 ("abbrev") | 974 ("abbrev") |
964 ("acronym") | 975 ("acronym") |
985 ("dl" (nil \n | 996 ("dl" (nil \n |
986 ( "Term: " | 997 ( "Term: " |
987 "<dt>" str "<dd>" _ \n))) | 998 "<dt>" str "<dd>" _ \n))) |
988 ("dt" (t _ "<dd>")) | 999 ("dt" (t _ "<dd>")) |
989 ("em") | 1000 ("em") |
990 ("fn" "id" "fn") | 1001 ;("fn" "id" "fn") ; ??? |
991 ("head" \n) | 1002 ("head" \n) |
992 ("html" (\n | 1003 ("html" (\n |
993 "<head>\n" | 1004 "<head>\n" |
994 "<title>" (setq str (read-input "Title: ")) "</title>\n" | 1005 "<title>" (setq str (read-input "Title: ")) "</title>\n" |
995 "<body>\n<h1>" str "</h1>\n" _ | 1006 "<body>\n<h1>" str "</h1>\n" _ |
1055 ("embed" . "Embedded data in foreign format") | 1066 ("embed" . "Embedded data in foreign format") |
1056 ("fig" . "Figure") | 1067 ("fig" . "Figure") |
1057 ("figa" . "Figure anchor") | 1068 ("figa" . "Figure anchor") |
1058 ("figd" . "Figure description") | 1069 ("figd" . "Figure description") |
1059 ("figt" . "Figure text") | 1070 ("figt" . "Figure text") |
1060 ("fn" . "?") | 1071 ;("fn" . "?") ; ??? |
1061 ("font" . "Font size") | 1072 ("font" . "Font size") |
1062 ("form" . "Form with input fields") | 1073 ("form" . "Form with input fields") |
1063 ("group" . "Document grouping") | 1074 ("group" . "Document grouping") |
1064 ("h1" . "Most important section headline") | 1075 ("h1" . "Most important section headline") |
1065 ("h2" . "Important section headline") | 1076 ("h2" . "Important section headline") |
1264 "Group of connected checkbox inputs." | 1275 "Group of connected checkbox inputs." |
1265 nil | 1276 nil |
1266 '(setq v1 nil | 1277 '(setq v1 nil |
1267 v2 nil) | 1278 v2 nil) |
1268 ("Value: " | 1279 ("Value: " |
1269 "<input type=\"" (identity "checkbox") | 1280 "<input type=\"" (identity "checkbox") ; see comment above about identity |
1270 "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: "))) | 1281 "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: "))) |
1271 "\" value=\"" str ?\" | 1282 "\" value=\"" str ?\" |
1272 (if (y-or-n-p "Set \"checked\" attribute? ") | 1283 (if (y-or-n-p "Set \"checked\" attribute? ") |
1273 (funcall skeleton-transformation " checked")) ">" | 1284 (funcall skeleton-transformation " checked")) ">" |
1274 (skeleton-read "Text: " (capitalize str)) | 1285 (skeleton-read "Text: " (capitalize str)) |
1281 "Group of connected radio button inputs." | 1292 "Group of connected radio button inputs." |
1282 nil | 1293 nil |
1283 '(setq v1 nil | 1294 '(setq v1 nil |
1284 v2 (cons nil nil)) | 1295 v2 (cons nil nil)) |
1285 ("Value: " | 1296 ("Value: " |
1286 "<input type=\"" (identity "radio") | 1297 "<input type=\"" (identity "radio") ; see comment above about identity |
1287 "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: "))) | 1298 "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: "))) |
1288 "\" value=\"" str ?\" | 1299 "\" value=\"" str ?\" |
1289 (if (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? "))) | 1300 (if (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? "))) |
1290 (funcall skeleton-transformation " checked") ">") | 1301 (funcall skeleton-transformation " checked") ">") |
1291 (skeleton-read "Text: " (capitalize str)) | 1302 (skeleton-read "Text: " (capitalize str)) |