diff options
| author | Stefan Monnier | 2016-01-16 10:43:19 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2016-01-16 10:43:19 -0500 |
| commit | d10982a91ac2b93bf9a375e00d676a25f90b885a (patch) | |
| tree | f235ae7beffa4275385afedeff1dc50e0f69aeac | |
| parent | 05988c0d527de99d54266cc3ef0688899761ba26 (diff) | |
| download | emacs-d10982a91ac2b93bf9a375e00d676a25f90b885a.tar.gz emacs-d10982a91ac2b93bf9a375e00d676a25f90b885a.zip | |
Use sgml-electric-tag-pair-mode also in nxml-mode
* lisp/nxml/rng-nxml.el: Require sgml-mode.
(rng-nxml-easy-menu): Add entry for sgml-electric-tag-pair-mode.
(rng-complete-qname-function): Use complete-with-action.
* lisp/textmodes/sgml-mode.el (sgml-electric-tag-pair-before-change-function):
Let-bind forward-sexp-function, since nxml-mode binds it to
something incompatible.
* lisp/nxml/nxml-mode.el: Use setq-local and defvar-local.
| -rw-r--r-- | lisp/nxml/nxml-mode.el | 70 | ||||
| -rw-r--r-- | lisp/nxml/rng-nxml.el | 27 | ||||
| -rw-r--r-- | lisp/textmodes/sgml-mode.el | 11 |
3 files changed, 44 insertions, 64 deletions
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el index db607502889..b7a4e2e2469 100644 --- a/lisp/nxml/nxml-mode.el +++ b/lisp/nxml/nxml-mode.el | |||
| @@ -26,9 +26,6 @@ | |||
| 26 | 26 | ||
| 27 | ;;; Code: | 27 | ;;; Code: |
| 28 | 28 | ||
| 29 | (when (featurep 'mucs) | ||
| 30 | (error "nxml-mode is not compatible with Mule-UCS")) | ||
| 31 | |||
| 32 | (eval-when-compile (require 'cl-lib)) | 29 | (eval-when-compile (require 'cl-lib)) |
| 33 | 30 | ||
| 34 | (require 'xmltok) | 31 | (require 'xmltok) |
| @@ -339,22 +336,19 @@ The delimiters are <! and >." | |||
| 339 | 336 | ||
| 340 | ;;; Global variables | 337 | ;;; Global variables |
| 341 | 338 | ||
| 342 | (defvar nxml-parent-document nil | 339 | (defvar-local nxml-parent-document nil |
| 343 | "The parent document for a part of a modular document. | 340 | "The parent document for a part of a modular document. |
| 344 | Use `nxml-parent-document-set' to set it.") | 341 | Use `nxml-parent-document-set' to set it.") |
| 345 | (make-variable-buffer-local 'nxml-parent-document) | ||
| 346 | (put 'nxml-parent-document 'safe-local-variable 'stringp) | 342 | (put 'nxml-parent-document 'safe-local-variable 'stringp) |
| 347 | 343 | ||
| 348 | (defvar nxml-prolog-regions nil | 344 | (defvar-local nxml-prolog-regions nil |
| 349 | "List of regions in the prolog to be fontified. | 345 | "List of regions in the prolog to be fontified. |
| 350 | See the function `xmltok-forward-prolog' for more information.") | 346 | See the function `xmltok-forward-prolog' for more information.") |
| 351 | (make-variable-buffer-local 'nxml-prolog-regions) | ||
| 352 | 347 | ||
| 353 | (defvar nxml-degraded nil | 348 | (defvar-local nxml-degraded nil |
| 354 | "Non-nil if currently operating in degraded mode. | 349 | "Non-nil if currently operating in degraded mode. |
| 355 | Degraded mode is enabled when an internal error is encountered in the | 350 | Degraded mode is enabled when an internal error is encountered in the |
| 356 | fontification or after-change functions.") | 351 | fontification or after-change functions.") |
| 357 | (make-variable-buffer-local 'nxml-degraded) | ||
| 358 | 352 | ||
| 359 | (defvar nxml-completion-hook nil | 353 | (defvar nxml-completion-hook nil |
| 360 | "Hook run by `nxml-complete'. | 354 | "Hook run by `nxml-complete'. |
| @@ -372,13 +366,12 @@ one of the functions returns nil.") | |||
| 372 | (defvar nxml-end-tag-indent-scan-distance 4000 | 366 | (defvar nxml-end-tag-indent-scan-distance 4000 |
| 373 | "Maximum distance from point to scan backwards when indenting end-tag.") | 367 | "Maximum distance from point to scan backwards when indenting end-tag.") |
| 374 | 368 | ||
| 375 | (defvar nxml-char-ref-extra-display t | 369 | (defvar-local nxml-char-ref-extra-display t |
| 376 | "Non-nil means display extra information for character references. | 370 | "Non-nil means display extra information for character references. |
| 377 | The extra information consists of a tooltip with the character name | 371 | The extra information consists of a tooltip with the character name |
| 378 | and, if `nxml-char-ref-display-glyph-flag' is non-nil, a glyph | 372 | and, if `nxml-char-ref-display-glyph-flag' is non-nil, a glyph |
| 379 | corresponding to the referenced character following the character | 373 | corresponding to the referenced character following the character |
| 380 | reference.") | 374 | reference.") |
| 381 | (make-variable-buffer-local 'nxml-char-ref-extra-display) | ||
| 382 | 375 | ||
| 383 | (defvar nxml-mode-map | 376 | (defvar nxml-mode-map |
| 384 | (let ((map (make-sparse-keymap))) | 377 | (let ((map (make-sparse-keymap))) |
| @@ -516,35 +509,24 @@ Many aspects this mode can be customized using | |||
| 516 | ;; FIXME: Use the fact that we're parsing the document already | 509 | ;; FIXME: Use the fact that we're parsing the document already |
| 517 | ;; rather than using regex-based filtering. | 510 | ;; rather than using regex-based filtering. |
| 518 | (setq-local tildify-foreach-region-function | 511 | (setq-local tildify-foreach-region-function |
| 519 | (apply-partially 'tildify-foreach-ignore-environments | 512 | (apply-partially #'tildify-foreach-ignore-environments |
| 520 | '(("<! *--" . "-- *>") ("<" . ">")))) | 513 | '(("<! *--" . "-- *>") ("<" . ">")))) |
| 521 | (set (make-local-variable 'mode-line-process) '((nxml-degraded "/degraded"))) | 514 | (setq-local mode-line-process '((nxml-degraded "/degraded"))) |
| 522 | ;; We'll determine the fill prefix ourselves | 515 | ;; We'll determine the fill prefix ourselves |
| 523 | (make-local-variable 'adaptive-fill-mode) | 516 | (setq-local adaptive-fill-mode nil) |
| 524 | (setq adaptive-fill-mode nil) | 517 | (setq-local forward-sexp-function #'nxml-forward-balanced-item) |
| 525 | (make-local-variable 'forward-sexp-function) | 518 | (setq-local indent-line-function #'nxml-indent-line) |
| 526 | (setq forward-sexp-function 'nxml-forward-balanced-item) | 519 | (setq-local fill-paragraph-function #'nxml-do-fill-paragraph) |
| 527 | (make-local-variable 'indent-line-function) | ||
| 528 | (setq indent-line-function 'nxml-indent-line) | ||
| 529 | (make-local-variable 'fill-paragraph-function) | ||
| 530 | (setq fill-paragraph-function 'nxml-do-fill-paragraph) | ||
| 531 | ;; Comment support | 520 | ;; Comment support |
| 532 | ;; This doesn't seem to work too well; | 521 | ;; This doesn't seem to work too well; |
| 533 | ;; I think we should probably roll our own nxml-comment-dwim function. | 522 | ;; I think we should probably roll our own nxml-comment-dwim function. |
| 534 | (make-local-variable 'comment-indent-function) | 523 | (setq-local comment-indent-function #'nxml-indent-line) |
| 535 | (setq comment-indent-function 'nxml-indent-line) | 524 | (setq-local comment-start "<!--") |
| 536 | (make-local-variable 'comment-start) | 525 | (setq-local comment-start-skip "<!--[ \t\r\n]*") |
| 537 | (setq comment-start "<!--") | 526 | (setq-local comment-end "-->") |
| 538 | (make-local-variable 'comment-start-skip) | 527 | (setq-local comment-end-skip "[ \t\r\n]*-->") |
| 539 | (setq comment-start-skip "<!--[ \t\r\n]*") | 528 | (setq-local comment-line-break-function #'nxml-newline-and-indent) |
| 540 | (make-local-variable 'comment-end) | 529 | (setq-local comment-quote-nested-function #'nxml-comment-quote-nested) |
| 541 | (setq comment-end "-->") | ||
| 542 | (make-local-variable 'comment-end-skip) | ||
| 543 | (setq comment-end-skip "[ \t\r\n]*-->") | ||
| 544 | (make-local-variable 'comment-line-break-function) | ||
| 545 | (setq comment-line-break-function 'nxml-newline-and-indent) | ||
| 546 | (setq-local comment-quote-nested-function 'nxml-comment-quote-nested) | ||
| 547 | (use-local-map nxml-mode-map) | ||
| 548 | (save-excursion | 530 | (save-excursion |
| 549 | (save-restriction | 531 | (save-restriction |
| 550 | (widen) | 532 | (widen) |
| @@ -556,13 +538,13 @@ Many aspects this mode can be customized using | |||
| 556 | (add-hook 'completion-at-point-functions | 538 | (add-hook 'completion-at-point-functions |
| 557 | #'nxml-completion-at-point-function nil t) | 539 | #'nxml-completion-at-point-function nil t) |
| 558 | (setq-local syntax-propertize-function #'nxml-after-change) | 540 | (setq-local syntax-propertize-function #'nxml-after-change) |
| 559 | (add-hook 'change-major-mode-hook 'nxml-cleanup nil t) | 541 | (add-hook 'change-major-mode-hook #'nxml-cleanup nil t) |
| 560 | 542 | ||
| 561 | ;; Emacs 23 handles the encoding attribute on the xml declaration | 543 | ;; Emacs 23 handles the encoding attribute on the xml declaration |
| 562 | ;; transparently to nxml-mode, so there is no longer a need for the below | 544 | ;; transparently to nxml-mode, so there is no longer a need for the below |
| 563 | ;; hook. The hook also had the drawback of overriding explicit user | 545 | ;; hook. The hook also had the drawback of overriding explicit user |
| 564 | ;; instruction to save as some encoding other than utf-8. | 546 | ;; instruction to save as some encoding other than utf-8. |
| 565 | ;;(add-hook 'write-contents-hooks 'nxml-prepare-to-save) | 547 | ;;(add-hook 'write-contents-hooks #'nxml-prepare-to-save) |
| 566 | (when (not (and (buffer-file-name) (file-exists-p (buffer-file-name)))) | 548 | (when (not (and (buffer-file-name) (file-exists-p (buffer-file-name)))) |
| 567 | (when (and nxml-default-buffer-file-coding-system | 549 | (when (and nxml-default-buffer-file-coding-system |
| 568 | (not (local-variable-p 'buffer-file-coding-system))) | 550 | (not (local-variable-p 'buffer-file-coding-system))) |
| @@ -592,7 +574,7 @@ Many aspects this mode can be customized using | |||
| 592 | (with-silent-modifications | 574 | (with-silent-modifications |
| 593 | (nxml-with-invisible-motion | 575 | (nxml-with-invisible-motion |
| 594 | (remove-text-properties (point-min) (point-max) '(face))))) | 576 | (remove-text-properties (point-min) (point-max) '(face))))) |
| 595 | (remove-hook 'change-major-mode-hook 'nxml-cleanup t)) | 577 | (remove-hook 'change-major-mode-hook #'nxml-cleanup t)) |
| 596 | 578 | ||
| 597 | (defun nxml-degrade (context err) | 579 | (defun nxml-degrade (context err) |
| 598 | (message "Internal nXML mode error in %s (%s), degrading" | 580 | (message "Internal nXML mode error in %s (%s), degrading" |
| @@ -1670,7 +1652,7 @@ single name. A character reference contains a character number." | |||
| 1670 | (t end))))) | 1652 | (t end))))) |
| 1671 | (nxml-scan-error | 1653 | (nxml-scan-error |
| 1672 | (goto-char (cadr err)) | 1654 | (goto-char (cadr err)) |
| 1673 | (apply 'error (cddr err))))) | 1655 | (apply #'error (cddr err))))) |
| 1674 | 1656 | ||
| 1675 | (defun nxml-backward-single-balanced-item () | 1657 | (defun nxml-backward-single-balanced-item () |
| 1676 | (condition-case err | 1658 | (condition-case err |
| @@ -1692,7 +1674,7 @@ single name. A character reference contains a character number." | |||
| 1692 | (t xmltok-start))))) | 1674 | (t xmltok-start))))) |
| 1693 | (nxml-scan-error | 1675 | (nxml-scan-error |
| 1694 | (goto-char (cadr err)) | 1676 | (goto-char (cadr err)) |
| 1695 | (apply 'error (cddr err))))) | 1677 | (apply #'error (cddr err))))) |
| 1696 | 1678 | ||
| 1697 | (defun nxml-scan-forward-within (end) | 1679 | (defun nxml-scan-forward-within (end) |
| 1698 | (setq end (- end (nxml-end-delimiter-length xmltok-type))) | 1680 | (setq end (- end (nxml-end-delimiter-length xmltok-type))) |
| @@ -1876,7 +1858,7 @@ single name. A character reference contains a character number." | |||
| 1876 | (setq arg (1- arg))) | 1858 | (setq arg (1- arg))) |
| 1877 | (nxml-scan-error | 1859 | (nxml-scan-error |
| 1878 | (goto-char (cadr err)) | 1860 | (goto-char (cadr err)) |
| 1879 | (apply 'error (cddr err)))))) | 1861 | (apply #'error (cddr err)))))) |
| 1880 | 1862 | ||
| 1881 | (defun nxml-backward-up-element (&optional arg) | 1863 | (defun nxml-backward-up-element (&optional arg) |
| 1882 | (interactive "p") | 1864 | (interactive "p") |
| @@ -1905,7 +1887,7 @@ single name. A character reference contains a character number." | |||
| 1905 | (setq arg (1- arg))) | 1887 | (setq arg (1- arg))) |
| 1906 | (nxml-scan-error | 1888 | (nxml-scan-error |
| 1907 | (goto-char (cadr err)) | 1889 | (goto-char (cadr err)) |
| 1908 | (apply 'error (cddr err)))))) | 1890 | (apply #'error (cddr err)))))) |
| 1909 | 1891 | ||
| 1910 | (defun nxml-down-element (&optional arg) | 1892 | (defun nxml-down-element (&optional arg) |
| 1911 | "Move forward down into the content of an element. | 1893 | "Move forward down into the content of an element. |
| @@ -1970,7 +1952,7 @@ Negative ARG means move backward." | |||
| 1970 | (setq arg (1- arg))) | 1952 | (setq arg (1- arg))) |
| 1971 | (nxml-scan-error | 1953 | (nxml-scan-error |
| 1972 | (goto-char (cadr err)) | 1954 | (goto-char (cadr err)) |
| 1973 | (apply 'error (cddr err)))))) | 1955 | (apply #'error (cddr err)))))) |
| 1974 | 1956 | ||
| 1975 | (defun nxml-backward-element (&optional arg) | 1957 | (defun nxml-backward-element (&optional arg) |
| 1976 | "Move backward over one element. | 1958 | "Move backward over one element. |
| @@ -1992,7 +1974,7 @@ Negative ARG means move forward." | |||
| 1992 | (setq arg (1- arg))) | 1974 | (setq arg (1- arg))) |
| 1993 | (nxml-scan-error | 1975 | (nxml-scan-error |
| 1994 | (goto-char (cadr err)) | 1976 | (goto-char (cadr err)) |
| 1995 | (apply 'error (cddr err)))))) | 1977 | (apply #'error (cddr err)))))) |
| 1996 | 1978 | ||
| 1997 | (defun nxml-mark-token-after () | 1979 | (defun nxml-mark-token-after () |
| 1998 | (interactive) | 1980 | (interactive) |
diff --git a/lisp/nxml/rng-nxml.el b/lisp/nxml/rng-nxml.el index 85e4bf33ee0..467f7af0bb7 100644 --- a/lisp/nxml/rng-nxml.el +++ b/lisp/nxml/rng-nxml.el | |||
| @@ -33,6 +33,7 @@ | |||
| 33 | (require 'rng-valid) | 33 | (require 'rng-valid) |
| 34 | (require 'nxml-mode) | 34 | (require 'nxml-mode) |
| 35 | (require 'rng-loc) | 35 | (require 'rng-loc) |
| 36 | (require 'sgml-mode) | ||
| 36 | 37 | ||
| 37 | (defcustom rng-nxml-auto-validate-flag t | 38 | (defcustom rng-nxml-auto-validate-flag t |
| 38 | "Non-nil means automatically turn on validation with nxml-mode." | 39 | "Non-nil means automatically turn on validation with nxml-mode." |
| @@ -65,6 +66,9 @@ Complete on start-tag names regardless.") | |||
| 65 | ["Validation" rng-validate-mode | 66 | ["Validation" rng-validate-mode |
| 66 | :style toggle | 67 | :style toggle |
| 67 | :selected rng-validate-mode] | 68 | :selected rng-validate-mode] |
| 69 | ["Electric Pairs" sgml-electric-tag-pair-mode | ||
| 70 | :style toggle | ||
| 71 | :selected sgml-electric-tag-pair-mode] | ||
| 68 | "---" | 72 | "---" |
| 69 | ("Set Schema" | 73 | ("Set Schema" |
| 70 | ["Automatically" rng-auto-set-schema] | 74 | ["Automatically" rng-auto-set-schema] |
| @@ -107,12 +111,12 @@ Validation will be enabled if `rng-nxml-auto-validate-flag' is non-nil." | |||
| 107 | 'append) | 111 | 'append) |
| 108 | (cond (rng-nxml-auto-validate-flag | 112 | (cond (rng-nxml-auto-validate-flag |
| 109 | (rng-validate-mode 1) | 113 | (rng-validate-mode 1) |
| 110 | (add-hook 'nxml-completion-hook 'rng-complete nil t) | 114 | (add-hook 'nxml-completion-hook #'rng-complete nil t) |
| 111 | (add-hook 'nxml-in-mixed-content-hook 'rng-in-mixed-content-p nil t)) | 115 | (add-hook 'nxml-in-mixed-content-hook #'rng-in-mixed-content-p nil t)) |
| 112 | (t | 116 | (t |
| 113 | (rng-validate-mode 0) | 117 | (rng-validate-mode 0) |
| 114 | (remove-hook 'nxml-completion-hook 'rng-complete t) | 118 | (remove-hook 'nxml-completion-hook #'rng-complete t) |
| 115 | (remove-hook 'nxml-in-mixed-content-hook 'rng-in-mixed-content-p t)))) | 119 | (remove-hook 'nxml-in-mixed-content-hook #'rng-in-mixed-content-p t)))) |
| 116 | 120 | ||
| 117 | (defvar rng-tag-history nil) | 121 | (defvar rng-tag-history nil) |
| 118 | (defvar rng-attribute-name-history nil) | 122 | (defvar rng-attribute-name-history nil) |
| @@ -328,7 +332,7 @@ Return non-nil if in a context it understands." | |||
| 328 | (nxml-ns-get-default)))) | 332 | (nxml-ns-get-default)))) |
| 329 | (if (and ns (memq prefix (nxml-ns-changed-prefixes))) | 333 | (if (and ns (memq prefix (nxml-ns-changed-prefixes))) |
| 330 | (list (nxml-namespace-name ns)) | 334 | (list (nxml-namespace-name ns)) |
| 331 | (mapcar 'nxml-namespace-name | 335 | (mapcar #'nxml-namespace-name |
| 332 | (delq nxml-xml-namespace-uri | 336 | (delq nxml-xml-namespace-uri |
| 333 | (rng-match-possible-namespace-uris)))))) | 337 | (rng-match-possible-namespace-uris)))))) |
| 334 | 338 | ||
| @@ -502,14 +506,7 @@ set `xmltok-dtd'. Returns the position of the end of the token." | |||
| 502 | (rng-match-attribute-name (cons ns local-name))))) | 506 | (rng-match-attribute-name (cons ns local-name))))) |
| 503 | 507 | ||
| 504 | (defun rng-complete-qname-function (string predicate flag) | 508 | (defun rng-complete-qname-function (string predicate flag) |
| 505 | (let ((alist (mapcar (lambda (name) (cons name nil)) | 509 | (complete-with-action flag (rng-generate-qname-list string) string predicate)) |
| 506 | (rng-generate-qname-list string)))) | ||
| 507 | (cond ((not flag) | ||
| 508 | (try-completion string alist predicate)) | ||
| 509 | ((eq flag t) | ||
| 510 | (all-completions string alist predicate)) | ||
| 511 | ((eq flag 'lambda) | ||
| 512 | (and (assoc string alist) t))))) | ||
| 513 | 510 | ||
| 514 | (defun rng-generate-qname-list (&optional string) | 511 | (defun rng-generate-qname-list (&optional string) |
| 515 | (let ((forced-prefix (and string | 512 | (let ((forced-prefix (and string |
| @@ -550,7 +547,7 @@ set `xmltok-dtd'. Returns the position of the end of the token." | |||
| 550 | (setcdr ns-prefixes (cons nil (cdr ns-prefixes)))))) | 547 | (setcdr ns-prefixes (cons nil (cdr ns-prefixes)))))) |
| 551 | (setq iter (cdr iter))) | 548 | (setq iter (cdr iter))) |
| 552 | (rng-uniquify-equal | 549 | (rng-uniquify-equal |
| 553 | (sort (apply 'append | 550 | (sort (apply #'append |
| 554 | (cons rng-complete-extra-strings | 551 | (cons rng-complete-extra-strings |
| 555 | (mapcar (lambda (name) | 552 | (mapcar (lambda (name) |
| 556 | (if (car name) | 553 | (if (car name) |
| @@ -584,7 +581,7 @@ set `xmltok-dtd'. Returns the position of the end of the token." | |||
| 584 | 581 | ||
| 585 | (defun rng-strings-to-completion-alist (strings) | 582 | (defun rng-strings-to-completion-alist (strings) |
| 586 | (mapcar (lambda (s) (cons s s)) | 583 | (mapcar (lambda (s) (cons s s)) |
| 587 | (rng-uniquify-equal (sort (mapcar 'rng-escape-string strings) | 584 | (rng-uniquify-equal (sort (mapcar #'rng-escape-string strings) |
| 588 | 'string<)))) | 585 | 'string<)))) |
| 589 | 586 | ||
| 590 | (provide 'rng-nxml) | 587 | (provide 'rng-nxml) |
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 98a01e8d83f..f729760e9ca 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el | |||
| @@ -862,11 +862,12 @@ Return non-nil if we skipped over matched tags." | |||
| 862 | (if endp | 862 | (if endp |
| 863 | (when (sgml-skip-tag-backward 1) (forward-char 1) t) | 863 | (when (sgml-skip-tag-backward 1) (forward-char 1) t) |
| 864 | (with-syntax-table sgml-tag-syntax-table | 864 | (with-syntax-table sgml-tag-syntax-table |
| 865 | (up-list -1) | 865 | (let ((forward-sexp-function nil)) |
| 866 | (when (sgml-skip-tag-forward 1) | 866 | (up-list -1) |
| 867 | (backward-sexp 1) | 867 | (when (sgml-skip-tag-forward 1) |
| 868 | (forward-char 2) | 868 | (backward-sexp 1) |
| 869 | t)))) | 869 | (forward-char 2) |
| 870 | t))))) | ||
| 870 | (clones (get-char-property (point) 'text-clones))) | 871 | (clones (get-char-property (point) 'text-clones))) |
| 871 | (when (and match | 872 | (when (and match |
| 872 | (/= cl-end cl-start) | 873 | (/= cl-end cl-start) |