emacs-devel
[Top][All Lists]
Advanced

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

Re: POC comment/uncomment region in nxml-mode


From: Andreas Röhler
Subject: Re: POC comment/uncomment region in nxml-mode
Date: Wed, 23 Jul 2014 08:36:03 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.6.0

On 23.07.2014 01:22, Tim Chambers wrote:
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



Why not just M-x comment-dwim?

Andreas



reply via email to

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