Run sgml-pretty-print when opening xml file in emacs?

Currently I can use sgml-pretty-print to print an XML file in emacs, but this is a manual process:

  • M- <
  • C space
  • M →
  • Mx sgml-pretty-print

I would like this to happen automatically (or at least have some kind of option). I am new to emacs / elisp and don't understand how:

  • emacs knows what code to run when opening a file (does this start with files.el?)
  • If you want to override this code with your own, how to do it
+3
source share
2 answers

This should do the trick for you:

(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 opened (if it sgml)"
  (when (eq major-mode 'sgml-mode)
    (sgml-pretty-print (point-min) (point-max))))

find-file-hook, point-min (-max) major-mode.

elisp, question, , , .

+6

. ~/.emacs :

(add-hook 'sgml-mode-hook #'(lambda ()
  (sgml-pretty-print (point-min) (point-max))))
+4

Source: https://habr.com/ru/post/1708769/


All Articles