From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.devel Subject: Re: xml-parse-file and text properties Date: Mon, 24 Jul 2006 09:44:51 -0700 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1153759586 27786 80.91.229.2 (24 Jul 2006 16:46:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 24 Jul 2006 16:46:26 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 24 18:46:25 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G53Yu-0003O8-QA for ged-emacs-devel@m.gmane.org; Mon, 24 Jul 2006 18:45:45 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G53Yu-0006FL-DG for ged-emacs-devel@m.gmane.org; Mon, 24 Jul 2006 12:45:44 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G53Yh-0006F6-45 for emacs-devel@gnu.org; Mon, 24 Jul 2006 12:45:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G53Yg-0006Ei-95 for emacs-devel@gnu.org; Mon, 24 Jul 2006 12:45:30 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G53Yg-0006Ee-0G for emacs-devel@gnu.org; Mon, 24 Jul 2006 12:45:30 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1G53Zn-0005aR-Am for emacs-devel@gnu.org; Mon, 24 Jul 2006 12:46:39 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1G53YP-0003CR-97 for emacs-devel@gnu.org; Mon, 24 Jul 2006 18:45:13 +0200 Original-Received: from turtle.as.arizona.edu ([128.196.208.207]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 24 Jul 2006 18:45:13 +0200 Original-Received: from jdsmith by turtle.as.arizona.edu with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 24 Jul 2006 18:45:13 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: emacs-devel@gnu.org Original-Lines: 100 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: turtle.as.arizona.edu User-Agent: Pan/0.14.2.91 (As She Crawled Across the Table) 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:57551 Archived-At: On Sat, 22 Jul 2006 12:15:34 +0300, Eli Zaretskii wrote: >> From: JD Smith >> Date: Fri, 21 Jul 2006 14:45:27 -0700 >> >> This is similar to the improved method Richard proposed yesterday >> (insert-file-contents using a temporary buffer). Remarkably enough >> (and highly surprising to me), even inserting the XML file contents in >> a temporary buffer is enough to get '(fontified nil) text properties >> added all over > > I don't see anything surprising here, since font-lock is now ON by > default. > > You should be able to overcome this if you turn off font-lock-mode in > the temporary buffer, before inserting the file's contents. This was my mistake. In fact, with Richard's formulation: (with-temp-buffer (insert-file-contents file) (xml-parse-region (point-min) (point-max) (current-buffer) parse-dtd parse-ns)))) no font-lock text properties ever get added to the temporary buffer, despite global-font-lock being on. It turns out I was pre-loading the file into a buffer to prevent warnings about its read-only status, so this code path was not being taken. With the patch below, xml-parse-file only returns unwanted text properties when a file is already loaded into a buffer. Should we install it? This doesn't address the larger issue of whether xml-parse-file should ever return text-properties, but it is simple and sensible. JD *** xml.el 06 Feb 2006 07:33:36 -0700 1.53 --- xml.el 24 Jul 2006 09:40:07 -0700 *************** *** 161,187 **** ;;;###autoload (defun xml-parse-file (file &optional parse-dtd parse-ns) "Parse the well-formed XML file FILE. ! If FILE is already visited, use its buffer and don't kill it. ! Returns the top node with all its children. ! If PARSE-DTD is non-nil, the DTD is parsed rather than skipped. ! If PARSE-NS is non-nil, then QNAMES are expanded." ! (let ((keep)) ! (if (get-file-buffer file) ! (progn ! (set-buffer (get-file-buffer file)) ! (setq keep (point))) ! (let (auto-mode-alist) ; no need for xml-mode ! (find-file file))) ! ! (let ((xml (xml-parse-region (point-min) ! (point-max) ! (current-buffer) ! parse-dtd parse-ns))) ! (if keep ! (goto-char keep) ! (kill-buffer (current-buffer))) ! xml))) ! (defvar xml-name-re) (defvar xml-entity-value-re) --- 161,182 ---- ;;;###autoload (defun xml-parse-file (file &optional parse-dtd parse-ns) "Parse the well-formed XML file FILE. ! If FILE is already visited, use its buffer and don't kill it. Returns the ! top node with all its children. If PARSE-DTD is non-nil, the DTD is parsed ! rather than skipped. If PARSE-NS is non-nil, then QNAMES are expanded." ! (if (get-file-buffer file) ! (with-current-buffer (get-file-buffer file) ! (save-excursion ! (xml-parse-region (point-min) ! (point-max) ! (current-buffer) ! parse-dtd parse-ns))) ! (with-temp-buffer ! (insert-file-contents file) ! (xml-parse-region (point-min) ! (point-max) ! (current-buffer) ! parse-dtd parse-ns)))) (defvar xml-name-re) (defvar xml-entity-value-re)