unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* LISP routines for commenting
@ 2008-08-08  8:36 Alex Gusarov
  2008-08-09  1:43 ` Joel J. Adamson 
       [not found] ` <mailman.16147.1218246548.18990.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Alex Gusarov @ 2008-08-08  8:36 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I want to implement some lisp functions for the following:
1. Insert comment - when mark some lines of code and using it, insert
ins-comments, like this:

before:

l = []
l.append(1)

then mark it and use ins-func, after:

# ins > <username>, <current date and time>
l = []
l.append(1)
# ins < <username>, <current date and time>

Please, help me with some general code, thanks!

--
Best regards, Alex Gusarov




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

* Re: LISP routines for commenting
  2008-08-08  8:36 LISP routines for commenting Alex Gusarov
@ 2008-08-09  1:43 ` Joel J. Adamson 
       [not found] ` <mailman.16147.1218246548.18990.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Joel J. Adamson  @ 2008-08-09  1:43 UTC (permalink / raw)
  To: Alex Gusarov; +Cc: help-gnu-emacs

>>>>> "Alex" == Alex Gusarov <alex.m.gusarov@gmail.com> writes:

    Alex> Hello,
    Alex> I want to implement some lisp functions for the following:
    Alex> 1. Insert comment - when mark some lines of code and using it, insert
    Alex> ins-comments, like this:

    Alex> before:

    Alex> l = []
    Alex> l.append(1)

    Alex> then mark it and use ins-func, after:

    Alex> # ins > <username>, <current date and time>
    Alex> l = []
    Alex> l.append(1)
    Alex> # ins < <username>, <current date and time>

If I understand correctly, you want to implement some lisp to comment
your Python code?  Have you tried Python mode?  There is a commonly used
key (M-;) that comments lines and regions --- look up the function
"comment-region."  In each programming language mode, this function
inserts the proper comments for the language you are using (e.g., ";"
for lisp and "#" for Python, Perl, et al).

Please be specific if you want something else.

Joel

-- 
Joel J. Adamson
(303) 880-3109
Public key: http://pgp.mit.edu
http://www.unc.edu/~adamsonj
http://trashbird1240.blogspot.com




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

* Re: LISP routines for commenting
       [not found] ` <mailman.16147.1218246548.18990.help-gnu-emacs@gnu.org>
@ 2008-08-09 14:43   ` weber
  2008-08-09 16:33     ` Thierry Volpiatto
  0 siblings, 1 reply; 11+ messages in thread
From: weber @ 2008-08-09 14:43 UTC (permalink / raw)
  To: help-gnu-emacs

On Aug 8, 10:43 pm, "Joel J. Adamson " <adams...@email.unc.edu> wrote:
> >>>>> "Alex" == Alex Gusarov <alex.m.gusa...@gmail.com> writes:
>
>     Alex> Hello,
>     Alex> I want to implement some lisp functions for the following:
>     Alex> 1. Insert comment - when mark some lines of code and using it, insert
>     Alex> ins-comments, like this:
>
>     Alex> before:
>
>     Alex> l = []
>     Alex> l.append(1)
>
>     Alex> then mark it and use ins-func, after:
>
>     Alex> # ins > <username>, <current date and time>
>     Alex> l = []
>     Alex> l.append(1)
>     Alex> # ins < <username>, <current date and time>
>
> If I understand correctly, you want to implement some lisp to comment
> your Python code?  Have you tried Python mode?  There is a commonly used
> key (M-;) that comments lines and regions --- look up the function
> "comment-region."  In each programming language mode, this function
> inserts the proper comments for the language you are using (e.g., ";"
> for lisp and "#" for Python, Perl, et al).
>
> Please be specific if you want something else.
>
> Joel
>
> --
> Joel J. Adamson
> (303) 880-3109
> Public key:http://pgp.mit.eduhttp://www.unc.edu/~adamsonjhttp://trashbird1240.blogspot.com

Alex,
is this what you want?

(defun ins-comment (beg end)
  (interactive "r")
  (let ((str (concat user-login-name ", " (format-time-string "%d/%m/
%y %Hh%Mmin"))))
	(goto-char end)
	(insert "# ins < " str)
	(goto-char beg)
	(insert "# ins > " str "\n")))

HTH,
hugo


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

* Re: LISP routines for commenting
  2008-08-09 14:43   ` weber
@ 2008-08-09 16:33     ` Thierry Volpiatto
  2008-08-09 16:42       ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 11+ messages in thread
From: Thierry Volpiatto @ 2008-08-09 16:33 UTC (permalink / raw)
  To: weber; +Cc: help-gnu-emacs

Python-mode provide a command for indenting that is bind to:

C-c # ==> comment
C-u C-c # ==> uncomment
The command is: `py-comment-region'

It is better to comment with that instead of the usual M-;
because it don't affect indentation after a block of commented code.

I don't know if python.el provide the same.

weber <hugows@gmail.com> writes:

> On Aug 8, 10:43 pm, "Joel J. Adamson " <adams...@email.unc.edu> wrote:
>> >>>>> "Alex" == Alex Gusarov <alex.m.gusa...@gmail.com> writes:
>>
>>     Alex> Hello,
>>     Alex> I want to implement some lisp functions for the following:
>>     Alex> 1. Insert comment - when mark some lines of code and using it, insert
>>     Alex> ins-comments, like this:
>>
>>     Alex> before:
>>
>>     Alex> l = []
>>     Alex> l.append(1)
>>
>>     Alex> then mark it and use ins-func, after:
>>
>>     Alex> # ins > <username>, <current date and time>
>>     Alex> l = []
>>     Alex> l.append(1)
>>     Alex> # ins < <username>, <current date and time>
>>
>> If I understand correctly, you want to implement some lisp to comment
>> your Python code?  Have you tried Python mode?  There is a commonly used
>> key (M-;) that comments lines and regions --- look up the function
>> "comment-region."  In each programming language mode, this function
>> inserts the proper comments for the language you are using (e.g., ";"
>> for lisp and "#" for Python, Perl, et al).
>>
>> Please be specific if you want something else.
>>
>> Joel
>>
>> --
>> Joel J. Adamson
>> (303) 880-3109
>> Public key:http://pgp.mit.eduhttp://www.unc.edu/~adamsonjhttp://trashbird1240.blogspot.com
>
> Alex,
> is this what you want?
>
> (defun ins-comment (beg end)
>   (interactive "r")
>   (let ((str (concat user-login-name ", " (format-time-string "%d/%m/
> %y %Hh%Mmin"))))
> 	(goto-char end)
> 	(insert "# ins < " str)
> 	(goto-char beg)
> 	(insert "# ins > " str "\n")))
>
> HTH,
> hugo
>

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France




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

* Re: LISP routines for commenting
  2008-08-09 16:33     ` Thierry Volpiatto
@ 2008-08-09 16:42       ` Lennart Borgman (gmail)
  2008-08-09 17:04         ` Thierry Volpiatto
  0 siblings, 1 reply; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 16:42 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: help-gnu-emacs, weber

Thierry Volpiatto wrote:
> Python-mode provide a command for indenting that is bind to:
> 
> C-c # ==> comment
> C-u C-c # ==> uncomment
> The command is: `py-comment-region'
> 
> It is better to comment with that instead of the usual M-;
> because it don't affect indentation after a block of commented code.


Do you mean that this is a bug in the support for M-; in phyton-mode? Or 
is it a bug in M-;




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

* Re: LISP routines for commenting
  2008-08-09 16:42       ` Lennart Borgman (gmail)
@ 2008-08-09 17:04         ` Thierry Volpiatto
  2008-08-09 17:11           ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 11+ messages in thread
From: Thierry Volpiatto @ 2008-08-09 17:04 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: help-gnu-emacs, weber

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:

> Thierry Volpiatto wrote:
>> Python-mode provide a command for indenting that is bind to:
>>
>> C-c # ==> comment
>> C-u C-c # ==> uncomment
>> The command is: `py-comment-region'
>>
>> It is better to comment with that instead of the usual M-;
>> because it don't affect indentation after a block of commented code.
>
>
> Do you mean that this is a bug in the support for M-; in phyton-mode?
> Or is it a bug in M-;
>
I don't think it's a bug, it's just better to comment with the proper
function in python, especially if there is complex level of indentation
(loop followed with other loop and if if if...etc).
However M-; work in most cases.
So if it's a bug, it come from python-mode, because M-; normally have to
be used with python.el (is it working with python.el ?) because it is
the normal mode to use in emacs with python even if IMHO python-mode is
much better.

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France




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

* Re: LISP routines for commenting
  2008-08-09 17:04         ` Thierry Volpiatto
@ 2008-08-09 17:11           ` Lennart Borgman (gmail)
  2008-08-09 17:19             ` Thierry Volpiatto
  0 siblings, 1 reply; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 17:11 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: help-gnu-emacs, weber

Thierry Volpiatto wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> 
>> Thierry Volpiatto wrote:
>>> Python-mode provide a command for indenting that is bind to:
>>>
>>> C-c # ==> comment
>>> C-u C-c # ==> uncomment
>>> The command is: `py-comment-region'
>>>
>>> It is better to comment with that instead of the usual M-;
>>> because it don't affect indentation after a block of commented code.
>>
>> Do you mean that this is a bug in the support for M-; in phyton-mode?
>> Or is it a bug in M-;
>>
> I don't think it's a bug, it's just better to comment with the proper
> function in python, especially if there is complex level of indentation
> (loop followed with other loop and if if if...etc).

But isn't there a bug somewhere if M-; does not do the right thing?

> However M-; work in most cases.
> So if it's a bug, it come from python-mode, because M-; normally have to
> be used with python.el (is it working with python.el ?) because it is
> the normal mode to use in emacs with python even if IMHO python-mode is
> much better.
> 




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

* Re: LISP routines for commenting
  2008-08-09 17:11           ` Lennart Borgman (gmail)
@ 2008-08-09 17:19             ` Thierry Volpiatto
  2008-08-09 17:38               ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 11+ messages in thread
From: Thierry Volpiatto @ 2008-08-09 17:19 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: help-gnu-emacs, weber

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:

> Thierry Volpiatto wrote:
>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>
>>> Thierry Volpiatto wrote:
>>>> Python-mode provide a command for indenting that is bind to:
>>>>
>>>> C-c # ==> comment
>>>> C-u C-c # ==> uncomment
>>>> The command is: `py-comment-region'
>>>>
>>>> It is better to comment with that instead of the usual M-;
>>>> because it don't affect indentation after a block of commented code.
>>>
>>> Do you mean that this is a bug in the support for M-; in phyton-mode?
>>> Or is it a bug in M-;
>>>
>> I don't think it's a bug, it's just better to comment with the proper
>> function in python, especially if there is complex level of indentation
>> (loop followed with other loop and if if if...etc).
>
> But isn't there a bug somewhere if M-; does not do the right thing?

Well, if emacs is meant to use python with python.el and it is working
fine with it, it is not a bug, but if M-; don't work properly with
python.el, yes, it is a bug!
I don't know how emacs is working actually with python.el because i
don't use it. 

>> However M-; work in most cases.
>> So if it's a bug, it come from python-mode, because M-; normally have to
>> be used with python.el (is it working with python.el ?) because it is
>> the normal mode to use in emacs with python even if IMHO python-mode is
>> much better.
>>
>

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France




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

* Re: LISP routines for commenting
  2008-08-09 17:19             ` Thierry Volpiatto
@ 2008-08-09 17:38               ` Lennart Borgman (gmail)
  2008-08-09 18:29                 ` Thierry Volpiatto
  0 siblings, 1 reply; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 17:38 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: help-gnu-emacs, weber

Thierry Volpiatto wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> 
>> Thierry Volpiatto wrote:
>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>
>>>> Thierry Volpiatto wrote:
>>>>> Python-mode provide a command for indenting that is bind to:
>>>>>
>>>>> C-c # ==> comment
>>>>> C-u C-c # ==> uncomment
>>>>> The command is: `py-comment-region'
>>>>>
>>>>> It is better to comment with that instead of the usual M-;
>>>>> because it don't affect indentation after a block of commented code.
>>>> Do you mean that this is a bug in the support for M-; in phyton-mode?
>>>> Or is it a bug in M-;
>>>>
>>> I don't think it's a bug, it's just better to comment with the proper
>>> function in python, especially if there is complex level of indentation
>>> (loop followed with other loop and if if if...etc).
>> But isn't there a bug somewhere if M-; does not do the right thing?
> 
> Well, if emacs is meant to use python with python.el and it is working
> fine with it, it is not a bug, but if M-; don't work properly with
> python.el, yes, it is a bug!


Don't you think that all major modes should support M-;? There are easy 
ways to do that. The doc strings says

(comment-dwim arg)

Call the comment command you want (Do What I Mean).
If the region is active and `transient-mark-mode' is on, call
   `comment-region' (unless it only consists of comments, in which
   case it calls `uncomment-region').
Else, if the current line is empty, call `comment-insert-comment-function'
if it is defined, otherwise insert a comment and indent it.
Else if a prefix arg is specified, call `comment-kill'.
Else, call `comment-indent'.
You can configure `comment-style' to change the way regions are commented.




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

* Re: LISP routines for commenting
  2008-08-09 17:38               ` Lennart Borgman (gmail)
@ 2008-08-09 18:29                 ` Thierry Volpiatto
  2008-08-14  8:07                   ` Alex Gusarov
  0 siblings, 1 reply; 11+ messages in thread
From: Thierry Volpiatto @ 2008-08-09 18:29 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: help-gnu-emacs, weber

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:

> Thierry Volpiatto wrote:
>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>
>>> Thierry Volpiatto wrote:
>>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>>
>>>>> Thierry Volpiatto wrote:
>>>>>> Python-mode provide a command for indenting that is bind to:
>>>>>>
>>>>>> C-c # ==> comment
>>>>>> C-u C-c # ==> uncomment
>>>>>> The command is: `py-comment-region'
>>>>>>
>>>>>> It is better to comment with that instead of the usual M-;
>>>>>> because it don't affect indentation after a block of commented code.
>>>>> Do you mean that this is a bug in the support for M-; in phyton-mode?
>>>>> Or is it a bug in M-;
>>>>>
>>>> I don't think it's a bug, it's just better to comment with the proper
>>>> function in python, especially if there is complex level of indentation
>>>> (loop followed with other loop and if if if...etc).
>>> But isn't there a bug somewhere if M-; does not do the right thing?
>>
>> Well, if emacs is meant to use python with python.el and it is working
>> fine with it, it is not a bug, but if M-; don't work properly with
>> python.el, yes, it is a bug!
>
>
> Don't you think that all major modes should support M-;? There are
> easy ways to do that. The doc strings says
>
> (comment-dwim arg)
>
> Call the comment command you want (Do What I Mean).
> If the region is active and `transient-mark-mode' is on, call
>   `comment-region' (unless it only consists of comments, in which
>   case it calls `uncomment-region').
> Else, if the current line is empty, call `comment-insert-comment-function'
> if it is defined, otherwise insert a comment and indent it.
> Else if a prefix arg is specified, call `comment-kill'.
> Else, call `comment-indent'.
> You can configure `comment-style' to change the way regions are commented.
>
Yes, i think that is enabled and working (indenting a comment block).
That is not working always correctly is indenting code after a block of
comment if this comment is commented with M-;. May be it's only because
M-; comment with only one # with no space in front.
Sure it can be corrected, i never ask myself about that as i use C-c #
in python.
-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France




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

* Re: LISP routines for commenting
  2008-08-09 18:29                 ` Thierry Volpiatto
@ 2008-08-14  8:07                   ` Alex Gusarov
  0 siblings, 0 replies; 11+ messages in thread
From: Alex Gusarov @ 2008-08-14  8:07 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: help-gnu-emacs, weber

Thanks to everebody, I just returned from buisness trip and read your answers.

weber - almost what I wanted, thank you for example, I will modify
your example for my needs.

On Sun, Aug 10, 2008 at 1:29 AM, Thierry Volpiatto
<thierry.volpiatto@gmail.com> wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>
>> Thierry Volpiatto wrote:
>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>
>>>> Thierry Volpiatto wrote:
>>>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>>>
>>>>>> Thierry Volpiatto wrote:
>>>>>>> Python-mode provide a command for indenting that is bind to:
>>>>>>>
>>>>>>> C-c # ==> comment
>>>>>>> C-u C-c # ==> uncomment
>>>>>>> The command is: `py-comment-region'
>>>>>>>
>>>>>>> It is better to comment with that instead of the usual M-;
>>>>>>> because it don't affect indentation after a block of commented code.
>>>>>> Do you mean that this is a bug in the support for M-; in phyton-mode?
>>>>>> Or is it a bug in M-;
>>>>>>
>>>>> I don't think it's a bug, it's just better to comment with the proper
>>>>> function in python, especially if there is complex level of indentation
>>>>> (loop followed with other loop and if if if...etc).
>>>> But isn't there a bug somewhere if M-; does not do the right thing?
>>>
>>> Well, if emacs is meant to use python with python.el and it is working
>>> fine with it, it is not a bug, but if M-; don't work properly with
>>> python.el, yes, it is a bug!
>>
>>
>> Don't you think that all major modes should support M-;? There are
>> easy ways to do that. The doc strings says
>>
>> (comment-dwim arg)
>>
>> Call the comment command you want (Do What I Mean).
>> If the region is active and `transient-mark-mode' is on, call
>>   `comment-region' (unless it only consists of comments, in which
>>   case it calls `uncomment-region').
>> Else, if the current line is empty, call `comment-insert-comment-function'
>> if it is defined, otherwise insert a comment and indent it.
>> Else if a prefix arg is specified, call `comment-kill'.
>> Else, call `comment-indent'.
>> You can configure `comment-style' to change the way regions are commented.
>>
> Yes, i think that is enabled and working (indenting a comment block).
> That is not working always correctly is indenting code after a block of
> comment if this comment is commented with M-;. May be it's only because
> M-; comment with only one # with no space in front.
> Sure it can be corrected, i never ask myself about that as i use C-c #
> in python.
> --
> A + Thierry Volpiatto
> Location: Saint-Cyr-Sur-Mer - France
>
>
>



-- 
--
Best regards, Alex Gusarov




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

end of thread, other threads:[~2008-08-14  8:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-08  8:36 LISP routines for commenting Alex Gusarov
2008-08-09  1:43 ` Joel J. Adamson 
     [not found] ` <mailman.16147.1218246548.18990.help-gnu-emacs@gnu.org>
2008-08-09 14:43   ` weber
2008-08-09 16:33     ` Thierry Volpiatto
2008-08-09 16:42       ` Lennart Borgman (gmail)
2008-08-09 17:04         ` Thierry Volpiatto
2008-08-09 17:11           ` Lennart Borgman (gmail)
2008-08-09 17:19             ` Thierry Volpiatto
2008-08-09 17:38               ` Lennart Borgman (gmail)
2008-08-09 18:29                 ` Thierry Volpiatto
2008-08-14  8:07                   ` Alex Gusarov

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