From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Lennart Borgman (gmail)" Newsgroups: gmane.emacs.devel Subject: nxml-mode parser and multi major modes Date: Wed, 28 May 2008 00:11:40 +0200 Message-ID: <483C871C.8040206@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020909020206090208030607" X-Trace: ger.gmane.org 1211926430 25110 80.91.229.12 (27 May 2008 22:13:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 27 May 2008 22:13:50 +0000 (UTC) To: Emacs Devel , Daniel Colascione Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 28 00:14:30 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K17PS-0006i8-Jr for ged-emacs-devel@m.gmane.org; Wed, 28 May 2008 00:12:47 +0200 Original-Received: from localhost ([127.0.0.1]:34421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K17Oh-0000WR-7m for ged-emacs-devel@m.gmane.org; Tue, 27 May 2008 18:11:59 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K17Oc-0000WL-0o for emacs-devel@gnu.org; Tue, 27 May 2008 18:11:54 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K17Oa-0000W9-4u for emacs-devel@gnu.org; Tue, 27 May 2008 18:11:52 -0400 Original-Received: from [199.232.76.173] (port=59028 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K17Oa-0000W6-2R for emacs-devel@gnu.org; Tue, 27 May 2008 18:11:52 -0400 Original-Received: from ch-smtp02.sth.basefarm.net ([80.76.149.213]:58001) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K17OZ-0003LG-6Q for emacs-devel@gnu.org; Tue, 27 May 2008 18:11:51 -0400 Original-Received: from c83-254-145-59.bredband.comhem.se ([83.254.145.59]:61131 helo=[127.0.0.1]) by ch-smtp02.sth.basefarm.net with esmtp (Exim 4.68) (envelope-from ) id 1K17OW-0005Dk-76; Wed, 28 May 2008 00:11:49 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 X-Antivirus: avast! (VPS 080527-1, 2008-05-27), Outbound message X-Antivirus-Status: Clean X-Originating-IP: 83.254.145.59 X-Scan-Result: No virus found in message 1K17OW-0005Dk-76. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1K17OW-0005Dk-76 d78840fada3ed0d84c02505756cad617 X-detected-kernel: by monty-python.gnu.org: Linux 2.6? (barebone, rare!) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:97839 Archived-At: This is a multi-part message in MIME format. --------------020909020206090208030607 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Since Daniel started to do some work on nxml-mode I decided to take a new look on the possibility to tame the nxml-mode parser to only look at those pieces of the buffer that it should care about. To my surprise it was much easier now :-) I have attached the relevant pieces from rng-valid.el. I think this is much easier to understand as one piece than as a diff. I believe it might need to be mixed with Daniel's code, not sure. So I send this here just in case someone has a comment or can make it better/faster. --------------020909020206090208030607 Content-Type: text/plain; name="rng-valid-for-mumamo.el" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rng-valid-for-mumamo.el" (defvar rng-get-major-mode-chunk-function nil "Function to use to get major mode chunk. It should take one argument, the point where to get the major mode chunk. This is to be set by multiple major mode frame works, like mumamo. See also `rng-valid-nxml-major-mode-chunk-function' and `rng-end-major-mode-chunk-function'. Note that all three variables must be set.") (make-variable-buffer-local 'rng-get-major-mode-chunk-function) (put 'rng-get-major-mode-chunk-function 'permanent-local t) (defvar rng-valid-nxml-major-mode-chunk-function nil "Function to use to check if nxml can parse major mode chunk. It should take one argument, the chunk. For more info see also `rng-get-major-mode-chunk-function'.") (make-variable-buffer-local 'rng-valid-nxml-major-mode-chunk-function) (put 'rng-valid-nxml-major-mode-chunk-function 'permanent-local t) (defvar rng-end-major-mode-chunk-function nil "Function to use to get the end of a major mode chunk. It should take one argument, the chunk. For more info see also `rng-get-major-mode-chunk-function'.") (make-variable-buffer-local 'rng-end-major-mode-chunk-function) (put 'rng-end-major-mode-chunk-function 'permanent-local t) (defun rng-do-some-validation-1 (&optional continue-p-function) (let (major-mode-chunk end-major-mode-chunk (limit (+ rng-validate-up-to-date-end rng-validate-chunk-size)) (remove-start rng-validate-up-to-date-end) (next-cache-point (+ (point) rng-state-cache-distance)) (continue t) (xmltok-dtd rng-dtd) have-remaining-chars xmltok-type xmltok-start xmltok-name-colon xmltok-name-end xmltok-replacement xmltok-attributes xmltok-namespace-attributes xmltok-dependent-regions xmltok-errors ) ;;(message ">>>>>>>>> here -1, p=%s" (point)) ;;(sit-for 4) (when (and continue (= (point) 1)) (let ((regions (xmltok-forward-prolog))) (rng-clear-overlays 1 (point)) (while regions (when (eq (aref (car regions) 0) 'encoding-name) (rng-process-encoding-name (aref (car regions) 1) (aref (car regions) 2))) (setq regions (cdr regions)))) (unless (equal rng-dtd xmltok-dtd) (rng-clear-conditional-region)) (setq rng-dtd xmltok-dtd)) (while continue ;; If mumamo (or something similar) is used then jump over parts ;; that can not be parsed by nxml-mode. (when (and rng-get-major-mode-chunk-function rng-valid-nxml-major-mode-chunk-function rng-end-major-mode-chunk-function) (let ((here (point)) next-non-space-pos) (skip-chars-forward " \t\r\n") (setq next-non-space-pos (point)) (goto-char here) ;;(message "here when, p=%s emmc=%s non-space=%s" (point) end-major-mode-chunk next-non-space-pos) ;;(sit-for 4) (unless (and end-major-mode-chunk ;; Remaining chars in this chunk? (< next-non-space-pos end-major-mode-chunk)) (setq end-major-mode-chunk nil) (setq major-mode-chunk (funcall rng-get-major-mode-chunk-function next-non-space-pos)) (while (and major-mode-chunk (not (funcall rng-valid-nxml-major-mode-chunk-function major-mode-chunk)) (< next-non-space-pos (point-max))) (let ((end-pos (funcall rng-end-major-mode-chunk-function major-mode-chunk))) (goto-char (+ end-pos 0)) (setq major-mode-chunk (funcall rng-get-major-mode-chunk-function (point))) ;;(message "---> here 3, point=%s, ep=%s, mm-chunk=%s" (point) end-pos major-mode-chunk) ) (setq next-non-space-pos (point)))) ;; Stop parsing if we do not have a chunk here yet. (setq continue (and major-mode-chunk (funcall rng-valid-nxml-major-mode-chunk-function major-mode-chunk))) (when continue ;;(message " continue=t") (setq end-major-mode-chunk (funcall rng-end-major-mode-chunk-function major-mode-chunk))))) (when continue ;;(message "*** here remain, p=%s" (point)) (setq have-remaining-chars (rng-forward end-major-mode-chunk)) ;;(message "*** here remain b, p=%s" (point)) (let ((pos (point))) (when end-major-mode-chunk ;; Fix-me: Seems like we need a new initialization (or why ;; do we otherwise hang without this?) (and (> limit end-major-mode-chunk) (setq limit end-major-mode-chunk))) (setq continue (and have-remaining-chars continue (or (< pos limit) (and continue-p-function (funcall continue-p-function) (setq limit (+ limit rng-validate-chunk-size)) t)))) (cond ((and rng-conditional-up-to-date-start ;; > because we are getting the state from (1- pos) (> pos rng-conditional-up-to-date-start) (< pos rng-conditional-up-to-date-end) (rng-state-matches-current (get-text-property (1- pos) 'rng-state))) (when (< remove-start (1- pos)) (rng-clear-cached-state remove-start (1- pos))) ;; sync up with cached validation state (setq continue nil) ;; do this before settting rng-validate-up-to-date-end ;; in case we get a quit (rng-mark-xmltok-errors) (rng-mark-xmltok-dependent-regions) (setq rng-validate-up-to-date-end (marker-position rng-conditional-up-to-date-end)) (rng-clear-conditional-region) (setq have-remaining-chars (< rng-validate-up-to-date-end (point-max)))) ((or (>= pos next-cache-point) (not continue)) (setq next-cache-point (+ pos rng-state-cache-distance)) (rng-clear-cached-state remove-start pos) (when have-remaining-chars ;;(message "rng-cach-state (1- %s)" pos) (rng-cache-state (1- pos))) (setq remove-start pos) (unless continue ;; if we have just blank chars skip to the end (when have-remaining-chars (skip-chars-forward " \t\r\n") (when (= (point) (point-max)) (rng-clear-overlays pos (point)) (rng-clear-cached-state pos (point)) (setq have-remaining-chars nil) (setq pos (point)))) (when (not have-remaining-chars) (rng-process-end-document)) (rng-mark-xmltok-errors) (rng-mark-xmltok-dependent-regions) (setq rng-validate-up-to-date-end pos) (when rng-conditional-up-to-date-end (cond ((<= rng-conditional-up-to-date-end pos) (rng-clear-conditional-region)) ((< rng-conditional-up-to-date-start pos) (set-marker rng-conditional-up-to-date-start pos)))))))))) have-remaining-chars)) --------------020909020206090208030607--