emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

POC comment/uncomment region in nxml-mode


From: Tim Chambers
Subject: POC comment/uncomment region in nxml-mode
Date: Tue, 22 Jul 2014 17:22:23 -0600

Here's a POC for interactively commenting/uncommenting a region in
nxml-mode. I guess if I wanted to submit this as an enhancement to
nxml-mode I'd have to properly integrate the functions into nXML mode.
Looking for motivation. Anyone interest in pursuing this?

(defun my-nxml-comment-region ()
  "comment a block if in nXML mode; else call comment-region"
  (interactive)
  ;; KLUDGE: should bind key in buffer, but I'm lazy
  (cond ((string-equal mode-name "nXML")
(save-excursion
  (narrow-to-region (point) (mark))
  (goto-point-min)
  (save-excursion (replace-string "--" "\\-\\-"))
  (insert "<!--\n")
  (goto-point-max)
  (insert "-->\n")
  (widen)))
(t (comment-region (point) (mark)))))

(defun my-nxml-uncomment-region ()
  "uncomment a block if in nXML mode; else call uncomment-region
assumes it was commented by my-nxml-comment-region"
  (interactive)
  ;; KLUDGE: should bind key in buffer, but I'm lazy
  (cond ((string-equal mode-name "nXML")
(save-excursion
  (search-backward "<!--\n")
  (delete-char 5)
  (let ((start (point)) end)
    (search-forward "-->\n")
    (delete-char -4)
    (setq end (point))
    (save-excursion (replace-string "\\-\\-" "--" nil start end)))))
(t (uncomment-region (point) (mark)))))

www.emacswiki.org/emacs/NxmlMode#toc13

– Tim Chambers 1E4AF729D5CEFFD0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]