X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/73b0cd50031a714347109169ceb8bacae338612a..51721edc6ba92f9c7cb6a2daab45bb538a696f3d:/lisp/textmodes/sgml-mode.el diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 8f06e029d4..d2f1307b6c 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -1,9 +1,10 @@ ;;; sgml-mode.el --- SGML- and HTML-editing modes -*- coding: utf-8 -*- -;; Copyright (C) 1992, 1995-1996, 1998, 2001-2011 Free Software Foundation, Inc. +;; Copyright (C) 1992, 1995-1996, 1998, 2001-2014 Free Software +;; Foundation, Inc. ;; Author: James Clark -;; Maintainer: FSF +;; Maintainer: emacs-devel@gnu.org ;; Adapted-By: ESR, Daniel Pfeiffer , ;; F.Potorti@cnuce.cnr.it ;; Keywords: wp, hypermedia, comm, languages @@ -33,8 +34,7 @@ (eval-when-compile (require 'skeleton) - (require 'outline) - (require 'cl)) + (require 'cl-lib)) (defgroup sgml nil "SGML editing mode." @@ -46,9 +46,26 @@ :type 'integer :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) + (defcustom sgml-transformation-function 'identity "Default value for `skeleton-transformation-function' in SGML mode." :type 'function + :initialize 'custom-initialize-default + :set (lambda (sym val) + (set-default sym val) + (mapc (lambda (buff) + (with-current-buffer buff + (and (derived-mode-p 'sgml-mode) + (not sgml-xml-mode) + (setq skeleton-transformation-function val)))) + (buffer-list))) :group 'sgml) (put 'sgml-transformation-function 'variable-interactive @@ -61,7 +78,7 @@ :group 'sgml :type 'hook) -;; As long as Emacs' syntax can't be complemented with predicates to context +;; As long as Emacs's syntax can't be complemented with predicates to context ;; sensitively confirm the syntax of characters, we have to live with this ;; kludgy kind of tradeoff. (defvar sgml-specials '(?\") @@ -291,12 +308,12 @@ Any terminating `>' or `/' is not matched.") ;; for font-lock, but must be defvar'ed after ;; sgml-font-lock-keywords-1 and sgml-font-lock-keywords-2 above (defvar sgml-font-lock-keywords sgml-font-lock-keywords-1 - "*Rules for highlighting SGML code. See also `sgml-tag-face-alist'.") + "Rules for highlighting SGML code. See also `sgml-tag-face-alist'.") (defconst sgml-syntax-propertize-function (syntax-propertize-rules - ;; Use the `b' style of comments to avoid interference with the -- ... -- - ;; comments recognized when `sgml-specials' includes ?-. + ;; Use the `b' style of comments to avoid interference with the -- ... -- + ;; comments recognized when `sgml-specials' includes ?-. ;; FIXME: beware of blabla !! ("\\(<\\)!--" (1 "< b")) ("--[ \t\n]*\\(>\\)" (1 "> b")) @@ -305,7 +322,7 @@ Any terminating `>' or `/' is not matched.") ;; going to change, so as not to need to flush the data we just computed. ("\"" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0)))) (goto-char (match-end 0))) - ".")))) + (string-to-syntax "."))))) "Syntactic keywords for `sgml-mode'.") ;; internal @@ -364,14 +381,6 @@ an optional alist of possible values." (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.") @@ -426,7 +435,12 @@ a DOCTYPE or an XML declaration." (format-mode-line mode-name)))))) (defun sgml-fill-nobreak () - ;; Don't break between a tag name and its first argument. + "Don't break between a tag name and its first argument. +This function is designed for use in `fill-nobreak-predicate'. + + + ^ ^ + | no break here | but still allowed here" (save-excursion (skip-chars-backward " \t") (and (not (zerop (skip-syntax-backward "w_"))) @@ -445,7 +459,7 @@ 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. +in your init file. Use \\[sgml-validate] to validate your document with an SGML parser. @@ -458,47 +472,39 @@ Do \\[describe-key] on the following bindings to discover what they do. ;; A start or end tag by itself on a line separates a paragraph. ;; This is desirable because SGML discards a newline that appears ;; immediately after a start tag or immediately before an end tag. - (set (make-local-variable 'paragraph-start) (concat "[ \t]*$\\|\ + (setq-local paragraph-start (concat "[ \t]*$\\|\ \[ \t]*")) - (set (make-local-variable 'paragraph-separate) - (concat paragraph-start "$")) - (set (make-local-variable 'adaptive-fill-regexp) "[ \t]*") + (setq-local paragraph-separate (concat paragraph-start "$")) + (setq-local 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-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)) + (setq-local indent-line-function 'sgml-indent-line) + (setq-local comment-start "") + (setq-local comment-indent-function 'sgml-comment-indent) + (setq-local comment-line-break-function 'sgml-comment-indent-new-line) + (setq-local skeleton-further-elements '((completion-ignore-case t))) + (setq-local skeleton-end-hook + (lambda () + (or (eolp) + (not (or (eq v2 '\n) (eq (car-safe v2) '\n))) + (newline-and-indent)))) + (setq font-lock-defaults '((sgml-font-lock-keywords + sgml-font-lock-keywords-1 + sgml-font-lock-keywords-2) + nil t)) + (setq-local syntax-propertize-function sgml-syntax-propertize-function) + (setq-local facemenu-add-face-function 'sgml-mode-facemenu-add-face-function) + (setq-local sgml-xml-mode (sgml-xml-guess)) + (unless sgml-xml-mode + (setq-local skeleton-transformation-function sgml-transformation-function)) ;; This will allow existing comments within declarations to be ;; recognized. ;; I can't find a clear description of SGML/XML comments, but it seems that ;; the only reliable ones are although it's not clear what ;; "..." can contain. It used to accept -- ... -- as well, but that was ;; apparently a mistake. - (set (make-local-variable 'comment-start-skip) "")) - (cdata (insert "]]>")) - (pi (insert " ?>")) - (jsp (insert " %>")) - (tag (insert " />")) - (text + (pcase (car (sgml-lexical-context)) + (`comment (insert " -->")) + (`cdata (insert "]]>")) + (`pi (insert " ?>")) + (`jsp (insert " %>")) + (`tag (insert " />")) + (`text (let ((context (save-excursion (sgml-get-context)))) (if context (progn (insert "") (indent-according-to-mode))))) - (otherwise + (_ (error "Nothing to close")))) (defun sgml-empty-tag-p (tag-name) @@ -1429,9 +1440,9 @@ LCON is the lexical context, if any." (save-excursion (goto-char (cdr lcon)) (looking-at "