Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commenting function. #1790

Closed
wants to merge 3 commits into from
Closed

Commenting function. #1790

wants to merge 3 commits into from

Conversation

ak3n
Copy link

@ak3n ak3n commented May 30, 2012

No description provided.

@Carreau
Copy link
Member

Carreau commented May 30, 2012

Hi, Thanks for the Pull Request !

Usually, we try not to directly modify codemirror.js as it is a lib that we upgrade from time to time and that is really customisable. Could you try to make the patch as a codemirror extension for commenting ?
You should find a demo here.
You can also try to have your changes incorporated upstream.

Also, usually, we prefere to have different fix in different PR, it allows us to merge one fix even if we don't agree (yet) on the implementation of another one.

pinging @ellisonbg as he should be consulted for the notebook.

@@ -95,6 +95,10 @@ var IPython = (function (IPython) {
$(this).dialog('close');
}
}
}).keyup(function(e){
if( e.keyCode == 13 ){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document what this does in a comment. Also rather than using hard coded number like 13 can you use the constants in IPython.utils.js? Actually I think those haven't been merged yet, but will be soon - so maybe let's wait on merging this until that other PR (#1711) is merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same reflex, about IPython.utils.js , i think we should merged it to have feedback as fast as possible.

@ellisonbg
Copy link
Member

I agree with @Carreau that we should not directly make changes to CodeMirror in our code base. Can you submit this upstream to CodeMirror and then we can update from them?

@ak3n
Copy link
Author

ak3n commented May 30, 2012

Hi. Okay, i will open another one when will be ready or reopen this.

@ak3n ak3n closed this May 30, 2012
@ak3n
Copy link
Author

ak3n commented May 30, 2012

@Carreau What if i will use codecell.js for comment/uncomment function?

@ellisonbg
Copy link
Member

I am fine if you want to add the commenting feature to code cell.

On Wed, May 30, 2012 at 10:49 AM, ak3n
reply@reply.github.com
wrote:

@Carreau What if i will use codecell.js for comment/uncomment function?


Reply to this email directly or view it on GitHub:
#1790 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@Carreau
Copy link
Member

Carreau commented May 30, 2012

I'm also fine if the commenting code is in codecell.

@ak3n ak3n reopened this May 30, 2012
@ak3n
Copy link
Author

ak3n commented May 30, 2012

So, i will wait for #1711.

@ellisonbg
Copy link
Member

OK #1711 is in. Can you use the keycodes in IPython.utils.js?

@@ -153,6 +153,16 @@ var IPython = (function (IPython) {
} else {
return false;
};
} else if (event.keyCode === 191 && event.ctrlKey && event.type == 'keydown') {
// if Ctrl+/ is pressed then comment/uncomment selected lines.
for (i = editor.getCursor(true).line;i < editor.getCursor(false).line + 1; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try to use this code I get an error that i is not defined. We need a var i somewhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay now?

@Carreau
Copy link
Member

Carreau commented Jun 1, 2012

I'll just need to try it on a non english keyboard (slash is accessed by pressing SHIFT on french for example), and then the logic might fail.

Otherwise look ok.

@Carreau
Copy link
Member

Carreau commented Jun 1, 2012

It seem to don't care wether shift is pressed or not, so the shortcut for english keyboard is both (C-/ and C-Shift-?).
We could look on how event.which is across browser/os/locals, this should allow us to differenciate the char (/) from the key ( here [?``/]).

Also, you can't comment lines if you already have comments ...

# comment line
code line
# comment line
code line

toggle with

 comment line
#code line
 comment line
#code line

I would go for a logic :

  • if at least one line does not start with a # , then comment all
  • otherwise uncomment.

What do you think ?

Also, try not to "merge" upstream/master, otherwise the history get messy. If it don't apply cleanly, we prefere a rebase, don't hesitate to ask for help if you need.

Thanks.

Pinging @ellisonbg to have his thought on that.

@ellisonbg
Copy link
Member

I agree that when some lines are commented and others are not and the user attempts to comment/uncomment the section, you should look at what is done on the first line. If it is uncommented, comment the block and vice-versa.

I also notice that the selection logic is wonky. When I use Shift and arrow keys to select a block of text and then comment that block, The line after the block is also affected. I think the selection logic is pulling the trailing \n and it should be discarded before commenting.

@ak3n ak3n closed this Jun 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants