12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177 |
- (eval-when-compile
- (require 'skeleton)
- (require 'outline)
- (require 'cl))
- (defgroup sgml nil
- "SGML editing mode."
- :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
- :group 'languages)
- (defcustom sgml-basic-offset 2
- "Specifies the basic indentation level for `sgml-indent-line'."
- :type 'integer
- :group 'sgml)
- (defcustom sgml-transformation-function 'identity
- "Default value for `skeleton-transformation-function' in SGML mode."
- :type 'function
- :group 'sgml)
- (put 'sgml-transformation-function 'variable-interactive
- "aTransformation function: ")
- (defvaralias 'sgml-transformation 'sgml-transformation-function)
- (defcustom sgml-mode-hook nil
- "Hook run by command `sgml-mode'.
- `text-mode-hook' is run first."
- :group 'sgml
- :type 'hook)
- (defvar sgml-specials '(?\")
- "List of characters that have a special meaning for SGML mode.
- This list is used when first loading the `sgml-mode' library.
- The supported characters and potential disadvantages are:
- ?\\\" Makes \" in text start a string.
- ?' Makes ' in text start a string.
- ?- Makes -- in text start a comment.
- When only one of ?\\\" or ?' are included, \"'\" or '\"', as can be found in
- DTDs, start a string. To partially avoid this problem this also makes these
- self insert as named entities depending on `sgml-quick-keys'.
- Including ?- has the problem of affecting dashes that have nothing to do
- with comments, so we normally turn it off.")
- (defvar sgml-quick-keys nil
- "Use <, >, &, /, SPC and `sgml-specials' keys \"electrically\" when non-nil.
- This takes effect when first loading the `sgml-mode' library.")
- (defvar sgml-mode-map
- (let ((map (make-keymap))
- (menu-map (make-sparse-keymap "SGML")))
- (define-key map "\C-c\C-i" 'sgml-tags-invisible)
- (define-key map "/" 'sgml-slash)
- (define-key map "\C-c\C-n" 'sgml-name-char)
- (define-key map "\C-c\C-t" 'sgml-tag)
- (define-key map "\C-c\C-a" 'sgml-attributes)
- (define-key map "\C-c\C-b" 'sgml-skip-tag-backward)
- (define-key map [?\C-c left] 'sgml-skip-tag-backward)
- (define-key map "\C-c\C-f" 'sgml-skip-tag-forward)
- (define-key map [?\C-c right] 'sgml-skip-tag-forward)
- (define-key map "\C-c\C-d" 'sgml-delete-tag)
- (define-key map "\C-c\^?" 'sgml-delete-tag)
- (define-key map "\C-c?" 'sgml-tag-help)
- (define-key map "\C-c]" 'sgml-close-tag)
- (define-key map "\C-c/" 'sgml-close-tag)
-
- (define-key map "\C-c\C-o" 'sgml-tag)
- (define-key map "\C-c\C-e" 'sgml-close-tag)
- (define-key map "\C-c8" 'sgml-name-8bit-mode)
- (define-key map "\C-c\C-v" 'sgml-validate)
- (when sgml-quick-keys
- (define-key map "&" 'sgml-name-char)
- (define-key map "<" 'sgml-tag)
- (define-key map " " 'sgml-auto-attributes)
- (define-key map ">" 'sgml-maybe-end-tag)
- (when (memq ?\" sgml-specials)
- (define-key map "\"" 'sgml-name-self))
- (when (memq ?' sgml-specials)
- (define-key map "'" 'sgml-name-self)))
- (let ((c 127)
- (map (nth 1 map)))
- (while (< (setq c (1+ c)) 256)
- (aset map c 'sgml-maybe-name-self)))
- (define-key map [menu-bar sgml] (cons "SGML" menu-map))
- (define-key menu-map [sgml-validate] '("Validate" . sgml-validate))
- (define-key menu-map [sgml-name-8bit-mode]
- '("Toggle 8 Bit Insertion" . sgml-name-8bit-mode))
- (define-key menu-map [sgml-tags-invisible]
- '("Toggle Tag Visibility" . sgml-tags-invisible))
- (define-key menu-map [sgml-tag-help]
- '("Describe Tag" . sgml-tag-help))
- (define-key menu-map [sgml-delete-tag]
- '("Delete Tag" . sgml-delete-tag))
- (define-key menu-map [sgml-skip-tag-forward]
- '("Forward Tag" . sgml-skip-tag-forward))
- (define-key menu-map [sgml-skip-tag-backward]
- '("Backward Tag" . sgml-skip-tag-backward))
- (define-key menu-map [sgml-attributes]
- '("Insert Attributes" . sgml-attributes))
- (define-key menu-map [sgml-tag] '("Insert Tag" . sgml-tag))
- map)
- "Keymap for SGML mode. See also `sgml-specials'.")
- (defun sgml-make-syntax-table (specials)
- (let ((table (make-syntax-table text-mode-syntax-table)))
- (modify-syntax-entry ?< "(>" table)
- (modify-syntax-entry ?> ")<" table)
- (modify-syntax-entry ?: "_" table)
- (modify-syntax-entry ?_ "_" table)
- (modify-syntax-entry ?. "_" table)
- (if (memq ?- specials)
- (modify-syntax-entry ?- "_ 1234" table))
- (if (memq ?\" specials)
- (modify-syntax-entry ?\" "\"\"" table))
- (if (memq ?' specials)
- (modify-syntax-entry ?\' "\"'" table))
- table))
- (defvar sgml-mode-syntax-table (sgml-make-syntax-table sgml-specials)
- "Syntax table used in SGML mode. See also `sgml-specials'.")
- (defconst sgml-tag-syntax-table
- (let ((table (sgml-make-syntax-table sgml-specials)))
- (dolist (char '(?\( ?\) ?\{ ?\} ?\[ ?\] ?$ ?% ?& ?* ?+ ?/))
- (modify-syntax-entry char "." table))
- (unless (memq ?' sgml-specials)
-
- (modify-syntax-entry ?' "w" table))
- table)
- "Syntax table used to parse SGML tags.")
- (defcustom sgml-name-8bit-mode nil
- "When non-nil, insert non-ASCII characters as named entities."
- :type 'boolean
- :group 'sgml)
- (defvar sgml-char-names
- [nil nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- "nbsp" "excl" "quot" "num" "dollar" "percnt" "amp" "apos"
- "lpar" "rpar" "ast" "plus" "comma" "hyphen" "period" "sol"
- nil nil nil nil nil nil nil nil
- nil nil "colon" "semi" "lt" "eq" "gt" "quest"
- "commat" nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- nil nil nil "lsqb" nil "rsqb" "uarr" "lowbar"
- "lsquo" nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- nil nil nil "lcub" "verbar" "rcub" "tilde" nil
- nil nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- nil nil nil nil nil nil nil nil
- "nbsp" "iexcl" "cent" "pound" "curren" "yen" "brvbar" "sect"
- "uml" "copy" "ordf" "laquo" "not" "shy" "reg" "macr"
- "ring" "plusmn" "sup2" "sup3" "acute" "micro" "para" "middot"
- "cedil" "sup1" "ordm" "raquo" "frac14" "frac12" "frac34" "iquest"
- "Agrave" "Aacute" "Acirc" "Atilde" "Auml" "Aring" "AElig" "Ccedil"
- "Egrave" "Eacute" "Ecirc" "Euml" "Igrave" "Iacute" "Icirc" "Iuml"
- "ETH" "Ntilde" "Ograve" "Oacute" "Ocirc" "Otilde" "Ouml" nil
- "Oslash" "Ugrave" "Uacute" "Ucirc" "Uuml" "Yacute" "THORN" "szlig"
- "agrave" "aacute" "acirc" "atilde" "auml" "aring" "aelig" "ccedil"
- "egrave" "eacute" "ecirc" "euml" "igrave" "iacute" "icirc" "iuml"
- "eth" "ntilde" "ograve" "oacute" "ocirc" "otilde" "ouml" "divide"
- "oslash" "ugrave" "uacute" "ucirc" "uuml" "yacute" "thorn" "yuml"]
- "Vector of symbolic character names without `&' and `;'.")
- (put 'sgml-table 'char-table-extra-slots 0)
- (defvar sgml-char-names-table
- (let ((table (make-char-table 'sgml-table))
- (i 32)
- elt)
- (while (< i 128)
- (setq elt (aref sgml-char-names i))
- (if elt (aset table (make-char 'latin-iso8859-1 i) elt))
- (setq i (1+ i)))
- table)
- "A table for mapping non-ASCII characters into SGML entity names.
- Currently, only Latin-1 characters are supported.")
- (defcustom sgml-validate-command "nsgmls -s"
- "The command to validate an SGML document.
- The file name of current buffer file name will be appended to this,
- separated by a space."
- :type 'string
- :version "21.1"
- :group 'sgml)
- (defvar sgml-saved-validate-command nil
- "The command last used to validate in this buffer.")
- (defcustom sgml-slash-distance 1000
- "If non-nil, is the maximum distance to search for matching `/'."
- :type '(choice (const nil) integer)
- :group 'sgml)
- (defconst sgml-namespace-re "[_[:alpha:]][-_.[:alnum:]]*")
- (defconst sgml-name-re "[_:[:alpha:]][-_.:[:alnum:]]*")
- (defconst sgml-tag-name-re (concat "<\\([!/?]?" sgml-name-re "\\)"))
- (defconst sgml-attrs-re "\\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*")
- (defconst sgml-start-tag-regex (concat "<" sgml-name-re sgml-attrs-re)
- "Regular expression that matches a non-empty start tag.
- Any terminating `>' or `/' is not matched.")
- (defface sgml-namespace
- '((t (:inherit font-lock-builtin-face)))
- "`sgml-mode' face used to highlight the namespace part of identifiers."
- :group 'sgml)
- (defvar sgml-namespace-face 'sgml-namespace)
- (defconst sgml-font-lock-keywords-1
- `((,(concat "<\\([!?]" sgml-name-re "\\)") 1 font-lock-keyword-face)
-
-
- (,(concat "</?\\(" sgml-namespace-re "\\)\\(?::\\(" sgml-name-re "\\)\\)?")
- (1 (if (match-end 2) sgml-namespace-face font-lock-function-name-face))
- (2 font-lock-function-name-face nil t))
-
-
-
-
- (,(concat "\\(?:^\\|[ \t]\\)\\(" sgml-namespace-re "\\)\\(?::\\("
- sgml-name-re "\\)\\)?=[\"']")
- (1 (if (match-end 2) sgml-namespace-face font-lock-variable-name-face))
- (2 font-lock-variable-name-face nil t))
- (,(concat "[&%]" sgml-name-re ";?") . font-lock-variable-name-face)))
- (defconst sgml-font-lock-keywords-2
- (append
- sgml-font-lock-keywords-1
- '((eval
- . (cons (concat "<"
- (regexp-opt (mapcar 'car sgml-tag-face-alist) t)
- "\\([ \t][^>]*\\)?>\\([^<]+\\)</\\1>")
- '(3 (cdr (assoc-string (match-string 1) sgml-tag-face-alist t))
- prepend))))))
- (defvar sgml-font-lock-keywords sgml-font-lock-keywords-1
- "*Rules for highlighting SGML code. See also `sgml-tag-face-alist'.")
- (defconst sgml-syntax-propertize-function
- (syntax-propertize-rules
-
-
-
- ("\\(<\\)!--" (1 "< b"))
- ("--[ \t\n]*\\(>\\)" (1 "> b"))
-
-
-
- ("\"" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
- (goto-char (match-end 0)))
- "."))))
- "Syntactic keywords for `sgml-mode'.")
- (defvar sgml-face-tag-alist ()
- "Alist of face and tag name for facemenu.")
- (defvar sgml-tag-face-alist ()
- "Tag names and face or list of faces to fontify with when invisible.
- When `font-lock-maximum-decoration' is 1 this is always used for fontifying.
- When more these are fontified together with `sgml-font-lock-keywords'.")
- (defvar sgml-display-text ()
- "Tag names as lowercase symbols, and display string when invisible.")
- (defvar sgml-tags-invisible nil)
- (defcustom sgml-tag-alist
- '(("![" ("ignore" t) ("include" t))
- ("!attlist")
- ("!doctype")
- ("!element")
- ("!entity"))
- "Alist of tag names for completing read and insertion rules.
- This alist is made up as
- ((\"tag\" . TAGRULE)
- ...)
- TAGRULE is a list of optionally t (no endtag) or `\\n' (separate endtag by
- newlines) or a skeleton with nil, t or `\\n' in place of the interactor
- followed by an ATTRIBUTERULE (for an always present attribute) or an
- attribute alist.
- The attribute alist is made up as
- ((\"attribute\" . ATTRIBUTERULE)
- ...)
- ATTRIBUTERULE is a list of optionally t (no value when no input) followed by
- an optional alist of possible values."
- :type '(repeat (cons (string :tag "Tag Name")
- (repeat :tag "Tag Rule" sexp)))
- :group 'sgml)
- (put 'sgml-tag-alist 'risky-local-variable t)
- (defcustom sgml-tag-help
- '(("!" . "Empty declaration for comment")
- ("![" . "Embed declarations with parser directive")
- ("!attlist" . "Tag attributes declaration")
- ("!doctype" . "Document type (DTD) declaration")
- ("!element" . "Tag declaration")
- ("!entity" . "Entity (macro) declaration"))
- "Alist of tag name and short description."
- :type '(repeat (cons (string :tag "Tag Name")
- (string :tag "Description")))
- :group 'sgml)
- (defcustom sgml-xml-mode nil
- "When non-nil, tag insertion functions will be XML-compliant.
- It is set to be buffer-local when the file has
- a DOCTYPE or an XML declaration."
- :type 'boolean
- :version "22.1"
- :group 'sgml)
- (defvar sgml-empty-tags nil
- "List of tags whose !ELEMENT definition says EMPTY.")
- (defvar sgml-unclosed-tags nil
- "List of tags whose !ELEMENT definition says the end-tag is optional.")
- (defun sgml-xml-guess ()
- "Guess whether the current buffer is XML. Return non-nil if so."
- (save-excursion
- (goto-char (point-min))
- (or (string= "xml" (file-name-extension (or buffer-file-name "")))
-
- (and (zerop (buffer-size))
- (string= "xhtml" (file-name-extension (or buffer-file-name ""))))
- (looking-at "\\s-*<\\?xml")
- (when (re-search-forward
- (eval-when-compile
- (mapconcat 'identity
- '("<!DOCTYPE" "\\(\\w+\\)" "\\(\\w+\\)"
- "\"\\([^\"]+\\)\"" "\"\\([^\"]+\\)\"")
- "\\s-+"))
- nil t)
- (string-match "X\\(HT\\)?ML" (match-string 3))))))
- (defvar v2)
- (defun sgml-comment-indent-new-line (&optional soft)
- (let ((-start "-- ")
- (-start-skip "\\(<!\\)?--[ \t]*")
- (-end " --")
- (-style 'plain))
- (-indent-new-line soft)))
- (defun sgml-mode-facemenu-add-face-function (face end)
- (let ((tag-face (cdr (assq face sgml-face-tag-alist))))
- (cond (tag-face
- (setq tag-face (funcall skeleton-transformation-function tag-face))
- (setq facemenu-end-add-face (concat "</" tag-face ">"))
- (concat "<" tag-face ">"))
- ((and (consp face)
- (consp (car face))
- (null (cdr face))
- (memq (caar face) '(:foreground :background)))
- (setq facemenu-end-add-face "</span>")
- (format "<span style=\"%s:%s\">"
- (if (eq (caar face) :foreground)
- "color"
- "background-color")
- (cadr (car face))))
- (t
- (error "Face not configured for %s mode"
- (format-mode-line mode-name))))))
- (defun sgml-fill-nobreak ()
- "Don't break between a tag name and its first argument.
- This function is designed for use in `fill-nobreak-predicate'.
- <a href=\"some://where\" type=\"text/plain\">
- ^ ^
- | no break here | but still allowed here"
- (save-excursion
- (skip-chars-backward " \t")
- (and (not (zerop (skip-syntax-backward "w_")))
- (skip-chars-backward "/?!")
- (eq (char-before) ?<))))
- (define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "SGML")
- "Major mode for editing SGML documents.
- Makes > match <.
- Keys <, &, SPC within <>, \", / and ' can be electric depending on
- `sgml-quick-keys'.
- An argument of N to a tag-inserting command means to wrap it around
- the next N words. In Transient Mark mode, when the mark is active,
- N defaults to -1, which means to wrap it around the current region.
- If you like upcased tags, put (setq sgml-transformation-function 'upcase)
- in your `.emacs' file.
- Use \\[sgml-validate] to validate your document with an SGML parser.
- Do \\[describe-variable] sgml- SPC to see available variables.
- Do \\[describe-key] on the following bindings to discover what they do.
- \\{sgml-mode-map}"
- (make-local-variable 'sgml-saved-validate-command)
- (make-local-variable 'facemenu-end-add-face)
-
-
-
-
- (set (make-local-variable 'paragraph-start) (concat "[ \t]*$\\|\
- \[ \t]*</?\\(" sgml-name-re sgml-attrs-re "\\)?>"))
- (set (make-local-variable 'paragraph-separate)
- (concat paragraph-start "$"))
- (set (make-local-variable 'adaptive-fill-regexp) "[ \t]*")
- (add-hook 'fill-nobreak-predicate 'sgml-fill-nobreak nil t)
- (set (make-local-variable 'indent-line-function) 'sgml-indent-line)
- (set (make-local-variable 'comment-start) "<!-- ")
- (set (make-local-variable 'comment-end) " -->")
- (set (make-local-variable 'comment-indent-function) 'sgml-comment-indent)
- (set (make-local-variable 'comment-line-break-function)
- 'sgml-comment-indent-new-line)
- (set (make-local-variable 'skeleton-further-elements)
- '((completion-ignore-case t)))
- (set (make-local-variable 'skeleton-end-hook)
- (lambda ()
- (or (eolp)
- (not (or (eq v2 '\n) (eq (car-safe v2) '\n)))
- (newline-and-indent))))
- (set (make-local-variable 'font-lock-defaults)
- '((sgml-font-lock-keywords
- sgml-font-lock-keywords-1
- sgml-font-lock-keywords-2)
- nil t))
- (set (make-local-variable 'syntax-propertize-function)
- sgml-syntax-propertize-function)
- (set (make-local-variable 'facemenu-add-face-function)
- 'sgml-mode-facemenu-add-face-function)
- (set (make-local-variable 'sgml-xml-mode) (sgml-xml-guess))
- (if sgml-xml-mode
- ()
- (set (make-local-variable 'skeleton-transformation-function)
- sgml-transformation-function))
-
-
-
-
-
-
- (set (make-local-variable 'comment-start-skip) "<!--[ \t]*")
- (set (make-local-variable 'comment-end-skip) "[ \t]*--[ \t\n]*>")
-
- (setq imenu-generic-expression
- `((nil
- ,(concat "<!\\(element\\|entity\\)[ \t\n]+%?[ \t\n]*\\("
- sgml-name-re "\\)")
- 2)
- ("Id"
- ,(concat "<[^>]+[ \t\n]+[Ii][Dd]=\\(['\"]"
- (if sgml-xml-mode "" "?")
- "\\)\\(" sgml-name-re "\\)\\1")
- 2)
- ("Name"
- ,(concat "<[^>]+[ \t\n]+[Nn][Aa][Mm][Ee]=\\(['\"]"
- (if sgml-xml-mode "" "?")
- "\\)\\(" sgml-name-re "\\)\\1")
- 2))))
- (defun sgml-comment-indent ()
- (if (looking-at "--") comment-column 0))
- (defun sgml-slash (arg)
- "Insert ARG slash characters.
- Behaves electrically if `sgml-quick-keys' is non-nil."
- (interactive "p")
- (cond
- ((not (and (eq (char-before) ?<) (= arg 1)))
- (sgml-slash-matching arg))
- ((eq sgml-quick-keys 'indent)
- (insert-char ?/ 1)
- (indent-according-to-mode))
- ((eq sgml-quick-keys 'close)
- (delete-char -1)
- (sgml-close-tag))
- (t
- (sgml-slash-matching arg))))
- (defun sgml-slash-matching (arg)
- "Insert `/' and display any previous matching `/'.
- Two `/'s are treated as matching if the first `/' ends a net-enabling
- start tag, and the second `/' is the corresponding null end tag."
- (interactive "p")
- (insert-char ?/ arg)
- (if (> arg 0)
- (let ((oldpos (point))
- (blinkpos)
- (level 0))
- (save-excursion
- (save-restriction
- (if sgml-slash-distance
- (narrow-to-region (max (point-min)
- (- (point) sgml-slash-distance))
- oldpos))
- (if (and (re-search-backward sgml-start-tag-regex (point-min) t)
- (eq (match-end 0) (1- oldpos)))
- ()
- (goto-char (1- oldpos))
- (while (and (not blinkpos)
- (search-backward "/" (point-min) t))
- (let ((tagend (save-excursion
- (if (re-search-backward sgml-start-tag-regex
- (point-min) t)
- (match-end 0)
- nil))))
- (if (eq tagend (point))
- (if (eq level 0)
- (setq blinkpos (point))
- (setq level (1- level)))
- (setq level (1+ level)))))))
- (when blinkpos
- (goto-char blinkpos)
- (if (pos-visible-in-window-p)
- (sit-for 1)
- (message "Matches %s"
- (buffer-substring (line-beginning-position)
- (1+ blinkpos)))))))))
- (defun sgml-name-char (&optional char)
- "Insert a symbolic character name according to `sgml-char-names'.
- Non-ASCII chars may be inserted either with the meta key, as in M-SPC for
- no-break space or M-- for a soft hyphen; or via an input method or
- encoded keyboard operation."
- (interactive "*")
- (insert ?&)
- (or char
- (setq char (read-quoted-char "Enter char or octal number")))
- (delete-char -1)
- (insert char)
- (undo-boundary)
- (sgml-namify-char))
- (defun sgml-namify-char ()
- "Change the char before point into its `&name;' equivalent.
- Uses `sgml-char-names'."
- (interactive)
- (let* ((char (char-before))
- (name
- (cond
- ((null char) (error "No char before point"))
- ((< char 256) (or (aref sgml-char-names char) char))
- ((aref sgml-char-names-table char))
- ((encode-char char 'ucs)))))
- (if (not name)
- (error "Don't know the name of `%c'" char)
- (delete-char -1)
- (insert (format (if (numberp name) "&#%d;" "&%s;") name)))))
- (defun sgml-name-self ()
- "Insert a symbolic character name according to `sgml-char-names'."
- (interactive "*")
- (sgml-name-char last-command-event))
- (defun sgml-maybe-name-self ()
- "Insert a symbolic character name according to `sgml-char-names'."
- (interactive "*")
- (if sgml-name-8bit-mode
- (sgml-name-char last-command-event)
- (self-insert-command 1)))
- (defun sgml-name-8bit-mode ()
- "Toggle whether to insert named entities instead of non-ASCII characters.
- This only works for Latin-1 input."
- (interactive)
- (setq sgml-name-8bit-mode (not sgml-name-8bit-mode))
- (message "sgml name entity mode is now %s"
- (if sgml-name-8bit-mode "ON" "OFF")))
- (defvar sgml-tag-last nil)
- (defvar sgml-tag-history nil)
- (define-skeleton sgml-tag
- "Prompt for a tag and insert it, optionally with attributes.
- Completion and configuration are done according to `sgml-tag-alist'.
- If you like tags and attributes in uppercase do \\[set-variable]
- `skeleton-transformation-function' RET `upcase' RET, or put this
- in your `.emacs':
- (setq sgml-transformation-function 'upcase)"
- (funcall (or skeleton-transformation-function 'identity)
- (setq sgml-tag-last
- (completing-read
- (if (> (length sgml-tag-last) 0)
- (format "Tag (default %s): " sgml-tag-last)
- "Tag: ")
- sgml-tag-alist nil nil nil 'sgml-tag-history sgml-tag-last)))
- ?< str |
- (("") -1 '(undo-boundary) (identity "<")) |
- `(("") '(setq v2 (sgml-attributes ,str t)) ?>
- (cond
- ((string= "![" ,str)
- (backward-char)
- '(("") " [ " _ " ]]"))
- ((and (eq v2 t) sgml-xml-mode (member ,str sgml-empty-tags))
- '(("") -1 " />"))
- ((or (and (eq v2 t) (not sgml-xml-mode)) (string-match "^[/!?]" ,str))
- nil)
- ((symbolp v2)
-
-
- (if (eq v2 t) (setq v2 nil))
-
-
- '(("") v2 _ v2 "</" (identity ',str) ?>))
- ((eq (car v2) t)
- (cons '("") (cdr v2)))
- (t
- (append '(("") (car v2))
- (cdr v2)
- '(resume: (car v2) _ "</" (identity ',str) ?>))))))
- (autoload 'skeleton-read "skeleton")
- (defun sgml-attributes (tag &optional quiet)
- "When at top level of a tag, interactively insert attributes.
- Completion and configuration of TAG are done according to `sgml-tag-alist'.
- If QUIET, do not print a message when there are no attributes for TAG."
- (interactive (list (save-excursion (sgml-beginning-of-tag t))))
- (or (stringp tag) (error "Wrong context for adding attribute"))
- (if tag
- (let ((completion-ignore-case t)
- (alist (cdr (assoc (downcase tag) sgml-tag-alist)))
- car attribute i)
- (if (or (symbolp (car alist))
- (symbolp (car (car alist))))
- (setq car (car alist)
- alist (cdr alist)))
- (or quiet
- (message "No attributes configured."))
- (if (stringp (car alist))
- (progn
- (insert (if (eq (preceding-char) ?\s) "" ?\s)
- (funcall skeleton-transformation-function (car alist)))
- (sgml-value alist))
- (setq i (length alist))
- (while (> i 0)
- (insert ?\s)
- (insert (funcall skeleton-transformation-function
- (setq attribute
- (skeleton-read '(completing-read
- "Attribute: "
- alist)))))
- (if (string= "" attribute)
- (setq i 0)
- (sgml-value (assoc (downcase attribute) alist))
- (setq i (1- i))))
- (if (eq (preceding-char) ?\s)
- (delete-char -1)))
- car)))
- (defun sgml-auto-attributes (arg)
- "Self insert the character typed; at top level of tag, prompt for attributes.
- With prefix argument, only self insert."
- (interactive "*P")
- (let ((point (point))
- tag)
- (if (or arg
- (not sgml-tag-alist)
- (symbolp (setq tag (save-excursion (sgml-beginning-of-tag t))))
- (eq (aref tag 0) ?/))
- (self-insert-command (prefix-numeric-value arg))
- (sgml-attributes tag)
- (setq last-command-event ?\s)
- (or (> (point) point)
- (self-insert-command 1)))))
- (defun sgml-tag-help (&optional tag)
- "Display description of tag TAG. If TAG is omitted, use the tag at point."
- (interactive
- (list (let ((def (save-excursion
- (if (eq (following-char) ?<) (forward-char))
- (sgml-beginning-of-tag))))
- (completing-read (if def
- (format "Tag (default %s): " def)
- "Tag: ")
- sgml-tag-alist nil nil nil
- 'sgml-tag-history def))))
- (or (and tag (> (length tag) 0))
- (save-excursion
- (if (eq (following-char) ?<)
- (forward-char))
- (setq tag (sgml-beginning-of-tag))))
- (or (stringp tag)
- (error "No tag selected"))
- (setq tag (downcase tag))
- (message "%s"
- (or (cdr (assoc (downcase tag) sgml-tag-help))
- (and (eq (aref tag 0) ?/)
- (cdr (assoc (downcase (substring tag 1)) sgml-tag-help)))
- "No description available")))
- (defun sgml-maybe-end-tag (&optional arg)
- "Name self unless in position to end a tag or a prefix ARG is given."
- (interactive "P")
- (if (or arg (eq (car (sgml-lexical-context)) 'tag))
- (self-insert-command (prefix-numeric-value arg))
- (sgml-name-self)))
- (defun sgml-skip-tag-backward (arg)
- "Skip to beginning of tag or matching opening tag if present.
- With prefix argument ARG, repeat this ARG times.
- Return non-nil if we skipped over matched tags."
- (interactive "p")
-
- (let ((return t))
- (while (>= arg 1)
- (search-backward "<" nil t)
- (if (looking-at "</\\([^ \n\t>]+\\)")
-
- (let ((case-fold-search t)
- (re (concat "</?" (regexp-quote (match-string 1))
-
- "\\([^>]*[^/>]\\)?>")))
- (while (and (re-search-backward re nil t)
- (eq (char-after (1+ (point))) ?/))
- (forward-char 1)
- (sgml-skip-tag-backward 1)))
- (setq return nil))
- (setq arg (1- arg)))
- return))
- (defvar sgml-electric-tag-pair-overlays nil)
- (defvar sgml-electric-tag-pair-timer nil)
- (defun sgml-electric-tag-pair-before-change-function (beg end)
- (condition-case err
- (save-excursion
- (goto-char end)
- (skip-chars-backward "[:alnum:]-_.:")
- (if (and
- (or (eq (char-before) ?<)
- (and (eq (char-before) ?/)
- (eq (char-before (1- (point))) ?<)))
- (null (get-char-property (point) 'text-clones)))
- (let* ((endp (eq (char-before) ?/))
- (cl-start (point))
- (cl-end (progn (skip-chars-forward "[:alnum:]-_.:") (point)))
- (match
- (if endp
- (when (sgml-skip-tag-backward 1) (forward-char 1) t)
- (with-syntax-table sgml-tag-syntax-table
- (up-list -1)
- (when (sgml-skip-tag-forward 1)
- (backward-sexp 1)
- (forward-char 2)
- t))))
- (clones (get-char-property (point) 'text-clones)))
- (when (and match
- (/= cl-end cl-start)
- (equal (buffer-substring cl-start cl-end)
- (buffer-substring (point)
- (save-excursion
- (skip-chars-forward "[:alnum:]-_.:")
- (point))))
- (or (not endp) (eq (char-after cl-end) ?>)))
- (when clones
- (message "sgml-electric-tag-pair-before-change-function: deleting old OLs")
- (mapc 'delete-overlay clones))
- (message "sgml-electric-tag-pair-before-change-function: new clone")
- (text-clone-create cl-start cl-end 'spread "[[:alnum:]-_.:]+")
- (setq sgml-electric-tag-pair-overlays
- (append (get-char-property (point) 'text-clones)
- sgml-electric-tag-pair-overlays))))))
- (scan-error nil)
- (error (message "Error in sgml-electric-pair-mode: %s" err))))
- (defun sgml-electric-tag-pair-flush-overlays ()
- (while sgml-electric-tag-pair-overlays
- (delete-overlay (pop sgml-electric-tag-pair-overlays))))
- (define-minor-mode sgml-electric-tag-pair-mode
- "Toggle SGML Electric Tag Pair mode.
- With a prefix argument ARG, enable the mode if ARG is positive,
- and disable it otherwise. If called from Lisp, enable the mode
- if ARG is omitted or nil.
- SGML Electric Tag Pair mode is a buffer-local minor mode for use
- with `sgml-mode' and related major modes. When enabled, editing
- an opening markup tag automatically updates the closing tag."
- :lighter "/e"
- (if sgml-electric-tag-pair-mode
- (progn
- (add-hook 'before-change-functions
- 'sgml-electric-tag-pair-before-change-function
- nil t)
- (unless sgml-electric-tag-pair-timer
- (setq sgml-electric-tag-pair-timer
- (run-with-idle-timer 5 'repeat 'sgml-electric-tag-pair-flush-overlays))))
- (remove-hook 'before-change-functions
- 'sgml-electric-tag-pair-before-change-function
- t)
-
- ))
- (defun sgml-skip-tag-forward (arg)
- "Skip to end of tag or matching closing tag if present.
- With prefix argument ARG, repeat this ARG times.
- Return t if after a closing tag."
- (interactive "p")
-
-
-
- (let ((return t))
- (with-syntax-table sgml-tag-syntax-table
- (while (>= arg 1)
- (skip-chars-forward "^<>")
- (if (eq (following-char) ?>)
- (up-list -1))
- (if (looking-at "<\\([^/ \n\t>]+\\)\\([^>]*[^/>]\\)?>")
-
- (let ((case-fold-search t)
- (re (concat "</?" (regexp-quote (match-string 1))
-
- "\\([^>]*[^/>]\\)?>"))
- point close)
- (forward-list 1)
- (setq point (point))
-
-
- (while (and (re-search-forward re nil t)
- (not (setq close
- (eq (char-after (1+ (match-beginning 0))) ?/)))
- (goto-char (match-beginning 0))
- (sgml-skip-tag-forward 1))
- (setq close nil))
- (unless close
- (goto-char point)
- (setq return nil)))
- (forward-list 1))
- (setq arg (1- arg)))
- return)))
- (defsubst sgml-looking-back-at (str)
- "Return t if the test before point matches STR."
- (let ((start (- (point) (length str))))
- (and (>= start (point-min))
- (equal str (buffer-substring-no-properties start (point))))))
- (defun sgml-delete-tag (arg)
-
- "Delete tag on or after cursor, and matching closing or opening tag.
- With prefix argument ARG, repeat this ARG times."
- (interactive "p")
- (while (>= arg 1)
- (save-excursion
- (let* (close open)
- (if (looking-at "[ \t\n]*<")
-
- (if (eq (char-after (match-end 0)) ?/)
-
- (progn
- (setq close (point))
- (goto-char (match-end 0))))
-
- (or (save-excursion (setq close (sgml-beginning-of-tag)
- close (and (stringp close)
- (eq (aref close 0) ?/)
- (point))))
-
- (let ((point (point)))
- (sgml-skip-tag-backward 1)
- (if (or (not (eq (following-char) ?<))
- (save-excursion
- (forward-list 1)
- (<= (point) point)))
- (error "Not on or before tag")))))
- (if close
- (progn
- (sgml-skip-tag-backward 1)
- (setq open (point))
- (goto-char close)
- (kill-sexp 1))
- (setq open (point))
- (when (and (sgml-skip-tag-forward 1)
- (not (sgml-looking-back-at "/>")))
- (kill-sexp -1)))
-
-
- (if (progn (forward-line 0) (looking-at "\\(?:[ \t]*$\\)\n?"))
- (delete-region (match-beginning 0) (match-end 0)))
- (goto-char open)
- (kill-sexp 1)
- (if (progn (forward-line 0) (looking-at "\\(?:[ \t]*$\\)\n?"))
- (delete-region (match-beginning 0) (match-end 0)))))
- (setq arg (1- arg))))
- (or (get 'sgml-tag 'invisible)
- (setplist 'sgml-tag
- (append '(invisible t
- point-entered sgml-point-entered
- rear-nonsticky t
- read-only t)
- (symbol-plist 'sgml-tag))))
- (defun sgml-tags-invisible (arg)
- "Toggle visibility of existing tags."
- (interactive "P")
- (let ((modified (buffer-modified-p))
- (inhibit-read-only t)
- (inhibit-modification-hooks t)
-
- (buffer-file-name nil)
-
-
-
- (inhibit-point-motion-hooks t)
- string)
- (unwind-protect
- (save-excursion
- (goto-char (point-min))
- (if (set (make-local-variable 'sgml-tags-invisible)
- (if arg
- (>= (prefix-numeric-value arg) 0)
- (not sgml-tags-invisible)))
- (while (re-search-forward sgml-tag-name-re nil t)
- (setq string
- (cdr (assq (intern-soft (downcase (match-string 1)))
- sgml-display-text)))
- (goto-char (match-beginning 0))
- (and (stringp string)
- (not (overlays-at (point)))
- (let ((ol (make-overlay (point) (match-beginning 1))))
- (overlay-put ol 'before-string string)
- (overlay-put ol 'sgml-tag t)))
- (put-text-property (point)
- (progn (forward-list) (point))
- 'category 'sgml-tag))
- (let ((pos (point-min)))
- (while (< (setq pos (next-overlay-change pos)) (point-max))
- (dolist (ol (overlays-at pos))
- (if (overlay-get ol 'sgml-tag)
- (delete-overlay ol)))))
- (remove-text-properties (point-min) (point-max) '(category nil))))
- (restore-buffer-modified-p modified))
- (run-hooks 'sgml-tags-invisible-hook)
- (message "")))
- (defun sgml-point-entered (x y)
-
- (let ((inhibit-point-motion-hooks t))
- (save-excursion
- (condition-case nil
- (message "Invisible tag: %s"
-
- (buffer-substring-no-properties
- (point)
- (if (or (and (> x y)
- (not (eq (following-char) ?<)))
- (and (< x y)
- (eq (preceding-char) ?>)))
- (backward-list)
- (forward-list))))
- (error nil)))))
- (defun sgml-validate (command)
- "Validate an SGML document.
- Runs COMMAND, a shell command, in a separate process asynchronously
- with output going to the buffer `*compilation*'.
- You can then use the command \\[next-error] to find the next error message
- and move to the line in the SGML document that caused it."
- (interactive
- (list (read-string "Validate command: "
- (or sgml-saved-validate-command
- (concat sgml-validate-command
- " "
- (shell-quote-argument
- (let ((name (buffer-file-name)))
- (and name
- (file-name-nondirectory name)))))))))
- (setq sgml-saved-validate-command command)
- (save-some-buffers (not compilation-ask-about-save) nil)
- (compilation-start command))
- (defsubst sgml-at-indentation-p ()
- "Return true if point is at the first non-whitespace character on the line."
- (save-excursion
- (skip-chars-backward " \t")
- (bolp)))
- (defun sgml-lexical-context (&optional limit)
- "Return the lexical context at point as (TYPE . START).
- START is the location of the start of the lexical element.
- TYPE is one of `string', `comment', `tag', `cdata', `pi', or `text'.
- Optional argument LIMIT is the position to start parsing from.
- If nil, start from a preceding tag at indentation."
- (save-excursion
- (let ((pos (point))
- text-start state)
- (if limit
- (goto-char limit)
-
- (while (and (ignore-errors (sgml-parse-tag-backward))
- (not (sgml-at-indentation-p)))))
- (with-syntax-table sgml-tag-syntax-table
- (while (< (point) pos)
-
- (setq text-start (point))
- (skip-chars-forward "^<" pos)
- (setq state
- (cond
- ((= (point) pos)
-
- nil)
- ((looking-at "<!\\[[A-Z]+\\[")
-
- (let ((cdata-start (point)))
- (unless (search-forward "]]>" pos 'move)
- (list 0 nil nil 'cdata nil nil nil nil cdata-start))))
- ((looking-at comment-start-skip)
-
-
- (let ((start (point)))
- (unless (re-search-forward comment-end-skip pos 'move)
- (list 0 nil nil nil t nil nil nil start))))
- ((and sgml-xml-mode (looking-at "<\\?"))
-
-
-
- (let ((pi-start (point)))
- (unless (search-forward "?>" pos 'move)
- (list 0 nil nil 'pi nil nil nil nil pi-start))))
- (t
-
-
- (parse-partial-sexp (point) pos 0))))))
- (cond
- ((memq (nth 3 state) '(cdata pi)) (cons (nth 3 state) (nth 8 state)))
- ((nth 3 state) (cons 'string (nth 8 state)))
- ((nth 4 state) (cons 'comment (nth 8 state)))
- ((and state (> (nth 0 state) 0)) (cons 'tag (nth 1 state)))
- (t (cons 'text text-start))))))
- (defun sgml-beginning-of-tag (&optional top-level)
- "Skip to beginning of tag and return its name.
- If this can't be done, return nil."
- (let ((context (sgml-lexical-context)))
- (if (eq (car context) 'tag)
- (progn
- (goto-char (cdr context))
- (when (looking-at sgml-tag-name-re)
- (match-string-no-properties 1)))
- (if top-level nil
- (when (not (eq (car context) 'text))
- (goto-char (cdr context))
- (sgml-beginning-of-tag t))))))
- (defun sgml-value (alist)
- "Interactively insert value taken from attribute-rule ALIST.
- See `sgml-tag-alist' for info about attribute rules."
- (setq alist (cdr alist))
- (if (stringp (car alist))
- (insert "=\"" (car alist) ?\")
- (if (and (eq (car alist) t) (not sgml-xml-mode))
- (when (cdr alist)
- (insert "=\"")
- (setq alist (skeleton-read '(completing-read "Value: " (cdr alist))))
- (if (string< "" alist)
- (insert alist ?\")
- (delete-char -2)))
- (insert "=\"")
- (if (cdr alist)
- (insert (skeleton-read '(completing-read "Value: " alist)))
- (when (null alist)
- (insert (skeleton-read '(read-string "Value: ")))))
- (insert ?\"))))
- (defun sgml-quote (start end &optional unquotep)
- "Quote SGML text in region START ... END.
- Only &, < and > are quoted, the rest is left untouched.
- With prefix argument UNQUOTEP, unquote the region."
- (interactive "r\nP")
- (save-restriction
- (narrow-to-region start end)
- (goto-char (point-min))
- (if unquotep
- ;; FIXME: We should unquote other named character references as well.
- (while (re-search-forward
- "\\(&\\(amp\\|\\(l\\|\\(g\\)\\)t\\)\\)[][<>&;\n\t \"%!'(),/=?]"
- nil t)
- (replace-match (if (match-end 4) ">" (if (match-end 3) "<" "&")) t t
- nil (if (eq (char-before (match-end 0)) ?\
- (while (re-search-forward "[&<>]" nil t)
- (replace-match (cdr (assq (char-before) '((?& . "&")
- (?< . "<")
- (?> . ">"))))
- t t)))))
- (defun sgml-pretty-print (beg end)
- "Simple-minded pretty printer for SGML.
- Re-indents the code and inserts newlines between BEG and END.
- You might want to turn on `auto-fill-mode' to get better results."
-
-
-
- (interactive "r")
- (save-excursion
- (if (< beg end)
- (goto-char beg)
- (goto-char end)
- (setq end beg)
- (setq beg (point)))
-
- (setq end (copy-marker end t))
- (with-syntax-table sgml-tag-syntax-table
- (while (re-search-forward "<" end t)
- (goto-char (match-beginning 0))
- (unless (or
- (progn (skip-chars-backward " \t") (bolp)))
- (reindent-then-newline-and-indent))
- (forward-sexp 1)))
-
- ))
- (defstruct (sgml-tag
- (:constructor sgml-make-tag (type start end name)))
- type start end name)
- (defsubst sgml-parse-tag-name ()
- "Skip past a tag-name, and return the name."
- (buffer-substring-no-properties
- (point) (progn (skip-syntax-forward "w_") (point))))
- (defun sgml-tag-text-p (start end)
- "Return non-nil if text between START and END is a tag.
- Checks among other things that the tag does not contain spurious
- unquoted < or > chars inside, which would indicate that it
- really isn't a tag after all."
- (save-excursion
- (with-syntax-table sgml-tag-syntax-table
- (let ((pps (parse-partial-sexp start end 2)))
- (and (= (nth 0 pps) 0))))))
- (defun sgml-parse-tag-backward (&optional limit)
- "Parse an SGML tag backward, and return information about the tag.
- Assume that parsing starts from within a textual context.
- Leave point at the beginning of the tag."
- (catch 'found
- (let (tag-type tag-start tag-end name)
- (or (re-search-backward "[<>]" limit 'move)
- (error "No tag found"))
- (when (eq (char-after) ?<)
-
-
-
-
-
-
- (setq tag-start (point))
- (with-syntax-table sgml-tag-syntax-table
- (let ((pos (point)))
- (condition-case nil
-
- (forward-sexp)
- (scan-error
-
- (goto-char pos)
- (throw 'found (sgml-parse-tag-backward limit))))
-
- (unless (sgml-tag-text-p pos (point))
- (goto-char pos)
- (throw 'found (sgml-parse-tag-backward limit)))
- (forward-char -1))))
- (setq tag-end (1+ (point)))
- (cond
- ((sgml-looking-back-at "--")
- (setq tag-type 'comment
- tag-start (or tag-start (search-backward "<!--" nil t))))
- ((sgml-looking-back-at "]]")
- (setq tag-type 'cdata
- tag-start (or tag-start
- (re-search-backward "<!\\[[A-Z]+\\[" nil t))))
- ((sgml-looking-back-at "?")
- (setq tag-type 'pi
-
-
-
-
-
-
- tag-start (or tag-start (search-backward "<?" nil t))))
- (t
- (unless tag-start
- (setq tag-start
- (with-syntax-table sgml-tag-syntax-table
- (goto-char tag-end)
- (condition-case nil
- (backward-sexp)
- (scan-error
-
- (goto-char (1- tag-end))
- (throw 'found (sgml-parse-tag-backward limit))))
- (point))))
- (goto-char (1+ tag-start))
- (case (char-after)
- (?! (setq tag-type 'decl))
- (?? (setq tag-type 'pi))
- (?% (setq tag-type 'jsp))
- (?/
- (forward-char 1)
- (setq tag-type 'close
- name (sgml-parse-tag-name)))
- (t
- (setq tag-type 'open
- name (sgml-parse-tag-name))
- (if (or (eq ?/ (char-before (- tag-end 1)))
- (sgml-empty-tag-p name))
- (setq tag-type 'empty))))))
- (goto-char tag-start)
- (sgml-make-tag tag-type tag-start tag-end name))))
- (defun sgml-get-context (&optional until)
- "Determine the context of the current position.
- By default, parse until we find a start-tag as the first thing on a line.
- If UNTIL is `empty', return even if the context is empty (i.e.
- we just skipped over some element and got to a beginning of line).
- The context is a list of tag-info structures. The last one is the tag
- immediately enclosing the current position.
- Point is assumed to be outside of any tag. If we discover that it's
- not the case, the first tag returned is the one inside which we are."
- (let ((here (point))
- (stack nil)
- (ignore nil)
- (context nil)
- tag-info)
-
-
-
-
-
- (skip-chars-backward " \t\n")
- (while
- (and (not (eq until 'now))
- (or stack
- (not (if until (eq until 'empty) context))
- (not (sgml-at-indentation-p))
- (and context
- (/= (point) (sgml-tag-start (car context)))
- (sgml-unclosed-tag-p (sgml-tag-name (car context)))))
- (setq tag-info (ignore-errors (sgml-parse-tag-backward))))
-
-
- (while (and context
- (> (sgml-tag-end tag-info)
- (sgml-tag-end (car context))))
- (setq context (cdr context)))
- (cond
- ((> (sgml-tag-end tag-info) here)
-
- (push tag-info context)
- (setq until 'now))
-
- ((eq (sgml-tag-type tag-info) 'open)
- (cond
- ((null stack)
- (if (assoc-string (sgml-tag-name tag-info) ignore t)
-
- nil
- (push tag-info context)
-
-
-
-
- (setq ignore nil)))
- ((eq t (compare-strings (sgml-tag-name tag-info) nil nil
- (car stack) nil nil t))
- (setq stack (cdr stack)))
- (t
-
- (if (not sgml-xml-mode)
- (unless (sgml-unclosed-tag-p (sgml-tag-name tag-info))
- (message "Unclosed tag <%s>" (sgml-tag-name tag-info))
- (let ((tmp stack))
-
-
-
- (while (and (cdr tmp)
- (not (eq t (compare-strings
- (sgml-tag-name tag-info) nil nil
- (cadr tmp) nil nil t))))
- (setq tmp (cdr tmp)))
- (if (cdr tmp) (setcdr tmp (cddr tmp)))))
- (message "Unmatched tags <%s> and </%s>"
- (sgml-tag-name tag-info) (pop stack)))))
- (if (and (null stack) (sgml-unclosed-tag-p (sgml-tag-name tag-info)))
-
-
-
- (push (sgml-tag-name tag-info) ignore)))
-
- ((eq (sgml-tag-type tag-info) 'close)
- (if (sgml-empty-tag-p (sgml-tag-name tag-info))
- (message "Spurious </%s>: empty tag" (sgml-tag-name tag-info))
- (push (sgml-tag-name tag-info) stack)))
- ))
-
- context))
- (defun sgml-show-context (&optional full)
- "Display the current context.
- If FULL is non-nil, parse back to the beginning of the buffer."
- (interactive "P")
- (with-output-to-temp-buffer "*XML Context*"
- (save-excursion
- (let ((context (sgml-get-context)))
- (when full
- (let ((more nil))
- (while (setq more (sgml-get-context))
- (setq context (nconc more context)))))
- (pp context)))))
- (defun sgml-close-tag ()
- "Close current element.
- Depending on context, inserts a matching close-tag, or closes
- the current start-tag or the current comment or the current cdata, ..."
- (interactive)
- (case (car (sgml-lexical-context))
- ( (insert " -->"))
- (cdata (insert "]]>"))
- (pi (insert " ?>"))
- (jsp (insert " %>"))
- (tag (insert " />"))
- (text
- (let ((context (save-excursion (sgml-get-context))))
- (if context
- (progn
- (insert "</" (sgml-tag-name (car (last context))) ">")
- (indent-according-to-mode)))))
- (otherwise
- (error "Nothing to close"))))
- (defun sgml-empty-tag-p (tag-name)
- "Return non-nil if TAG-NAME is an implicitly empty tag."
- (and (not sgml-xml-mode)
- (assoc-string tag-name sgml-empty-tags 'ignore-case)))
- (defun sgml-unclosed-tag-p (tag-name)
- "Return non-nil if TAG-NAME is a tag for which an end-tag is optional."
- (and (not sgml-xml-mode)
- (assoc-string tag-name sgml-unclosed-tags 'ignore-case)))
- (defun sgml-calculate-indent (&optional lcon)
- "Calculate the column to which this line should be indented.
- LCON is the lexical context, if any."
- (unless lcon (setq lcon (sgml-lexical-context)))
-
- (if (and (eq (car lcon) 'tag)
- (looking-at "--")
- (save-excursion (goto-char (cdr lcon)) (looking-at "<!--")))
- (setq lcon (cons 'comment (+ (cdr lcon) 2))))
- (case (car lcon)
- (string
-
- (while (and (> (point) (cdr lcon))
- (zerop (forward-line -1))
- (looking-at "[ \t]*$")))
- (if (> (point) (cdr lcon))
-
- (current-indentation)
- (goto-char (cdr lcon))
- (1+ (current-column))))
- (
- (let ((mark (looking-at "--")))
-
- (while (and (> (point) (cdr lcon))
- (zerop (forward-line -1))
- (or (looking-at "[ \t]*$")
- (if mark (not (looking-at "[ \t]*--"))))))
- (if (> (point) (cdr lcon))
-
- (skip-chars-forward " \t")
- (goto-char (cdr lcon))
-
- (search-forward "--")
- (goto-char (match-beginning 0)))
- (when (and (not mark) (looking-at "--"))
- (forward-char 2) (skip-chars-forward " \t"))
- (current-column)))
-
- (cdata nil)
-
- (pi nil)
- (tag
- (goto-char (1+ (cdr lcon)))
- (skip-chars-forward "^ \t\n")
- (skip-chars-forward " \t")
- (if (not (eolp))
- (current-column)
-
- (goto-char (1+ (cdr lcon)))
- (+ (current-column) sgml-basic-offset)))
- (text
- (while (looking-at "</")
- (forward-sexp 1)
- (skip-chars-forward " \t"))
- (let* ((here (point))
- (unclosed (and
- (looking-at sgml-tag-name-re)
- (assoc-string (match-string 1)
- sgml-unclosed-tags 'ignore-case)
- (match-string 1)))
- (context
-
-
-
- (if (and (not unclosed) (skip-chars-backward " \t")
- (< (skip-chars-backward " \t\n") 0)
- (back-to-indentation)
- (> (point) (cdr lcon)))
- nil
- (goto-char here)
- (nreverse (sgml-get-context (if unclosed nil 'empty)))))
- (there (point)))
-
- (while (and context unclosed
- (eq t (compare-strings
- (sgml-tag-name (car context)) nil nil
- unclosed nil nil t)))
- (setq context (cdr context)))
-
- (cond
-
- ((and context (> (sgml-tag-end (car context)) here))
- (goto-char here)
- (sgml-calculate-indent
- (cons (if (memq (sgml-tag-type (car context)) '( cdata))
- (sgml-tag-type (car context)) 'tag)
- (sgml-tag-start (car context)))))
-
- ((and context
- (goto-char (sgml-tag-end (car context)))
- (skip-chars-forward " \t\n")
- (< (point) here) (sgml-at-indentation-p))
- (current-column))
- (t
- (goto-char there)
- (+ (current-column)
- (* sgml-basic-offset (length context)))))))
- (otherwise
- (error "Unrecognized context %s" (car lcon)))
- ))
- (defun sgml-indent-line ()
- "Indent the current line as SGML."
- (interactive)
- (let* ((savep (point))
- (indent-col
- (save-excursion
- (back-to-indentation)
- (if (>= (point) savep) (setq savep nil))
- (sgml-calculate-indent))))
- (if (null indent-col)
- 'noindent
- (if savep
- (save-excursion (indent-line-to indent-col))
- (indent-line-to indent-col)))))
- (defun sgml-guess-indent ()
- "Guess an appropriate value for `sgml-basic-offset'.
- Base the guessed indentation level on the first indented tag in the buffer.
- Add this to `sgml-mode-hook' for convenience."
- (interactive)
- (save-excursion
- (goto-char (point-min))
- (if (re-search-forward "^\\([ \t]+\\)<" 500 'noerror)
- (progn
- (set (make-local-variable 'sgml-basic-offset)
- (1- (current-column)))
- (message "Guessed sgml-basic-offset = %d"
- sgml-basic-offset)
- ))))
- (defun sgml-parse-dtd ()
- "Simplistic parse of the current buffer as a DTD.
- Currently just returns (EMPTY-TAGS UNCLOSED-TAGS)."
- (goto-char (point-min))
- (let ((empty nil)
- (unclosed nil))
- (while (re-search-forward "<!ELEMENT[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+[-O][ \t\n]+\\([-O]\\)[ \t\n]+\\([^ \t\n]+\\)" nil t)
- (cond
- ((string= (match-string 3) "EMPTY")
- (push (match-string-no-properties 1) empty))
- ((string= (match-string 2) "O")
- (push (match-string-no-properties 1) unclosed))))
- (setq empty (sort (mapcar 'downcase empty) 'string<))
- (setq unclosed (sort (mapcar 'downcase unclosed) 'string<))
- (list empty unclosed)))
- (defcustom html-mode-hook nil
- "Hook run by command `html-mode'.
- `text-mode-hook' and `sgml-mode-hook' are run first."
- :group 'sgml
- :type 'hook
- :options '(html-autoview-mode))
- (defvar html-quick-keys sgml-quick-keys
- "Use C-c X combinations for quick insertion of frequent tags when non-nil.
- This defaults to `sgml-quick-keys'.
- This takes effect when first loading the library.")
- (defvar html-mode-map
- (let ((map (make-sparse-keymap))
- (menu-map (make-sparse-keymap "HTML")))
- (set-keymap-parent map sgml-mode-map)
- (define-key map "\C-c6" 'html-headline-6)
- (define-key map "\C-c5" 'html-headline-5)
- (define-key map "\C-c4" 'html-headline-4)
- (define-key map "\C-c3" 'html-headline-3)
- (define-key map "\C-c2" 'html-headline-2)
- (define-key map "\C-c1" 'html-headline-1)
- (define-key map "\C-c\r" 'html-paragraph)
- (define-key map "\C-c\n" 'html-line)
- (define-key map "\C-c\C-c-" 'html-horizontal-rule)
- (define-key map "\C-c\C-co" 'html-ordered-list)
- (define-key map "\C-c\C-cu" 'html-unordered-list)
- (define-key map "\C-c\C-cr" 'html-radio-buttons)
- (define-key map "\C-c\C-cc" 'html-checkboxes)
- (define-key map "\C-c\C-cl" 'html-list-item)
- (define-key map "\C-c\C-ch" 'html-href-anchor)
- (define-key map "\C-c\C-cn" 'html-name-anchor)
- (define-key map "\C-c\C-ci" 'html-image)
- (when html-quick-keys
- (define-key map "\C-c-" 'html-horizontal-rule)
- (define-key map "\C-co" 'html-ordered-list)
- (define-key map "\C-cu" 'html-unordered-list)
- (define-key map "\C-cr" 'html-radio-buttons)
- (define-key map "\C-cc" 'html-checkboxes)
- (define-key map "\C-cl" 'html-list-item)
- (define-key map "\C-ch" 'html-href-anchor)
- (define-key map "\C-cn" 'html-name-anchor)
- (define-key map "\C-ci" 'html-image))
- (define-key map "\C-c\C-s" 'html-autoview-mode)
- (define-key map "\C-c\C-v" 'browse-url-of-buffer)
- (define-key map [menu-bar html] (cons "HTML" menu-map))
- (define-key menu-map [html-autoview-mode]
- '("Toggle Autoviewing" . html-autoview-mode))
- (define-key menu-map [browse-url-of-buffer]
- '("View Buffer Contents" . browse-url-of-buffer))
- (define-key menu-map [nil] '("--"))
-
-
-
- (define-key menu-map "3" '("Heading 3" . html-headline-3))
- (define-key menu-map "2" '("Heading 2" . html-headline-2))
- (define-key menu-map "1" '("Heading 1" . html-headline-1))
- (define-key menu-map "l" '("Radio Buttons" . html-radio-buttons))
- (define-key menu-map "c" '("Checkboxes" . html-checkboxes))
- (define-key menu-map "l" '("List Item" . html-list-item))
- (define-key menu-map "u" '("Unordered List" . html-unordered-list))
- (define-key menu-map "o" '("Ordered List" . html-ordered-list))
- (define-key menu-map "-" '("Horizontal Rule" . html-horizontal-rule))
- (define-key menu-map "\n" '("Line Break" . html-line))
- (define-key menu-map "\r" '("Paragraph" . html-paragraph))
- (define-key menu-map "i" '("Image" . html-image))
- (define-key menu-map "h" '("Href Anchor" . html-href-anchor))
- (define-key menu-map "n" '("Name Anchor" . html-name-anchor))
- map)
- "Keymap for commands for use in HTML mode.")
- (defvar html-face-tag-alist
- '((bold . "b")
- (italic . "i")
- (underline . "u")
- (modeline . "rev"))
- "Value of `sgml-face-tag-alist' for HTML mode.")
- (defvar html-tag-face-alist
- '(("b" . bold)
- ("big" . bold)
- ("blink" . highlight)
- ("cite" . italic)
- ("em" . italic)
- ("h1" bold underline)
- ("h2" bold-italic underline)
- ("h3" italic underline)
- ("h4" . underline)
- ("h5" . underline)
- ("h6" . underline)
- ("i" . italic)
- ("rev" . modeline)
- ("s" . underline)
- ("small" . default)
- ("strong" . bold)
- ("title" bold underline)
- ("tt" . default)
- ("u" . underline)
- ("var" . italic))
- "Value of `sgml-tag-face-alist' for HTML mode.")
- (defvar html-display-text
- '((img . "[/]")
- (hr . "----------")
- (li . "o "))
- "Value of `sgml-display-text' for HTML mode.")
- (defvar html-tag-alist
- (let* ((1-7 '(("1") ("2") ("3") ("4") ("5") ("6") ("7")))
- (1-9 `(,@1-7 ("8") ("9")))
- (align '(("align" ("left") ("center") ("right"))))
- (valign '(("top") ("middle") ("bottom") ("baseline")))
- (rel '(("next") ("previous") ("parent") ("subdocument") ("made")))
- (href '("href" ("ftp:") ("file:") ("finger:") ("gopher:") ("http:")
- ("mailto:") ("news:") ("rlogin:") ("telnet:") ("tn3270:")
- ("wais:") ("/cgi-bin/")))
- (name '("name"))
- (link `(,href
- ("rel" ,@rel)
- ("rev" ,@rel)
- ("title")))
- (list '((nil \n ("List item: " "<li>" str
- (if sgml-xml-mode "</li>") \n))))
- (cell `(t
- ,@align
- ("valign" ,@valign)
- ("colspan" ,@1-9)
- ("rowspan" ,@1-9)
- ("nowrap" t))))
-
-
- `(("a" ,name ,@link)
- ("base" t ,@href)
- ("dir" ,@list)
- ("font" nil "size" ("-1") ("+1") ("-2") ("+2") ,@1-7)
- ("form" (\n _ \n "<input type=\"submit\" value=\"\""
- (if sgml-xml-mode " />" ">"))
- ("action" ,@(cdr href)) ("method" ("get") ("post")))
- ("h1" ,@align)
- ("h2" ,@align)
- ("h3" ,@align)
- ("h4" ,@align)
- ("h5" ,@align)
- ("h6" ,@align)
- ("hr" t ("size" ,@1-9) ("width") ("noshade" t) ,@align)
- ("img" t ("align" ,@valign ("texttop") ("absmiddle") ("absbottom"))
- ("src") ("alt") ("width" "1") ("height" "1")
- ("border" "1") ("vspace" "1") ("hspace" "1") ("ismap" t))
- ("input" t ("size" ,@1-9) ("maxlength" ,@1-9) ("checked" t) ,name
- ("type" ("text") ("password") ("checkbox") ("radio")
- ("submit") ("reset"))
- ("value"))
- ("link" t ,@link)
- ("menu" ,@list)
- ("ol" ,@list ("type" ("A") ("a") ("I") ("i") ("1")))
- ("p" t ,@align)
- ("select" (nil \n
- ("Text: "
- "<option>" str (if sgml-xml-mode "</option>") \n))
- ,name ("size" ,@1-9) ("multiple" t))
- ("table" (nil \n
- ((completing-read "Cell kind: " '(("td") ("th"))
- nil t "t")
- "<tr><" str ?> _
- (if sgml-xml-mode (concat "<" str "></tr>")) \n))
- ("border" t ,@1-9) ("width" "10") ("cellpadding"))
- ("td" ,@cell)
- ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9))
- ("th" ,@cell)
- ("ul" ,@list ("type" ("disc") ("circle") ("square")))
- ,@sgml-tag-alist
- ("abbrev")
- ("acronym")
- ("address")
- ("array" (nil \n
- ("Item: " "<item>" str (if sgml-xml-mode "</item>") \n))
- "align")
- ("au")
- ("b")
- ("big")
- ("blink")
- ("blockquote" \n)
- ("body" \n ("background" ".gif") ("bgcolor" "#") ("text" "#")
- ("link" "#") ("alink" "#") ("vlink" "#"))
- ("box" (nil _ "<over>" _ (if sgml-xml-mode "</over>")))
- ("br" t ("clear" ("left") ("right")))
- ("caption" ("valign" ("top") ("bottom")))
- ("center" \n)
- ("cite")
- ("code" \n)
- ("dd" ,(not sgml-xml-mode))
- ("del")
- ("dfn")
- ("div")
- ("dl" (nil \n
- ( "Term: "
- "<dt>" str (if sgml-xml-mode "</dt>")
- "<dd>" _ (if sgml-xml-mode "</dd>") \n)))
- ("dt" (t _ (if sgml-xml-mode "</dt>")
- "<dd>" (if sgml-xml-mode "</dd>") \n))
- ("em")
- ("fn" "id" "fn")
- ("head" \n)
- ("html" (\n
- "<head>\n"
- "<title>" (setq str (read-input "Title: ")) "</title>\n"
- "</head>\n"
- "<body>\n<h1>" str "</h1>\n" _
- "\n<address>\n<a href=\"mailto:"
- user-mail-address
- "\">" (user-full-name) "</a>\n</address>\n"
- "</body>"
- ))
- ("i")
- ("ins")
- ("isindex" t ("action") ("prompt"))
- ("kbd")
- ("lang")
- ("li" ,(not sgml-xml-mode))
- ("math" \n)
- ("nobr")
- ("option" t ("value") ("label") ("selected" t))
- ("over" t)
- ("person")
- ("pre" \n)
- ("q")
- ("rev")
- ("s")
- ("samp")
- ("small")
- ("span" nil
- ("class"
- ("builtin")
- ("comment")
- ("constant")
- ("function-name")
- ("keyword")
- ("string")
- ("type")
- ("variable-name")
- ("warning")))
- ("strong")
- ("sub")
- ("sup")
- ("title")
- ("tr" t)
- ("tt")
- ("u")
- ("var")
- ("wbr" t)))
- "*Value of `sgml-tag-alist' for HTML mode.")
- (defvar html-tag-help
- `(,@sgml-tag-help
- ("a" . "Anchor of point or link elsewhere")
- ("abbrev" . "Abbreviation")
- ("acronym" . "Acronym")
- ("address" . "Formatted mail address")
- ("array" . "Math array")
- ("au" . "Author")
- ("b" . "Bold face")
- ("base" . "Base address for URLs")
- ("big" . "Font size")
- ("blink" . "Blinking text")
- ("blockquote" . "Indented quotation")
- ("body" . "Document body")
- ("box" . "Math fraction")
- ("br" . "Line break")
- ("caption" . "Table caption")
- ("center" . "Centered text")
- ("changed" . "Change bars")
- ("cite" . "Citation of a document")
- ("code" . "Formatted source code")
- ("dd" . "Definition of term")
- ("del" . "Deleted text")
- ("dfn" . "Defining instance of a term")
- ("dir" . "Directory list (obsolete)")
- ("div" . "Generic block-level container")
- ("dl" . "Definition list")
- ("dt" . "Term to be defined")
- ("em" . "Emphasized")
- ("embed" . "Embedded data in foreign format")
- ("fig" . "Figure")
- ("figa" . "Figure anchor")
- ("figd" . "Figure description")
- ("figt" . "Figure text")
- ("fn" . "Footnote")
- ("font" . "Font size")
- ("form" . "Form with input fields")
- ("group" . "Document grouping")
- ("h1" . "Most important section headline")
- ("h2" . "Important section headline")
- ("h3" . "Section headline")
- ("h4" . "Minor section headline")
- ("h5" . "Unimportant section headline")
- ("h6" . "Least important section headline")
- ("head" . "Document header")
- ("hr" . "Horizontal rule")
- ("html" . "HTML Document")
- ("i" . "Italic face")
- ("img" . "Graphic image")
- ("input" . "Form input field")
- ("ins" . "Inserted text")
- ("isindex" . "Input field for index search")
- ("kbd" . "Keyboard example face")
- ("lang" . "Natural language")
- ("li" . "List item")
- ("link" . "Link relationship")
- ("math" . "Math formula")
- ("menu" . "Menu list (obsolete)")
- ("mh" . "Form mail header")
- ("nextid" . "Allocate new id")
- ("nobr" . "Text without line break")
- ("ol" . "Ordered list")
- ("option" . "Selection list item")
- ("over" . "Math fraction rule")
- ("p" . "Paragraph start")
- ("panel" . "Floating panel")
- ("person" . "Person's name")
- ("pre" . "Preformatted fixed width text")
- ("q" . "Quotation")
- ("rev" . "Reverse video")
- ("s" . "Strikeout")
- ("samp" . "Sample text")
- ("select" . "Selection list")
- ("small" . "Font size")
- ("sp" . "Nobreak space")
- ("span" . "Generic inline container")
- ("strong" . "Standout text")
- ("sub" . "Subscript")
- ("sup" . "Superscript")
- ("table" . "Table with rows and columns")
- ("tb" . "Table vertical break")
- ("td" . "Table data cell")
- ("textarea" . "Form multiline edit area")
- ("th" . "Table header cell")
- ("title" . "Document title")
- ("tr" . "Table row separator")
- ("tt" . "Typewriter face")
- ("u" . "Underlined text")
- ("ul" . "Unordered list")
- ("var" . "Math variable face")
- ("wbr" . "Enable <br> within <nobr>"))
- "*Value of `sgml-tag-help' for HTML mode.")
- (define-derived-mode html-mode sgml-mode '(sgml-xml-mode "XHTML" "HTML")
- "Major mode based on SGML mode for editing HTML documents.
- This allows inserting skeleton constructs used in hypertext documents with
- completion. See below for an introduction to HTML. Use
- \\[browse-url-of-buffer] to see how this comes out. See also `sgml-mode' on
- which this is based.
- Do \\[describe-variable] html- SPC and \\[describe-variable] sgml- SPC to see available variables.
- To write fairly well formatted pages you only need to know few things. Most
- browsers have a function to read the source code of the page being seen, so
- you can imitate various tricks. Here's a very short HTML primer which you
- can also view with a browser to see what happens:
- <title>A Title Describing Contents</title> should be on every page. Pages can
- have <h1>Very Major Headlines</h1> through <h6>Very Minor Headlines</h6>
- <hr> Parts can be separated with horizontal rules.
- <p>Paragraphs only need an opening tag. Line breaks and multiple spaces are
- ignored unless the text is <pre>preformatted.</pre> Text can be marked as
- <b>bold</b>, <i>italic</i> or <u>underlined</u> using the normal M-o or
- Edit/Text Properties/Face commands.
- Pages can have <a name=\"SOMENAME\">named points</a> and can link other points
- to them with <a href=\"#SOMENAME\">see also somename</a>. In the same way <a
- href=\"URL\">see also URL</a> where URL is a filename relative to current
- directory, or absolute as in `http://www.cs.indiana.edu/elisp/w3/docs.html'.
- Images in many formats can be inlined with <img src=\"URL\">.
- If you mainly create your own documents, `sgml-specials' might be
- interesting. But note that some HTML 2 browsers can't handle `''.
- To work around that, do:
- (eval-after-load \"sgml-mode\" '(aset sgml-char-names ?' nil))
- \\{html-mode-map}"
- (set (make-local-variable 'sgml-display-text) html-display-text)
- (set (make-local-variable 'sgml-tag-face-alist) html-tag-face-alist)
- (make-local-variable 'sgml-tag-alist)
- (make-local-variable 'sgml-face-tag-alist)
- (make-local-variable 'sgml-tag-help)
- (make-local-variable 'outline-regexp)
- (make-local-variable 'outline-heading-end-regexp)
- (make-local-variable 'outline-level)
- (make-local-variable 'sentence-end-base)
- (setq sentence-end-base "[.?!][]\"'”)}]*\\(<[^>]*>\\)*"
- sgml-tag-alist html-tag-alist
- sgml-face-tag-alist html-face-tag-alist
- sgml-tag-help html-tag-help
- outline-regexp "^.*<[Hh][1-6]\\>"
- outline-heading-end-regexp "</[Hh][1-6]>"
- outline-level (lambda ()
- (char-before (match-end 0))))
- (setq imenu-create-index-function 'html-imenu-index)
- (set (make-local-variable 'sgml-empty-tags)
-
-
- '("area" "base" "basefont" "br" "col" "frame" "hr" "img" "input"
- "isindex" "link" "meta" "param" "wbr"))
- (set (make-local-variable 'sgml-unclosed-tags)
-
- '("body" "colgroup" "dd" "dt" "head" "html" "li" "option"
- "p" "tbody" "td" "tfoot" "th" "thead" "tr"))
-
-
-
- )
- (defvar html-imenu-regexp
- "\\s-*<h\\([1-9]\\)[^\n<>]*>\\(<[^\n<>]*>\\)*\\s-*\\([^\n<>]*\\)"
- "*A regular expression matching a head line to be added to the menu.
- The first `match-string' should be a number from 1-9.
- The second `match-string' matches extra tags and is ignored.
- The third `match-string' will be the used in the menu.")
- (defun html-imenu-index ()
- "Return a table of contents for an HTML buffer for use with Imenu."
- (let (toc-index)
- (save-excursion
- (goto-char (point-min))
- (while (re-search-forward html-imenu-regexp nil t)
- (setq toc-index
- (cons (cons (concat (make-string
- (* 2 (1- (string-to-number (match-string 1))))
- ?\s)
- (match-string 3))
- (line-beginning-position))
- toc-index))))
- (nreverse toc-index)))
- (define-minor-mode html-autoview-mode
- "Toggle viewing of HTML files on save (HTML Autoview mode).
- With a prefix argument ARG, enable HTML Autoview mode if ARG is
- positive, and disable it otherwise. If called from Lisp, enable
- the mode if ARG is omitted or nil.
- HTML Autoview mode is a buffer-local minor mode for use with
- `html-mode'. If enabled, saving the file automatically runs
- `browse-url-of-buffer' to view it."
- nil nil nil
- :group 'sgml
- (if html-autoview-mode
- (add-hook 'after-save-hook 'browse-url-of-buffer nil t)
- (remove-hook 'after-save-hook 'browse-url-of-buffer t)))
- (define-skeleton html-href-anchor
- "HTML anchor tag with href attribute."
- "URL: "
-
- "<a href=\"" str "\">" _ "</a>")
- (define-skeleton html-name-anchor
- "HTML anchor tag with name attribute."
- "Name: "
- "<a name=\"" str "\""
- (if sgml-xml-mode (concat " id=\"" str "\""))
- ">" _ "</a>")
- (define-skeleton html-headline-1
- "HTML level 1 headline tags."
- nil
- "<h1>" _ "</h1>")
- (define-skeleton html-headline-2
- "HTML level 2 headline tags."
- nil
- "<h2>" _ "</h2>")
- (define-skeleton html-headline-3
- "HTML level 3 headline tags."
- nil
- "<h3>" _ "</h3>")
- (define-skeleton html-headline-4
- "HTML level 4 headline tags."
- nil
- "<h4>" _ "</h4>")
- (define-skeleton html-headline-5
- "HTML level 5 headline tags."
- nil
- "<h5>" _ "</h5>")
- (define-skeleton html-headline-6
- "HTML level 6 headline tags."
- nil
- "<h6>" _ "</h6>")
- (define-skeleton html-horizontal-rule
- "HTML horizontal rule tag."
- nil
- (if sgml-xml-mode "<hr />" "<hr>") \n)
- (define-skeleton html-image
- "HTML image tag."
- "Image URL: "
- "<img src=\"" str "\" alt=\"" _ "\""
- (if sgml-xml-mode " />" ">"))
- (define-skeleton html-line
- "HTML line break tag."
- nil
- (if sgml-xml-mode "<br />" "<br>") \n)
- (define-skeleton html-ordered-list
- "HTML ordered list tags."
- nil
- "<ol>" \n
- "<li>" _ (if sgml-xml-mode "</li>") \n
- "</ol>")
- (define-skeleton html-unordered-list
- "HTML unordered list tags."
- nil
- "<ul>" \n
- "<li>" _ (if sgml-xml-mode "</li>") \n
- "</ul>")
- (define-skeleton html-list-item
- "HTML list item tag."
- nil
- (if (bolp) nil '\n)
- "<li>" _ (if sgml-xml-mode "</li>"))
- (define-skeleton html-paragraph
- "HTML paragraph tag."
- nil
- (if (bolp) nil ?\n)
- "<p>" _ (if sgml-xml-mode "</p>"))
- (define-skeleton html-checkboxes
- "Group of connected checkbox inputs."
- nil
- '(setq v1 nil
- v2 nil)
- ("Value: "
- "<input type=\"" (identity "checkbox")
- "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: ")))
- "\" value=\"" str ?\"
- (when (y-or-n-p "Set \"checked\" attribute? ")
- (funcall skeleton-transformation-function
- (if sgml-xml-mode " checked=\"checked\"" " checked")))
- (if sgml-xml-mode " />" ">")
- (skeleton-read "Text: " (capitalize str))
- (or v2 (setq v2 (if (y-or-n-p "Newline after text? ")
- (funcall skeleton-transformation-function
- (if sgml-xml-mode "<br />" "<br>"))
- "")))
- \n))
- (define-skeleton html-radio-buttons
- "Group of connected radio button inputs."
- nil
- '(setq v1 nil
- v2 (cons nil nil))
- ("Value: "
- "<input type=\"" (identity "radio")
- "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: ")))
- "\" value=\"" str ?\"
- (when (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? ")))
- (funcall skeleton-transformation-function
- (if sgml-xml-mode " checked=\"checked\"" " checked")))
- (if sgml-xml-mode " />" ">")
- (skeleton-read "Text: " (capitalize str))
- (or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ")
- (funcall skeleton-transformation-function
- (if sgml-xml-mode "<br />" "<br>"))
- "")))
- \n))
- (provide 'sgml-mode)
|