;;    Artur Hefczyc sample, working .emacs file
;;    http://wttools.sf.net/
;;    (C) 2003, Artur Hefczyc
;;
;;    This library is free software; you can redistribute it and/or
;;    modify it under the terms of the GNU Lesser General Public
;;    License as published by the Free Software Foundation;
;;    version 2.1 of the License.
;;
;;    This library is distributed in the hope that it will be useful,
;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;    Lesser General Public License for more details.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;    Some of stuuf stored here are created on my own and some
;;    were found on the Internet.
;;    I hope I don't break their authors permisions. If some one
;;    will find I do, please let me know.
;;    I also don't remember where I have found these functions and
;;    who is origin author. 
;;    I will try to complete these lack if possible.
;;
;; $Id: $

(defun sgml-lt ()
  "Insert ISO entity reference for less-than."
  (interactive)
  (insert "<"))

(defun sgml-nbsp ()
  "Insert ISO entity reference for non-breaking space."
  (interactive)
  (insert " "))

(defun sgml-para ()
  "Insert para tags and position cursor."
  (interactive)
  (sgml-insert-element 'para))

(defun sgml-literal ()
  "Insert literal element."
  (interactive)
  (sgml-insert-element 'literal))
    
(defun sgml-kill-to-eoelement ()  
  "Kill to end of element."
  (interactive)
  (let ((start (point)))
    (sgml-end-of-element)
    (kill-region start (point))))

(defun sgml-copy-element ()
  "Copy the current element to the buffer."
  (interactive)
  (sgml-backward-up-element)
  (let ((start (point)))
    (sgml-forward-element)
    (kill-ring-save start (point))))

(defun sgml-fill-and-save ()
  "Rejustify element at cursor and save file."
  (interactive)
  (sgml-fill-element (sgml-find-element-of (point))) ; see psgml-edit.el
  (save-buffer))

;;; The only way I have found to customize sgml and xml mode
;;; defined in pacjage psgml is to add customizations to 
;;; switching mode hook.
(defun my-psgml-mode-hook ()
  "It looks this is the only way to set variables for psgml"
    (setq
     sgml-insert-missing-element-comment nil
     sgml-auto-insert-required-elements t
     sgml-live-element-indicator t
     sgml-ommittag-transparent t
     sgml-balanced-tag-edit t
     sgml-indent-data t
     sgml-indent-step 2
     sgml-set-face t
     sgml-validate-command "xmllint -noout -valid %s %s"
     sgml-markup-faces '((comment   . font-lock-comment-face)
                         (start-tag . font-lock-keyword-face)
                         (end-tag   . font-lock-builtin-face)
                         (doctype   . font-lock-type-face)
                         (entity    . font-lock-function-name-face)
                         (pi . bold)
                         (sgml . bold)
                         (shortref . font-lock-string-face)
                         ))

    (define-key sgml-mode-map "\C-c<" 'sgml-lt)
    (define-key sgml-mode-map "\C-ce" 'sgml-nbsp)
    (define-key sgml-mode-map "\C-cp" 'sgml-para)
    (define-key sgml-mode-map "\C-cl" 'sgml-literal)
    (define-key sgml-mode-map "\C-ck" 'sgml-kill-to-eoelement)
    (define-key sgml-mode-map "\C-cw" 'sgml-copy-element)
    (define-key sgml-mode-map [f2] 'sgml-fill-and-save)
)

;;; Make them available for sgml files
(add-hook 'sgml-mode-hook 'my-psgml-mode-hook)
;;; Make them available for xml files
(add-hook 'xml-mode-hook 'my-psgml-mode-hook)