[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: xml-parse-file and text properties
From: |
JD Smith |
Subject: |
Re: xml-parse-file and text properties |
Date: |
Mon, 24 Jul 2006 09:44:51 -0700 |
User-agent: |
Pan/0.14.2.91 (As She Crawled Across the Table) |
On Sat, 22 Jul 2006 12:15:34 +0300, Eli Zaretskii wrote:
>> From: JD Smith <address@hidden>
>> 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)
- Re: xml-parse-file and text properties, (continued)
- Re: xml-parse-file and text properties, Richard Stallman, 2006/07/24
- Re: xml-parse-file and text properties, Stuart D. Herring, 2006/07/24
- Re: xml-parse-file and text properties, Richard Stallman, 2006/07/24
- Re: xml-parse-file and text properties, Stefan Monnier, 2006/07/25
- Re: xml-parse-file and text properties, Richard Stallman, 2006/07/25
- Re: xml-parse-file and text properties, Stefan Monnier, 2006/07/24
- Re: xml-parse-file and text properties, Richard Stallman, 2006/07/24
- Re: xml-parse-file and text properties, Thien-Thi Nguyen, 2006/07/21
- Re: xml-parse-file and text properties, JD Smith, 2006/07/21
- Re: xml-parse-file and text properties, Eli Zaretskii, 2006/07/22
- Re: xml-parse-file and text properties,
JD Smith <=
- Re: xml-parse-file and text properties, JD Smith, 2006/07/25
- Re: xml-parse-file and text properties, Stefan Monnier, 2006/07/25
- Re: xml-parse-file and text properties, JD Smith, 2006/07/25