为什么font-lock-fontify-buffer在从迷你缓冲区工作时不能从elisp工作?

时间:2012-02-02 20:19:33

标签: emacs elisp

所以我正在攻击一些elisp来测试一个Web服务,我遇到了语法高亮问题。我正在使用url-retrieve-synchronous来获取HTTP响应,然后编辑文本以获得我需要查看的XML。不幸的是,语法突出显示在返回的缓冲区中不起作用,即使我已将其设置为nxml-mode并在脚本中使用“font-lock-fontify-buffer”。但是,如果我做“M-x font-lock-fontify-buffer”,突出显示就像我期望的那样。在elisp和emacs内部使用它有什么区别吗?

以下是我正在整理的脚本的相关部分。我在前面承认这是我做过的第一个elisp脚本,而且我可能以一种荒谬不正确的方式做事,但到目前为止一切都有效。

(defun modality-http-request (url args request-type)
    (let ((url-request-method request-type)
        (url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded")))
        (url-request-data
            (mapconcat (lambda (arg)
                (concat  (url-hexify-string (car arg))
                    "="
                    (url-hexify-string (cdr arg))))
                    args
                    "&")))
        (url-retrieve-synchronously url)))

(defun modality-http-get (url args)
    (modality-http-request url args "GET"))

(defun modality-http-post (url args)
    (modality-http-request url args "POST"))

(defun test-modality (test)
    (interactive "s\Test: ")
        (let ((buffer (modality-http-get (concat (get-modality-path) test) nil)))
            (set-buffer buffer)
            (setq modality-beginning (point))
            (forward-paragraph)
            (next-line)
            (beginning-of-line)
            (setq modality-end (point))
            (delete-region modality-beginning modality-end)
            (bf-pretty-print-xml-region)
            (switch-to-buffer buffer)
            (font-lock-fontify-buffer)))

(defun bf-pretty-print-xml-region ()
  "Pretty format XML markup in region. You need to have nxml-mode
http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
this.  The function inserts linebreaks to separate tags that have
nothing but whitespace between them.  It then indents the markup
by using nxml's indentation rules."
  (interactive "r")
  (save-excursion
      (nxml-mode)
      (goto-char (point-min))
      (while (search-forward-regexp "\>[ \\t]*\<" nil t) 
        (backward-char) (insert "\n"))
      (indent-region (point-min) (point-max))
      ))

1 个答案:

答案 0 :(得分:1)

URL使用临时/内部缓冲区(通过其名称以空格开头的事实来识别)。它们非常正常,但有些功能会特别对待它们:不会激活font-lock,并且通常不会向用户显示缓冲区(例如,C-x b TAB不会显示这些缓冲区)。 因此,要么在启用font-lock之前重命名缓冲区,要么将所需的文本复制到另一个名称不以空格开头的缓冲区中。