unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to change 'comment-region' behaviour globally?
@ 2013-02-16  2:00 Thorsten Jolitz
  2013-02-16  3:26 ` Drew Adams
  0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2013-02-16  2:00 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

suppose I want to outcomment this function definition in an Elisp Buffer:

,----------------------
| (defun add-3-and-4 ()
|    (+ 3 4 ))
`----------------------

If I mark both lines (the whole defun) and call 'comment-region', I get
what I want: 

;; (defun add-3-and-4 ()  
;;    (+ 3 4 ))


but when I act on one line only, i.e. mark the first line and call
'comment-region', and then the second line, I get: 

;; (defun add-3-and-4 ()  
   ;; (+ 3 4 ))

This happens in Emacs Lisp mode, and in PicoLisp mode too. Is there a
way to change the behaviour of 'comment-region' globally such that, even
when applied one line after another, the 'comment-start' characters are
never indented, but always placed at the beginning of line?

With globally I mean that this works independent from the comment-style
definitions of the major-mode, and overrides the major-mode settings if
they are different. 

-- 
cheers,
Thorsten





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

* RE: How to change 'comment-region' behaviour globally?
  2013-02-16  2:00 How to change 'comment-region' behaviour globally? Thorsten Jolitz
@ 2013-02-16  3:26 ` Drew Adams
  2013-02-16 11:31   ` Thorsten Jolitz
  2013-02-16 12:14   ` Thorsten Jolitz
  0 siblings, 2 replies; 6+ messages in thread
From: Drew Adams @ 2013-02-16  3:26 UTC (permalink / raw)
  To: 'Thorsten Jolitz', help-gnu-emacs

> Is there a way to change the behaviour of 'comment-region'
> globally such that, even when applied one line after another,
> the 'comment-start' characters are
> never indented, but always placed at the beginning of line?
> 
> With globally I mean that this works independent from the 
> comment-style definitions of the major-mode, and overrides
> the major-mode settings if they are different. 

Customizing `comment-style' to `plain' doesn't help?

I guess it won't help if a given major mode declares that variable to be
buffer-local and sets its own value for it.  But it's not playing nice if the
major mode does that, IMO.  `comment-styles' is a user option.




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

* Re: How to change 'comment-region' behaviour globally?
  2013-02-16  3:26 ` Drew Adams
@ 2013-02-16 11:31   ` Thorsten Jolitz
  2013-02-16 12:14   ` Thorsten Jolitz
  1 sibling, 0 replies; 6+ messages in thread
From: Thorsten Jolitz @ 2013-02-16 11:31 UTC (permalink / raw)
  To: help-gnu-emacs

"Drew Adams" <drew.adams@oracle.com> writes:

>> Is there a way to change the behaviour of 'comment-region'
>> globally such that, even when applied one line after another,
>> the 'comment-start' characters are
>> never indented, but always placed at the beginning of line?
>> 
>> With globally I mean that this works independent from the 
>> comment-style definitions of the major-mode, and overrides
>> the major-mode settings if they are different. 
>
> Customizing `comment-style' to `plain' doesn't help?
>
> I guess it won't help if a given major mode declares that variable to be
> buffer-local and sets its own value for it.  But it's not playing nice if the
> major mode does that, IMO.  `comment-styles' is a user option.

But I could check for a buffer-local value of 'comment-style', read and
store it, set it temporarilly to 'plain', and restore the old value when
I'm done. 

Thanks for the tip - that helped. 

-- 
cheers,
Thorsten




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

* Re: How to change 'comment-region' behaviour globally?
  2013-02-16  3:26 ` Drew Adams
  2013-02-16 11:31   ` Thorsten Jolitz
@ 2013-02-16 12:14   ` Thorsten Jolitz
  2013-02-16 14:33     ` Stefan Monnier
  1 sibling, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2013-02-16 12:14 UTC (permalink / raw)
  To: help-gnu-emacs

"Drew Adams" <drew.adams@oracle.com> writes:

> Customizing `comment-style' to `plain' doesn't help?
>
> I guess it won't help if a given major mode declares that variable to be
> buffer-local and sets its own value for it.  But it's not playing nice if the
> major mode does that, IMO.  `comment-styles' is a user option.

One more question about the global vs buffer-local variable
'comment-style': 

if I want to temporarilly set it to another value in a program, do I
have to check first if its a global value or a buffer-local value that
is set for the buffer, or is this immaterial, i.e. whenever I call setq
on 'comment-style', it will apply to the version that is active in the
buffer?

In other words, can I simply call '(setq comment-style "plain") at the
beginning of the program, and then e.g. '(setq comment-style "indent")
at the end of the program, without worrying if 'comment-style' is global
or local for the buffer at hand?

-- 
cheers,
Thorsten




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

* Re: How to change 'comment-region' behaviour globally?
  2013-02-16 12:14   ` Thorsten Jolitz
@ 2013-02-16 14:33     ` Stefan Monnier
  2013-02-16 14:38       ` Thorsten Jolitz
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-02-16 14:33 UTC (permalink / raw)
  To: help-gnu-emacs

> if I want to temporarilly set it to another value in a program, do I
> have to check first if its a global value or a buffer-local value that
> is set for the buffer, or is this immaterial, i.e. whenever I call setq
> on 'comment-style', it will apply to the version that is active in the
> buffer?

You can just do

  (let ((comment-style 'plain))
    (comment-region ...))


-- Stefan




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

* Re: How to change 'comment-region' behaviour globally?
  2013-02-16 14:33     ` Stefan Monnier
@ 2013-02-16 14:38       ` Thorsten Jolitz
  0 siblings, 0 replies; 6+ messages in thread
From: Thorsten Jolitz @ 2013-02-16 14:38 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> if I want to temporarilly set it to another value in a program, do I
>> have to check first if its a global value or a buffer-local value that
>> is set for the buffer, or is this immaterial, i.e. whenever I call setq
>> on 'comment-style', it will apply to the version that is active in the
>> buffer?
>
> You can just do
>
>   (let ((comment-style 'plain))
>     (comment-region ...))

yes, much better than using 'setq'. Thanks for the tip. 

-- 
cheers,
Thorsten




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

end of thread, other threads:[~2013-02-16 14:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-16  2:00 How to change 'comment-region' behaviour globally? Thorsten Jolitz
2013-02-16  3:26 ` Drew Adams
2013-02-16 11:31   ` Thorsten Jolitz
2013-02-16 12:14   ` Thorsten Jolitz
2013-02-16 14:33     ` Stefan Monnier
2013-02-16 14:38       ` Thorsten Jolitz

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).