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

Quotes and colons autocompletion #872

Closed
spyder-bot opened this issue Feb 17, 2015 · 83 comments
Closed

Quotes and colons autocompletion #872

spyder-bot opened this issue Feb 17, 2015 · 83 comments

Comments

@spyder-bot
Copy link
Collaborator

From nunoport...@gmail.com on 2011-12-07T06:58:36Z

Hi,

How can i edit Spyder autocomplete feauture? I can't seem to find in preferences a way to do this...

thanks

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=872

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-07T09:03:09Z

What do you mean exactly by "edit"? Please give us an example

You can change how autocompletion works in:

  1. Tools > Preferences > Editor > Code Introspection/Analysis (for the Editor)
  2. Tools > Preferences > Console > Introspection (for the Console)

Summary: Autocomplete edition
Labels: Cat-CodeCompletion

@spyder-bot
Copy link
Collaborator Author

From nunoport...@gmail.com on 2011-12-07T09:28:22Z

In preferences you just activate or deactivate autocompletion.

This are some examples of what i would like to add

Auto complete single quotation marks.

Putting a colon after parenthesis when defining a function.

Putting a colon in front of each if...else statements (don't know if this is doable or pratical).

Autoindent (at least on my spyder is not working don't know if this is already implemented...)

I'm used to that so i think that would be a plus...

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-07T09:40:03Z

Ok, I understand you now. The problem is these things have to be added to the source code. I don't think there is a way for users to add them.

What do you mean by 'Auto complete single quotation marks'? Something like: if you write ' you want to get ''?

Autoindentation can be turned on/off in Tools > Preferences > Editor > Advanced Settings. To make it work you have to write colons at the end of def's, if's, etc, though.

Summary: Code completion enhancements
Labels: -Type-Defect Type-Enhancement

@spyder-bot
Copy link
Collaborator Author

From nunoport...@gmail.com on 2011-12-07T09:57:11Z

In pydev for eclipse, when you put a single quotation mark it automatically adds the other one and the cursor stays between them for typing whatever you want...

if colons were automatically placed after if or def's, indentation should work as it normally does... i guess it would save some time but i can't argue with you because you probably know more (a lot more) of python than i do! :)

@spyder-bot
Copy link
Collaborator Author

From techtonik@gmail.com on 2011-12-08T03:45:40Z

To me it is completely normal to add autocompletion enhancements to the source code. The difficulty is that the process is not documented. =) Carlos, can you provide an entrypoint for people who want to improve this part of Spyder to look at?

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-26T10:12:35Z

Summary: Several edition enhancements
Labels: -Cat-CodeCompletion Cat-Editor

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-29T16:40:59Z

Pierre, I added the possibility to automatically insert colons after an Enter keypress. I also added a config option so the user can decide if he/she wants to turn on/off this functionality. Should I update the UserConfig version because of this change, like you did f.ex in revision 7ef1137a0c95 ?

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2011-12-30T05:07:16Z

We need to change the configuration file version number only when changing the default value of an existing option (like I did in the revision you mentioned). If this is a new option (or section) in the configuration file, this is not necessary. I suppose that it's a new option here, so you shouldn't have to change the version number.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-31T07:15:13Z

Yep, I'm adding a new option. Thanks for the clarification.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-31T07:15:49Z

This issue was updated by revision 8cb13b3c5f93 .

Status: Started

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-31T07:15:49Z

This issue was updated by revision faa8ad54d476 .

-. The user can decide at will if he/she wants to turn on/off this functionality
-. The option to add colons is turned on by default.

Status: Fixed

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-12-31T07:21:46Z

Nuno, I hope these additions cover all your suggestions. Thanks for taking the time to post them here, they're a great addition to Spyder's usability.

Cheers,
Carlos

@spyder-bot
Copy link
Collaborator Author

From nunoport...@gmail.com on 2011-12-31T10:40:49Z

Yes, i believe that these additions make life easier for programmers...

I'm glad i could contribute for the improvement of Spyder! it's a great tool!
keep up the good work! :)

Regards,
Nuno

@spyder-bot
Copy link
Collaborator Author

From pmav99@gmail.com on 2012-01-01T05:49:14Z

After the previous commits pressing "enter" at the end of the following lines adds (wrongly) a semicolon

if a == 1 and \

for i in ("a", "b", "c",

I think a check should be a added for "" and for parentheses.

Also there is a problem with the automatic insertion of the second quote. Par example. After inserting a double quote the cursor is at the position noted with "":
"
"
After writing some text we are like this:
"text_"
Now inserting a double quote inserts 2 more double quotes instead of moving the cursor one position to the right.
"text"_""
I think that this should behave similarly to parentheses.

Regards
Panos

@spyder-bot
Copy link
Collaborator Author

From pmav99@gmail.com on 2012-01-01T06:11:35Z

Clarifying my previous comment. Now, when you insert a quote you have the following
""
After inserting the second quote you should have the following
""

instead of
""""
of course there should be some special care for triple quotes, so inserting a third quote in a row should be recognized and you should have something like this
""
(inserting a new quote here)
"""*"""

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-01-01T13:53:07Z

Thanks Panos for your feedback. I'll improve our checking mechanism to cover the cases you describe for 'if' and 'for'.

About double quotes, do you think it would be better to disable completely their automatic insertion? I think it's not that easy to check for open quotes to close them, as it is for parentheses but I'll have to think about it.

Status: Started

@spyder-bot
Copy link
Collaborator Author

From pmav99@gmail.com on 2012-01-01T14:23:40Z

Hi Carlos,

In regard of quotes, I think that it is a nice feauture to have, but in no way necessary. I tried to think of an algorithm implementing the correct behavior, but you are right, it is not very easy to find a generic and consistent algorithm. Of course, it is possible but probably it is not worth the effort, since the usefulness is limited (in contrast with parentheses).

I don't know if it easy, or even possible, to add tests for spyder's editor, but I think that this problem would be much easier solved through test driven programming. I think that writing tests for this problem is easier than describing it :)

@spyder-bot
Copy link
Collaborator Author

From pmav99@gmail.com on 2012-01-02T06:04:10Z

perhaps the following issue could be merged with this one https://code.google.com/p/spyderlib/issues/detail?id=887

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-01-05T15:41:34Z

This issue was updated by revision 18efa83f9033 .

Improve usability of automatic insertion of colons and quotes after pmav99
gmail com suggestions

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-01-05T15:45:50Z

I added several changes that I think cover all your suggestions (including triple quotes). Please try them and let me now if they work for you.

@spyder-bot
Copy link
Collaborator Author

From pmav99@gmail.com on 2012-01-07T12:54:23Z

After the last changes, each time I press enter I get the following traceback at the internal console

Traceback (most recent call last):
File "/home/feanor/Programming/Mercurial/spyderlib/spyderlib/widgets/sourcecode/codeeditor.py", line 2025, in keyPressEvent
self.__do_insert_colons():
File "/home/feanor/Programming/Mercurial/spyderlib/spyderlib/widgets/sourcecode/codeeditor.py", line 1998, in __do_insert_colons
line_pos = self.toPlainText().index(leading_text)
AttributeError: 'QString' object has no attribute 'index'

changing line 1998 to the following one to

    line_pos = str(self.toPlainText()).index(leading_text)

results in the following traceback

Traceback (most recent call last):
File "/home/feanor/Programming/Mercurial/spyderlib/spyderlib/widgets/sourcecode/codeeditor.py", line 2025, in keyPressEvent
self.__do_insert_colons():
File "/home/feanor/Programming/Mercurial/spyderlib/spyderlib/widgets/sourcecode/codeeditor.py", line 1998, in __do_insert_colons
line_pos = str(self.toPlainText()).index(leading_text)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 38: ordinal not in range(128)

using unicode() instead of str() solves the problem but I don't know if there are other side-effects.

@spyder-bot
Copy link
Collaborator Author

From pmav99@gmail.com on 2012-01-07T13:03:25Z

In regard the issue with the quotes, it works ok, but there are problems when the quotes are nested. Try to do the following:

(1) the cursor is at the asterisk. It is just before you insert the single quote
(2) what you get after you insert the single quote.

(1) "Some text. A single quote follows "
(2) "Some text. A single quote follows '
'"

As you can see a second quote has been inserted. If it is easy, add a check for already open quotes (of any type). If it is bothersome leave it as it is.

@spyder-bot
Copy link
Collaborator Author

From pmav99@gmail.com on 2012-01-07T14:40:28Z

In continuation of comment 21

The need for unicode() comes up when I edit files with unicode characters (using from future import unicode_literals). I don't know if this has any side-effects.

@spyder-bot
Copy link
Collaborator Author

From pmav99@gmail.com on 2012-01-07T14:42:58Z

In regard of quotes, erasing the first quote, leaves the second one in place. The second one should be erased too.

Current behavior:

"*" # pressing backspace
*"

wanted behavior:

"*" # pressing backspace
*

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-01-08T17:06:43Z

Thanks Panos for your invaluable help on testing these changes and making me improve them.

You're totally right about the use of unicode (I didn't noticed because I was using PySide). I'm going to correct it as soon as possible. Also, I'll try to implement the behavior you described in comment #27.

However, I don't follow you in comment #22. Probably your example expression should be this one?

'Some text. A single quote follows *'

Notice that here the first and last quotes are single ones, not double (as you wrote them). I'll see how easy it is to check for unmatched quotes but can't promise anything.

@spyder-bot
Copy link
Collaborator Author

From airdrik@gmail.com on 2013-04-02T08:30:37Z

So I just checked out a fresh copy (Spyder 2.2.0beta4 (b6204549563f+:2690+)) and tried out some of the auto-quote stuff, but the only thing I got was that if the cursor is between two quotes and you hit backspace it will delete both quotes. I didn't get any auto-inserting of quotes or moving past a quote if you type the quote.
Or in other words according to the Quotes Insertion section on that wiki page, A3 works, A4 doesn't work, A5 works (does nothing special), A6 doesn't work, A7 works, A8 works, A9 works (you should also include some more basic test cases, including adding a quote to a fresh line, or to a new assignment e.g. a = "hello", typing a quote when in front of the end-quote - neither of which worked when I tried them).

I also tested the Colon insertion and auto-indentation and came to the same conclusions as are listed on the wiki page.

@spyder-bot
Copy link
Collaborator Author

From airdrik@gmail.com on 2013-04-02T08:34:15Z

Also, quoting selected text isn't working ( issue #877 )

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-04-02T11:57:31Z

airdrik, I think you haven't activated the feature. In 2.2 auto-quotes are off by default and you have to explicitly turn them on.

For that you have to go to

Tools > Preferences > Editor > Advanced Settings > Source code

and then select the option

"Automatic insertion of closing quotes."

By the way, issue #877 depends on this feature too.

I'll add your recommendations for basic tests, thanks for your suggestions.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-04-05T14:33:18Z

Jed, could you help me test if everything is working according to our spec?

Cc: jed.lud...@gmail.com

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-04-05T20:48:05Z

Test results at revision b6204549563f on Windows 7.

Colon insertion: Test cases A3, A5, B3, B5, C3, and E4 are not working.

Quote insertion: I can't seem to get any of the test cases to work. I did enable the setting in Preferences, but it doesn't seem to matter.

Auto indent: Test cases A3, A5, B3, and B5 are not working.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-04-06T06:34:46Z

Thanks Jed. About your results:

Colon insertion: Your reported failures were expected because all correspond to multi-line statements, which I didn't fixed yet.

Quote insertion: I don't know why is failing for you. I tested it on WinXP and Linux, and it's working fine for me. I'll investigate further.

Auto indent: I haven't touched that part yet because it's not part of this issue.

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-04-06T12:12:46Z

Ok, retesting quote insertion now that I understand the spec a little better :).

Advanced test A4 requires that I enter four " symbols before the auto insert happens.

There are still a couple of test cases that I'm not sure I completely understand, but as best I can tell they seem to be working.

@spyder-bot
Copy link
Collaborator Author

From airdrik@gmail.com on 2013-04-08T15:50:51Z

Going back and retesting the quotes insertion with the option enabled, I get the same results as Jed - everything works except that A4 requires typing a 4th quote to activate, but it should activate on the 3rd quote.

Another (more advanced, feel free to veto) suggestion: if you hit enter inside of a fully-closed single or double-quote string to update the quotes to triple-quotes
example:
a = "some string I want to *make into a multi-line string"
->
a = """some string I want to
make into a multi-line string"""

Which also brings up a couple more advanced indentation cases: indentation within and after triple-quote strings.
Inside triple-quote strings indentation should be manual, or at least ignore any previous indentation.
After triple-quote strings indentation should resume from where it was before the string.

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-04-29T15:08:36Z

Labels: MS-v2.2.1

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-04-29T15:10:06Z

Labels: -MS-v2.2

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-06-10T18:47:16Z

Labels: -MS-v2.2.1 MS-v2.3

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-09-09T07:23:21Z

Cc: -jed.lud...@gmail.com

@spyder-bot
Copy link
Collaborator Author

From wsu...@gmail.com on 2013-11-07T16:12:26Z

Try this using 2.2.3:

class MyNewException(Exception): pass

After hitting enter, you will see this:

class MyNewException(Exception): pass:

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-12-11T12:18:17Z

Labels: -MS-v2.3 MS-v2.3.1

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-08-17T18:36:20Z

Labels: -MS-v2.3.1 MS-v2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants