1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-02-02 20:16:25 +00:00

* lisp/nxml/nxml-mode.el: Use lexical-binding and syntax-propertize.

(font-lock-beg, font-lock-end): Move before first use.
(nxml-mode): Use syntax-propertize-function.
(nxml-after-change, nxml-after-change1): Adjust accordingly.
(nxml-extend-after-change-region): Remove.
* lisp/nxml/nxml-ns.el: Use lexical-binding.
(nxml-ns-save): Use `declare'.
(nxml-ns-prefixes-for): Avoid add-to-list.
* lisp/nxml/nxml-util.el: Use lexical-binding.
(nxml-with-degradation-on-error, nxml-with-invisible-motion):
Use `declare'.
* lisp/nxml/rng-match.el: Use lexical-binding.
(rng--ipattern): Use cl-defstruct.
(rng-compute-start-tag-open-deriv, rng-compute-start-attribute-deriv)
(rng-cons-group-after, rng-subst-group-after)
(rng-subst-interleave-after, rng-apply-after, rng-compute-data-deriv):
Use closures instead of `(lambda...).
* lisp/nxml/xmltok.el: Use lexical-binding.
(xmltok-save): Use `declare'.
(xmltok-unclosed-reparse-p, xmltok-semi-closed-reparse-p): Remove.
This commit is contained in:
Stefan Monnier 2013-10-07 09:54:48 -04:00
parent 2f84ba1086
commit da3e5ebb8d
6 changed files with 290 additions and 368 deletions

View File

@ -1,14 +1,37 @@
2013-10-07 Stefan Monnier <monnier@iro.umontreal.ca>
* nxml/nxml-mode.el: Use lexical-binding and syntax-propertize.
(font-lock-beg, font-lock-end): Move before first use.
(nxml-mode): Use syntax-propertize-function.
(nxml-after-change, nxml-after-change1): Adjust accordingly.
(nxml-extend-after-change-region): Remove.
* nxml/xmltok.el: Use lexical-binding.
(xmltok-save): Use `declare'.
(xmltok-unclosed-reparse-p, xmltok-semi-closed-reparse-p): Remove.
* nxml/nxml-util.el: Use lexical-binding.
(nxml-with-degradation-on-error, nxml-with-invisible-motion):
Use `declare'.
* nxml/nxml-ns.el: Use lexical-binding.
(nxml-ns-save): Use `declare'.
(nxml-ns-prefixes-for): Avoid add-to-list.
* nxml/rng-match.el: Use lexical-binding.
(rng--ipattern): Use cl-defstruct.
(rng-compute-start-tag-open-deriv, rng-compute-start-attribute-deriv)
(rng-cons-group-after, rng-subst-group-after)
(rng-subst-interleave-after, rng-apply-after, rng-compute-data-deriv):
Use closures instead of `(lambda...).
2013-10-07 Michael Albinus <michael.albinus@gmx.de>
* net/tramp.el (tramp-handle-insert-file-contents): Improve handling
of BEG and END.
* net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): Use
`tramp-handle-insert-file-contents'.
* net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
Use `tramp-handle-insert-file-contents'.
(tramp-gvfs-handle-insert-file-contents): Remove function.
* net/tramp-sh.el (tramp-sh-handle-insert-directory): Use
`save-restriction' in order to keep markers.
* net/tramp-sh.el (tramp-sh-handle-insert-directory):
Use `save-restriction' in order to keep markers.
* net/trampver.el: Update release number.
@ -20,7 +43,8 @@
* emacs-lisp/easymenu.el (easy-menu-create-menu): Use closures.
* emacs-lisp/lisp-mode.el (eval-defun-2): Simplify, using lexical-binding.
* emacs-lisp/lisp-mode.el (eval-defun-2): Simplify, using
lexical-binding.
* emacs-lisp/tq.el (tq-create): Use a closure instead of `(lambda...).

View File

@ -1,4 +1,4 @@
;;; nxml-mode.el --- a new XML mode
;;; nxml-mode.el --- a new XML mode -*- lexical-binding:t -*-
;; Copyright (C) 2003-2004, 2007-2013 Free Software Foundation, Inc.
@ -540,14 +540,14 @@ Many aspects this mode can be customized using
(nxml-scan-prolog)))))
(add-hook 'completion-at-point-functions
#'nxml-completion-at-point-function nil t)
(add-hook 'after-change-functions 'nxml-after-change nil t)
(setq-local syntax-propertize-function #'nxml-after-change)
(add-hook 'change-major-mode-hook 'nxml-cleanup nil t)
;; Emacs 23 handles the encoding attribute on the xml declaration
;; transparently to nxml-mode, so there is no longer a need for the below
;; hook. The hook also had the drawback of overriding explicit user
;; instruction to save as some encoding other than utf-8.
;;; (add-hook 'write-contents-hooks 'nxml-prepare-to-save)
;;(add-hook 'write-contents-hooks 'nxml-prepare-to-save)
(when (not (and (buffer-file-name) (file-exists-p (buffer-file-name))))
(when (and nxml-default-buffer-file-coding-system
(not (local-variable-p 'buffer-file-coding-system)))
@ -561,8 +561,6 @@ Many aspects this mode can be customized using
nil ; font-lock-keywords-case-fold-search. XML is case sensitive
nil ; no special syntax table
nil ; no automatic syntactic fontification
(font-lock-extend-after-change-region-function
. nxml-extend-after-change-region)
(font-lock-extend-region-functions . (nxml-extend-region))
(jit-lock-contextually . t)
(font-lock-unfontify-region-function . nxml-unfontify-region)))
@ -597,6 +595,7 @@ Many aspects this mode can be customized using
;;; Change management
(defvar font-lock-beg) (defvar font-lock-end)
(defun nxml-debug-region (start end)
(interactive "r")
(let ((font-lock-beg start)
@ -605,22 +604,16 @@ Many aspects this mode can be customized using
(goto-char font-lock-beg)
(set-mark font-lock-end)))
(defun nxml-after-change (start end pre-change-length)
; In font-lock mode, nxml-after-change1 is called via
; nxml-extend-after-change-region instead so that the updated
; book-keeping information is available for fontification.
(unless (or font-lock-mode nxml-degraded)
(defun nxml-after-change (start end)
;; Called via syntax-propertize-function.
(unless nxml-degraded
(nxml-with-degradation-on-error 'nxml-after-change
(save-excursion
(save-restriction
(widen)
(save-match-data
(nxml-with-invisible-motion
(with-silent-modifications
(nxml-after-change1
start end pre-change-length)))))))))
(save-restriction
(widen)
(nxml-with-invisible-motion
(nxml-after-change1 start end))))))
(defun nxml-after-change1 (start end pre-change-length)
(defun nxml-after-change1 (start end)
"After-change bookkeeping.
Returns a cons cell containing a possibly-enlarged change region.
You must call `nxml-extend-region' on this expanded region to obtain
@ -628,23 +621,14 @@ the full extent of the area needing refontification.
For bookkeeping, call this function even when fontification is
disabled."
(let ((pre-change-end (+ start pre-change-length)))
;; If the prolog might have changed, rescan the prolog
(when (<= start
;; Add 2 so as to include the < and following char that
;; start the instance (document element), since changing
;; these can change where the prolog ends.
(+ nxml-prolog-end 2))
;; end must be extended to at least the end of the old prolog in
;; case the new prolog is shorter
(when (< pre-change-end nxml-prolog-end)
(setq end
;; don't let end get out of range even if pre-change-length
;; is bogus
(min (point-max)
(+ end (- nxml-prolog-end pre-change-end)))))
(nxml-scan-prolog)
(setq start (point-min))))
;; If the prolog might have changed, rescan the prolog.
(when (<= start
;; Add 2 so as to include the < and following char that
;; start the instance (document element), since changing
;; these can change where the prolog ends.
(+ nxml-prolog-end 2))
(nxml-scan-prolog)
(setq start (point-min)))
(when (> end nxml-prolog-end)
(goto-char start)
@ -653,8 +637,7 @@ disabled."
(setq end (max (nxml-scan-after-change start end)
end)))
(nxml-debug-change "nxml-after-change1" start end)
(cons start end))
(nxml-debug-change "nxml-after-change1" start end))
;;; Encodings
@ -845,7 +828,6 @@ The XML declaration will declare an encoding depending on the buffer's
(font-lock-default-unfontify-region start end)
(nxml-clear-char-ref-extra-display start end))
(defvar font-lock-beg) (defvar font-lock-end)
(defun nxml-extend-region ()
"Extend the region to hold the minimum area we can fontify with nXML.
Called with `font-lock-beg' and `font-lock-end' dynamically bound."
@ -887,19 +869,6 @@ Called with `font-lock-beg' and `font-lock-end' dynamically bound."
(nxml-debug-change "nxml-extend-region" start end)
t)))
(defun nxml-extend-after-change-region (start end pre-change-length)
(unless nxml-degraded
(nxml-with-degradation-on-error
'nxml-extend-after-change-region
(save-excursion
(save-restriction
(widen)
(save-match-data
(nxml-with-invisible-motion
(with-silent-modifications
(nxml-after-change1
start end pre-change-length)))))))))
(defun nxml-fontify-matcher (bound)
"Called as font-lock keyword matcher."

View File

@ -1,4 +1,4 @@
;;; nxml-ns.el --- XML namespace processing
;;; nxml-ns.el --- XML namespace processing -*- lexical-binding:t -*-
;; Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc.
@ -56,12 +56,10 @@ namespace bindings (no default namespace and only the xml prefix bound).")
(equal nxml-ns-state state))
(defmacro nxml-ns-save (&rest body)
(declare (indent 0) (debug t))
`(let ((nxml-ns-state nxml-ns-initial-state))
,@body))
(put 'nxml-ns-save 'lisp-indent-function 0)
(def-edebug-spec nxml-ns-save t)
(defun nxml-ns-init ()
(setq nxml-ns-state nxml-ns-initial-state))
@ -117,11 +115,12 @@ NS is a symbol or nil."
(setq current (cdr current))
(while (let ((binding (rassq ns current)))
(when binding
(when (eq (nxml-ns-get-prefix (car binding)) ns)
(add-to-list 'prefixes
(car binding)))
(setq current
(cdr (member binding current))))))
(let ((prefix (car binding)))
(when (eq (nxml-ns-get-prefix prefix) ns)
(unless (member prefix prefixes)
(push prefix prefixes))))
(setq current
(cdr (member binding current))))))
prefixes))
(defun nxml-ns-prefix-for (ns)

View File

@ -1,4 +1,4 @@
;;; nxml-util.el --- utility functions for nxml-*.el
;;; nxml-util.el --- utility functions for nxml-*.el -*- lexical-binding:t -*-
;; Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc.
@ -70,6 +70,7 @@ This is the inverse of `nxml-make-namespace'."
(nxml-make-namespace "http://www.w3.org/2000/xmlns/"))
(defmacro nxml-with-degradation-on-error (context &rest body)
(declare (indent 1) (debug t))
(if (not nxml-debug)
(let ((error-symbol (make-symbol "err")))
`(condition-case ,error-symbol
@ -80,12 +81,10 @@ This is the inverse of `nxml-make-namespace'."
(defmacro nxml-with-invisible-motion (&rest body)
"Evaluate body without calling any point motion hooks."
(declare (indent 0) (debug t))
`(let ((inhibit-point-motion-hooks t))
,@body))
(put 'nxml-with-invisible-motion 'lisp-indent-function 0)
(def-edebug-spec nxml-with-invisible-motion t)
(defun nxml-display-file-parse-error (err)
(let* ((filename (nth 1 err))
(buffer (find-file-noselect filename))

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
;;; xmltok.el --- XML tokenization
;;; xmltok.el --- XML tokenization -*- lexical-binding:t -*-
;; Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc.
@ -142,6 +142,7 @@ string giving the error message and START and END are integers
indicating the position of the error.")
(defmacro xmltok-save (&rest body)
(declare (indent 0) (debug t))
`(let (xmltok-type
xmltok-start
xmltok-name-colon
@ -152,9 +153,6 @@ indicating the position of the error.")
xmltok-errors)
,@body))
(put 'xmltok-save 'lisp-indent-function 0)
(def-edebug-spec xmltok-save t)
(defsubst xmltok-attribute-name-start (att)
(aref att 0))
@ -411,7 +409,6 @@ Return the type of the token."
(eval-when-compile
(let* ((or "\\|")
(open "\\(?:")
(gopen "\\(")
(close "\\)")
(name-start-char "[_[:alpha:]]")
(name-continue-not-start-char "[-.[:digit:]]")
@ -988,33 +985,6 @@ Return the type of the token."
(xmltok-valid-char-p n)
n)))
(defun xmltok-unclosed-reparse-p (change-start
change-end
pre-change-length
start
end
delimiter)
(let ((len-1 (1- (length delimiter))))
(goto-char (max start (- change-start len-1)))
(search-forward delimiter (min end (+ change-end len-1)) t)))
;; Handles a <!-- with the next -- not followed by >
(defun xmltok-semi-closed-reparse-p (change-start
change-end
pre-change-length
start
end
delimiter
delimiter-length)
(or (<= (- end delimiter-length) change-end)
(xmltok-unclosed-reparse-p change-start
change-end
pre-change-length
start
end
delimiter)))
(defun xmltok-valid-char-p (n)
"Return non-nil if N is the Unicode code of a valid XML character."
(cond ((< n #x20) (memq n '(#xA #xD #x9)))
@ -1072,7 +1042,7 @@ Adds to `xmltok-errors' as appropriate."
(setq xmltok-dtd xmltok-predefined-entity-alist)
(xmltok-scan-xml-declaration)
(xmltok-next-prolog-token)
(while (condition-case err
(while (condition-case nil
(when (xmltok-parse-prolog-item)
(xmltok-next-prolog-token))
(xmltok-markup-declaration-parse-error
@ -1371,7 +1341,7 @@ If LIMIT is non-nil, then do not consider characters beyond LIMIT."
(t
(let ((xmltok-start (1- (point)))
xmltok-type xmltok-replacement)
(xmltok-scan-after-amp (lambda (start end)))
(xmltok-scan-after-amp (lambda (_start _end)))
(cond ((eq xmltok-type 'char-ref)
(setq value-parts
(cons (buffer-substring-no-properties