Function: nxml-electric-slash

nxml-electric-slash is an interactive and byte-compiled function defined in nxml-mode.el.gz.

Signature

(nxml-electric-slash ARG)

Documentation

Insert a slash.

With a prefix ARG, do nothing other than insert the slash.

Otherwise, if nxml-slash-auto-complete-flag is non-nil, insert the rest of the end-tag or empty-element if the slash is potentially part of an end-tag or the close of an empty-element.

If the slash is part of an end-tag that is the first non-whitespace on the line, reindent the line.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/nxml/nxml-mode.el.gz
;;; Editing

(defun nxml-electric-slash (arg)
  "Insert a slash.

With a prefix ARG, do nothing other than insert the slash.

Otherwise, if `nxml-slash-auto-complete-flag' is non-nil, insert the
rest of the end-tag or empty-element if the slash is potentially part
of an end-tag or the close of an empty-element.

If the slash is part of an end-tag that is the first non-whitespace
on the line, reindent the line."
  (interactive "*P")
  (nxml-ensure-scan-up-to-date)
  (let* ((slash-pos (point))
	 (end-tag-p (and (eq (char-before slash-pos) ?<)
			 (not (nxml-get-inside slash-pos))))
	 (at-indentation (save-excursion
			   (back-to-indentation)
			   (eq (point) (1- slash-pos)))))
    (self-insert-command (prefix-numeric-value arg))
    (unless arg
      (if nxml-slash-auto-complete-flag
	  (if end-tag-p
	      (condition-case nil
		  (let ((start-tag-end
			 (nxml-scan-element-backward (1- slash-pos) t)))
		    (when start-tag-end
		      (insert (xmltok-start-tag-qname) ">")
		      ;; copy the indentation of the start-tag
		      (when (and at-indentation
				 (save-excursion
				   (goto-char xmltok-start)
				   (back-to-indentation)
				   (eq (point) xmltok-start)))
			(save-excursion
			  (indent-line-to (save-excursion
					    (goto-char xmltok-start)
					    (current-column)))))))
		(nxml-scan-error nil))
	    (when (and (eq (nxml-token-before) (point))
		       (eq xmltok-type 'partial-empty-element))
	      (insert ">"))))
      (when (and end-tag-p at-indentation)
        (nxml-indent-line)))))