unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* POC comment/uncomment region in nxml-mode
@ 2014-07-22 23:22 Tim Chambers
  2014-07-23  6:36 ` Andreas Röhler
  2014-08-18 15:31 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Tim Chambers @ 2014-07-22 23:22 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: POC comment/uncomment region in nxml-mode
  2014-07-22 23:22 POC comment/uncomment region in nxml-mode Tim Chambers
@ 2014-07-23  6:36 ` Andreas Röhler
  2014-08-18 15:31 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Röhler @ 2014-07-23  6:36 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: POC comment/uncomment region in nxml-mode
  2014-07-22 23:22 POC comment/uncomment region in nxml-mode Tim Chambers
  2014-07-23  6:36 ` Andreas Röhler
@ 2014-08-18 15:31 ` Stefan Monnier
  2014-08-19 15:12   ` Tim Chambers
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-08-18 15:31 UTC (permalink / raw)
  To: Tim Chambers; +Cc: emacs-devel

> 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?

IIUC, this is indeed needed, thank you.
A few comments, tho:
- It should not create new commands.  Instead it should set
  (un)comment-region-function buffer-locally.
- It should use the default (un)comment-region functions internally
  (e.g. first quote all "--", then call the default comment-region).
- I don't think you need to turn "--" into "\-\-".  Turning them into
  "-\-" should be sufficient.
- comment-region followed by an uncomment-region should also work on
  a region which already contains comments with a quoted "--"
  (i.e. with a "-\-").  For that I think you also need to quote "-\-" to
  "-\\-" and to unquote "-\\-" to "-\-" (and same for any number of
  backslashed between dashes).

Would you like to try to submit  revised patch?


        Stefan



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: POC comment/uncomment region in nxml-mode
  2014-08-18 15:31 ` Stefan Monnier
@ 2014-08-19 15:12   ` Tim Chambers
  2014-08-20 14:13     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Chambers @ 2014-08-19 15:12 UTC (permalink / raw)
  To: Stefan Monnier, andreas.roehler; +Cc: emacs-devel@gnu.org

> IIUC, this is indeed needed, thank you.
> A few comments, tho:...

Thank you for the feedback, Stefan! Exactly what I was looking for. I hope
we can meet f2f someday so I can buy you a beverage of your choice. [1]

> Would you like to try to submit  revised patch?

Yes, I would like to submit a patch. I need to make time to study [2]
and [3] first. I also need to review [4]. So thank you for inspiring
me! If [2] and [3] need any touch-up, this week would be the time. I'm
going to get started this weekend.

> From: =?UTF-8?B?QW5kcmVhcyBSw7ZobGVy?= <andreas.roehler@online.de>
> Message-ID: <53CF57D3.1050605@online.de>
> Date: Wed, 23 Jul 2014 08:36:03 +0200

> Why not just M-x comment-dwim?

Andreas, Stefan acknowledged the problem I was trying to correct: '--'
in XML comments should be escaped. Does that make sense to you?

All, the other innovation I want to make is to comment regions in XML
with a single pair of <!-- --> instead of commenting every line. Can
anyone point me to the history of why line-by-line XML comments are
the norm in emacs, even though XML supports block comments?

Also, have any insights to share re. relationship between
un/comment-region and comment-dwim? These specifics are all new to me,
but I'm a quick study who is motivated to make emacs better.

– tbc

[1] details of this offer being the same as those specified at
www.emacswiki.org/emacs-en/tbc
[2] www.gnu.org/software/emacs/CONTRIBUTE
[3] www.gnu.org/software/emacs/manual/html_node/emacs/Sending-Patches.html
[4]
lists.gnu.org/archive/cgi-bin/namazu.cgi?query=nxml&submit=Search%21&idxname=bug-gnu-emacs



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: POC comment/uncomment region in nxml-mode
  2014-08-19 15:12   ` Tim Chambers
@ 2014-08-20 14:13     ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2014-08-20 14:13 UTC (permalink / raw)
  To: Tim Chambers; +Cc: tbc, andreas.roehler, emacs-devel@gnu.org

> All, the other innovation I want to make is to comment regions in XML
> with a single pair of <!-- --> instead of commenting every line.  Can
> anyone point me to the history of why line-by-line XML comments are
> the norm in Emacs, even though XML supports block comments?

That's just the default `comment-style', globally.
You probably want to configure it to something else globally as well
(assuming you don't like line-by-line commenting with /*...*/ in
C either, for example).

> Also, have any insights to share re. relationship between
> un/comment-region and comment-dwim? These specifics are all new to me,
> but I'm a quick study who is motivated to make emacs better.

comment-dwim is just a wrapper that calls different comment operations
(e.g. comment-region, comment-kill, ...) depending on "context".


        Stefan



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-20 14:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22 23:22 POC comment/uncomment region in nxml-mode Tim Chambers
2014-07-23  6:36 ` Andreas Röhler
2014-08-18 15:31 ` Stefan Monnier
2014-08-19 15:12   ` Tim Chambers
2014-08-20 14:13     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).