在emacs中打开xml文件时运行sgml pretty print?
我目前可以使用sgml pretty print在emacs中漂亮地打印xml文件,但这是一个手动过程:在emacs中打开xml文件时运行sgml pretty print?,emacs,elisp,Emacs,Elisp,我目前可以使用sgml pretty print在emacs中漂亮地打印xml文件,但这是一个手动过程: M- M-x sgml漂亮印花 我希望这种情况能够自动发生(或者至少可以选择这样做)。我是emacs/elisp新手,不了解如何: emacs知道打开文件时要运行什么代码(是否从files.el开始?) 如果您想用自己的代码覆盖该代码,如何做到这一点 这将为您带来好处: (add-hook 'find-file-hook 'my-sgml-find-file-hook) (defun my-
这将为您带来好处:
(add-hook 'find-file-hook 'my-sgml-find-file-hook)
(defun my-sgml-find-file-hook ()
"run sgml pretty-print on the file when it's opened (if it's sgml)"
(when (eq major-mode 'sgml-mode)
(sgml-pretty-print (point-min) (point-max))))
关键信息是、(-max)和
如果你想了解更多关于elisp的信息,你可以看看这个,它提供了一些关于如何解决问题的建议。一个稍微简单一点的替代方法。只需将其添加到您的
~/.emacs
文件中:
(add-hook 'sgml-mode-hook #'(lambda ()
(sgml-pretty-print (point-min) (point-max))))
是的,它有点简单,但TJ的解决方案也允许您手动运行该函数。此外,您可以将
sgml pretty print
函数调用包装在一个y-or-n-p
条件语句中,询问是否希望内容打印美观。您可以通过键入选择整个缓冲区的C-h
来结束第一步和第三步。对您来说,它是这样做的,但对我来说,C-h是序列中的第一个键,获取各种主题的帮助。抱歉,输入错误,我的意思是C-x h
。