comparison lisp/textmodes/sgml-mode.el @ 70823:ca1b3788f58d

(sgml-transformation): Make this the alias for the following variable. (sgml-transformation-function): Make this the real name. (sgml-tag-alist): Mark as risky.
author Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
date Sun, 21 May 2006 22:19:59 +0000
parents 067115a6e738
children 429f18443ca0 a8190f7e546e
comparison
equal deleted inserted replaced
70822:2139854814c1 70823:ca1b3788f58d
47 (defcustom sgml-basic-offset 2 47 (defcustom sgml-basic-offset 2
48 "*Specifies the basic indentation level for `sgml-indent-line'." 48 "*Specifies the basic indentation level for `sgml-indent-line'."
49 :type 'integer 49 :type 'integer
50 :group 'sgml) 50 :group 'sgml)
51 51
52 (defcustom sgml-transformation 'identity 52 (defcustom sgml-transformation-function 'identity
53 "*Default value for `skeleton-transformation' (which see) in SGML mode." 53 "*Default value for `skeleton-transformation-function' in SGML mode."
54 :type 'function 54 :type 'function
55 :group 'sgml) 55 :group 'sgml)
56 56
57 (put 'sgml-transformation 'variable-interactive 57 (put 'sgml-transformation-function 'variable-interactive
58 "aTransformation function: ") 58 "aTransformation function: ")
59 (defvaralias 'sgml-transformation 'sgml-transformation-function)
59 60
60 (defcustom sgml-mode-hook nil 61 (defcustom sgml-mode-hook nil
61 "Hook run by command `sgml-mode'. 62 "Hook run by command `sgml-mode'.
62 `text-mode-hook' is run first." 63 `text-mode-hook' is run first."
63 :group 'sgml 64 :group 'sgml
333 ATTRIBUTERULE is a list of optionally t (no value when no input) followed by 334 ATTRIBUTERULE is a list of optionally t (no value when no input) followed by
334 an optional alist of possible values." 335 an optional alist of possible values."
335 :type '(repeat (cons (string :tag "Tag Name") 336 :type '(repeat (cons (string :tag "Tag Name")
336 (repeat :tag "Tag Rule" sexp))) 337 (repeat :tag "Tag Rule" sexp)))
337 :group 'sgml) 338 :group 'sgml)
339 (put 'sgml-tag-alist 'risky-local-variable t)
338 340
339 (defcustom sgml-tag-help 341 (defcustom sgml-tag-help
340 '(("!" . "Empty declaration for comment") 342 '(("!" . "Empty declaration for comment")
341 ("![" . "Embed declarations with parser directive") 343 ("![" . "Embed declarations with parser directive")
342 ("!attlist" . "Tag attributes declaration") 344 ("!attlist" . "Tag attributes declaration")
389 (comment-indent-new-line soft))) 391 (comment-indent-new-line soft)))
390 392
391 (defun sgml-mode-facemenu-add-face-function (face end) 393 (defun sgml-mode-facemenu-add-face-function (face end)
392 (if (setq face (cdr (assq face sgml-face-tag-alist))) 394 (if (setq face (cdr (assq face sgml-face-tag-alist)))
393 (progn 395 (progn
394 (setq face (funcall skeleton-transformation face)) 396 (setq face (funcall skeleton-transformation-function face))
395 (setq facemenu-end-add-face (concat "</" face ">")) 397 (setq facemenu-end-add-face (concat "</" face ">"))
396 (concat "<" face ">")) 398 (concat "<" face ">"))
397 (error "Face not configured for %s mode" mode-name))) 399 (error "Face not configured for %s mode" mode-name)))
398 400
399 (defun sgml-fill-nobreak () 401 (defun sgml-fill-nobreak ()
413 415
414 An argument of N to a tag-inserting command means to wrap it around 416 An argument of N to a tag-inserting command means to wrap it around
415 the next N words. In Transient Mark mode, when the mark is active, 417 the next N words. In Transient Mark mode, when the mark is active,
416 N defaults to -1, which means to wrap it around the current region. 418 N defaults to -1, which means to wrap it around the current region.
417 419
418 If you like upcased tags, put (setq sgml-transformation 'upcase) in 420 If you like upcased tags, put (setq sgml-transformation-function 'upcase)
419 your `.emacs' file. 421 in your `.emacs' file.
420 422
421 Use \\[sgml-validate] to validate your document with an SGML parser. 423 Use \\[sgml-validate] to validate your document with an SGML parser.
422 424
423 Do \\[describe-variable] sgml- SPC to see available variables. 425 Do \\[describe-variable] sgml- SPC to see available variables.
424 Do \\[describe-key] on the following bindings to discover what they do. 426 Do \\[describe-key] on the following bindings to discover what they do.
458 (set (make-local-variable 'facemenu-add-face-function) 460 (set (make-local-variable 'facemenu-add-face-function)
459 'sgml-mode-facemenu-add-face-function) 461 'sgml-mode-facemenu-add-face-function)
460 (sgml-xml-guess) 462 (sgml-xml-guess)
461 (if sgml-xml-mode 463 (if sgml-xml-mode
462 (setq mode-name "XML") 464 (setq mode-name "XML")
463 (set (make-local-variable 'skeleton-transformation) sgml-transformation)) 465 (set (make-local-variable 'skeleton-transformation-function)
466 sgml-transformation-function))
464 ;; This will allow existing comments within declarations to be 467 ;; This will allow existing comments within declarations to be
465 ;; recognized. 468 ;; recognized.
466 (set (make-local-variable 'comment-start-skip) "\\(?:<!\\)?--[ \t]*") 469 (set (make-local-variable 'comment-start-skip) "\\(?:<!\\)?--[ \t]*")
467 (set (make-local-variable 'comment-end-skip) "[ \t]*--\\([ \t\n]*>\\)?") 470 (set (make-local-variable 'comment-end-skip) "[ \t]*--\\([ \t\n]*>\\)?")
468 ;; This definition has an HTML leaning but probably fits well for other modes. 471 ;; This definition has an HTML leaning but probably fits well for other modes.
602 (setq sgml-name-8bit-mode (not sgml-name-8bit-mode)) 605 (setq sgml-name-8bit-mode (not sgml-name-8bit-mode))
603 (message "sgml name entity mode is now %s" 606 (message "sgml name entity mode is now %s"
604 (if sgml-name-8bit-mode "ON" "OFF"))) 607 (if sgml-name-8bit-mode "ON" "OFF")))
605 608
606 ;; When an element of a skeleton is a string "str", it is passed 609 ;; When an element of a skeleton is a string "str", it is passed
607 ;; through skeleton-transformation and inserted. If "str" is to be 610 ;; through `skeleton-transformation-function' and inserted.
608 ;; inserted literally, one should obtain it as the return value of a 611 ;; If "str" is to be inserted literally, one should obtain it as
609 ;; function, e.g. (identity "str"). 612 ;; the return value of a function, e.g. (identity "str").
610 613
611 (defvar sgml-tag-last nil) 614 (defvar sgml-tag-last nil)
612 (defvar sgml-tag-history nil) 615 (defvar sgml-tag-history nil)
613 (define-skeleton sgml-tag 616 (define-skeleton sgml-tag
614 "Prompt for a tag and insert it, optionally with attributes. 617 "Prompt for a tag and insert it, optionally with attributes.
615 Completion and configuration are done according to `sgml-tag-alist'. 618 Completion and configuration are done according to `sgml-tag-alist'.
616 If you like tags and attributes in uppercase do \\[set-variable] 619 If you like tags and attributes in uppercase do \\[set-variable]
617 skeleton-transformation RET upcase RET, or put this in your `.emacs': 620 `skeleton-transformation-function' RET `upcase' RET, or put this
618 (setq sgml-transformation 'upcase)" 621 in your `.emacs':
619 (funcall (or skeleton-transformation 'identity) 622 (setq sgml-transformation-function 'upcase)"
623 (funcall (or skeleton-transformation-function 'identity)
620 (setq sgml-tag-last 624 (setq sgml-tag-last
621 (completing-read 625 (completing-read
622 (if (> (length sgml-tag-last) 0) 626 (if (> (length sgml-tag-last) 0)
623 (format "Tag (default %s): " sgml-tag-last) 627 (format "Tag (default %s): " sgml-tag-last)
624 "Tag: ") 628 "Tag: ")
637 ((symbolp v2) 641 ((symbolp v2)
638 ;; Make sure we don't fall into an infinite loop. 642 ;; Make sure we don't fall into an infinite loop.
639 ;; For xhtml's `tr' tag, we should maybe use \n instead. 643 ;; For xhtml's `tr' tag, we should maybe use \n instead.
640 (if (eq v2 t) (setq v2 nil)) 644 (if (eq v2 t) (setq v2 nil))
641 ;; We use `identity' to prevent skeleton from passing 645 ;; We use `identity' to prevent skeleton from passing
642 ;; `str' through skeleton-transformation a second time. 646 ;; `str' through `skeleton-transformation-function' a second time.
643 '(("") v2 _ v2 "</" (identity ',str) ?>)) 647 '(("") v2 _ v2 "</" (identity ',str) ?>))
644 ((eq (car v2) t) 648 ((eq (car v2) t)
645 (cons '("") (cdr v2))) 649 (cons '("") (cdr v2)))
646 (t 650 (t
647 (append '(("") (car v2)) 651 (append '(("") (car v2))
668 (or quiet 672 (or quiet
669 (message "No attributes configured.")) 673 (message "No attributes configured."))
670 (if (stringp (car alist)) 674 (if (stringp (car alist))
671 (progn 675 (progn
672 (insert (if (eq (preceding-char) ?\s) "" ?\s) 676 (insert (if (eq (preceding-char) ?\s) "" ?\s)
673 (funcall skeleton-transformation (car alist))) 677 (funcall skeleton-transformation-function (car alist)))
674 (sgml-value alist)) 678 (sgml-value alist))
675 (setq i (length alist)) 679 (setq i (length alist))
676 (while (> i 0) 680 (while (> i 0)
677 (insert ?\s) 681 (insert ?\s)
678 (insert (funcall skeleton-transformation 682 (insert (funcall skeleton-transformation-function
679 (setq attribute 683 (setq attribute
680 (skeleton-read '(completing-read 684 (skeleton-read '(completing-read
681 "Attribute: " 685 "Attribute: "
682 alist))))) 686 alist)))))
683 (if (string= "" attribute) 687 (if (string= "" attribute)
1979 ("Value: " 1983 ("Value: "
1980 "<input type=\"" (identity "checkbox") ; see comment above about identity 1984 "<input type=\"" (identity "checkbox") ; see comment above about identity
1981 "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: "))) 1985 "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: ")))
1982 "\" value=\"" str ?\" 1986 "\" value=\"" str ?\"
1983 (when (y-or-n-p "Set \"checked\" attribute? ") 1987 (when (y-or-n-p "Set \"checked\" attribute? ")
1984 (funcall skeleton-transformation 1988 (funcall skeleton-transformation-function
1985 (if sgml-xml-mode " checked=\"checked\"" " checked"))) 1989 (if sgml-xml-mode " checked=\"checked\"" " checked")))
1986 (if sgml-xml-mode " />" ">") 1990 (if sgml-xml-mode " />" ">")
1987 (skeleton-read "Text: " (capitalize str)) 1991 (skeleton-read "Text: " (capitalize str))
1988 (or v2 (setq v2 (if (y-or-n-p "Newline after text? ") 1992 (or v2 (setq v2 (if (y-or-n-p "Newline after text? ")
1989 (funcall skeleton-transformation 1993 (funcall skeleton-transformation-function
1990 (if sgml-xml-mode "<br />" "<br>")) 1994 (if sgml-xml-mode "<br />" "<br>"))
1991 ""))) 1995 "")))
1992 \n)) 1996 \n))
1993 1997
1994 (define-skeleton html-radio-buttons 1998 (define-skeleton html-radio-buttons
1999 ("Value: " 2003 ("Value: "
2000 "<input type=\"" (identity "radio") ; see comment above about identity 2004 "<input type=\"" (identity "radio") ; see comment above about identity
2001 "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: "))) 2005 "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: ")))
2002 "\" value=\"" str ?\" 2006 "\" value=\"" str ?\"
2003 (when (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? "))) 2007 (when (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? ")))
2004 (funcall skeleton-transformation 2008 (funcall skeleton-transformation-function
2005 (if sgml-xml-mode " checked=\"checked\"" " checked"))) 2009 (if sgml-xml-mode " checked=\"checked\"" " checked")))
2006 (if sgml-xml-mode " />" ">") 2010 (if sgml-xml-mode " />" ">")
2007 (skeleton-read "Text: " (capitalize str)) 2011 (skeleton-read "Text: " (capitalize str))
2008 (or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ") 2012 (or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ")
2009 (funcall skeleton-transformation 2013 (funcall skeleton-transformation-function
2010 (if sgml-xml-mode "<br />" "<br>")) 2014 (if sgml-xml-mode "<br />" "<br>"))
2011 ""))) 2015 "")))
2012 \n)) 2016 \n))
2013 2017
2014 (provide 'sgml-mode) 2018 (provide 'sgml-mode)