* override comment-or-uncomment-region gives an error
@ 2013-05-30 2:05 ishi soichi
2013-05-30 2:47 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: ishi soichi @ 2013-05-30 2:05 UTC (permalink / raw)
To: help-gnu-emacs
I am trying to override the existing function,
comment-or-uncommnent-region like
(defun comment-or-uncomment-region ()
(interactive)
(cond ((equal major-mode 'web-mode)
(web-mode-comment-or-uncomment))
(t
(comment-or-uncomment-region))))
When using web-mode, the commenting function is different. So I need
something like this.
It works for web-mode case, but it raises an error for any other modes,
cond: Lisp nesting exceeds `max-lisp-eval-depth'
Does anyone see why?
soichi
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: override comment-or-uncomment-region gives an error
2013-05-30 2:05 override comment-or-uncomment-region gives an error ishi soichi
@ 2013-05-30 2:47 ` Drew Adams
2013-05-30 3:21 ` ishi soichi
2013-05-30 5:54 ` Andreas Röhler
2013-05-30 14:50 ` Stefan Monnier
2 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2013-05-30 2:47 UTC (permalink / raw)
To: ishi soichi, help-gnu-emacs
> I am trying to override the existing function,
> comment-or-uncommnent-region like
>
> (defun comment-or-uncomment-region ()
> (interactive)
> (cond ((equal major-mode 'web-mode)
> (web-mode-comment-or-uncomment))
> (t
> (comment-or-uncomment-region))))
>
> cond: Lisp nesting exceeds `max-lisp-eval-depth'
You have (c-o-u-r) calling (c-o-u-r) calling (c-o-u-r)...
See the Elisp manual about using defadvice.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: override comment-or-uncomment-region gives an error
2013-05-30 2:47 ` Drew Adams
@ 2013-05-30 3:21 ` ishi soichi
0 siblings, 0 replies; 6+ messages in thread
From: ishi soichi @ 2013-05-30 3:21 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
thanks. I will read the documentation.
2013/5/30 Drew Adams <drew.adams@oracle.com>
> > I am trying to override the existing function,
> > comment-or-uncommnent-region like
> >
> > (defun comment-or-uncomment-region ()
> > (interactive)
> > (cond ((equal major-mode 'web-mode)
> > (web-mode-comment-or-uncomment))
> > (t
> > (comment-or-uncomment-region))))
> >
> > cond: Lisp nesting exceeds `max-lisp-eval-depth'
>
> You have (c-o-u-r) calling (c-o-u-r) calling (c-o-u-r)...
>
> See the Elisp manual about using defadvice.
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: override comment-or-uncomment-region gives an error
2013-05-30 2:05 override comment-or-uncomment-region gives an error ishi soichi
2013-05-30 2:47 ` Drew Adams
@ 2013-05-30 5:54 ` Andreas Röhler
2013-05-30 14:50 ` Stefan Monnier
2 siblings, 0 replies; 6+ messages in thread
From: Andreas Röhler @ 2013-05-30 5:54 UTC (permalink / raw)
To: help-gnu-emacs
Am 30.05.2013 04:05, schrieb ishi soichi:
> I am trying to override the existing function,
> comment-or-uncommnent-region like
>
> (defun comment-or-uncomment-region ()
> (interactive)
> (cond ((equal major-mode 'web-mode)
> (web-mode-comment-or-uncomment))
> (t
> (comment-or-uncomment-region))))
>
> When using web-mode, the commenting function is different. So I need
> something like this.
>
> It works for web-mode case, but it raises an error for any other modes,
>
> cond: Lisp nesting exceeds `max-lisp-eval-depth'
>
> Does anyone see why?
>
> soichi
>
Defadvice is an an option. Personally, I'd redefine
comment-or-uncomment-region like that
(defun comment-or-uncomment-region (beg end &optional arg)
"Call `comment-region', unless the region only consists of comments,
in which case call `uncomment-region'. If a prefix arg is given, it
is passed on to the respective function."
(interactive "*r\nP")
(comment-normalize-vars)
(cond ((equal major-mode 'web-mode)
MY_NEEDED_FUNCALL
(t
(funcall (if (comment-only-p beg end)
'uncomment-region 'comment-region)
beg end arg))
;;;;;;
Redefining seems preferable WRT debugging/edebug
Andreas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: override comment-or-uncomment-region gives an error
2013-05-30 2:05 override comment-or-uncomment-region gives an error ishi soichi
2013-05-30 2:47 ` Drew Adams
2013-05-30 5:54 ` Andreas Röhler
@ 2013-05-30 14:50 ` Stefan Monnier
2013-06-04 3:04 ` ishi soichi
2 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-05-30 14:50 UTC (permalink / raw)
To: help-gnu-emacs
> When using web-mode, the commenting function is different. So I need
Why not just set `comment-region-function' buffer-locally to some
function of your choice?
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: override comment-or-uncomment-region gives an error
2013-05-30 14:50 ` Stefan Monnier
@ 2013-06-04 3:04 ` ishi soichi
0 siblings, 0 replies; 6+ messages in thread
From: ishi soichi @ 2013-06-04 3:04 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
thanks. all comments seem useful. I will try one by one.
soichi
2013/5/30 Stefan Monnier <monnier@iro.umontreal.ca>
> > When using web-mode, the commenting function is different. So I need
>
> Why not just set `comment-region-function' buffer-locally to some
> function of your choice?
>
>
> Stefan
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-06-04 3:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-30 2:05 override comment-or-uncomment-region gives an error ishi soichi
2013-05-30 2:47 ` Drew Adams
2013-05-30 3:21 ` ishi soichi
2013-05-30 5:54 ` Andreas Röhler
2013-05-30 14:50 ` Stefan Monnier
2013-06-04 3:04 ` ishi soichi
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).