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

configuration: allow tab to insert spaces at the end of a line #2378

Open
jydiw opened this issue Sep 20, 2024 · 6 comments · May be fixed by #2394
Open

configuration: allow tab to insert spaces at the end of a line #2378

jydiw opened this issue Sep 20, 2024 · 6 comments · May be fixed by #2394
Labels
enhancement New feature or request

Comments

@jydiw
Copy link

jydiw commented Sep 20, 2024

Describe the bug

Apologies in advance if this is better highlighted as a feature request.

I would like the ability to enter tab to insert and align spaces after a line, as in the case of formatting inline comments:

def foo(bar):
    barbar = bar * 2            # doubles bar
    print(f'{bar} -> {barbar}') # print barbar
    return barbar

Environment

{
  "marimo": "0.8.15",
  "OS": "Darwin",
  "OS Version": "23.5.0",
  "Processor": "arm",
  "Python Version": "3.11.9",
  "Binaries": {
    "Browser": "128.0.6613.138",
    "Node": "--"
  },
  "Dependencies": {
    "click": "8.1.7",
    "importlib-resources": "missing",
    "jedi": "0.19.0",
    "markdown": "3.7",
    "pygments": "2.16.1",
    "pymdown-extensions": "10.9",
    "ruff": "0.6.4",
    "starlette": "0.38.4",
    "tomlkit": "0.13.2",
    "typing-extensions": "4.12.2",
    "uvicorn": "0.30.6",
    "websockets": "12.0"
  },
  "Optional Dependencies": {
    "pandas": "2.1.0"
  }
}

Code to reproduce

No response

@jydiw jydiw added the bug Something isn't working label Sep 20, 2024
@mscolnick mscolnick removed the bug Something isn't working label Sep 21, 2024
@mscolnick
Copy link
Contributor

I think this is more of a feature request - as I can see both being preferences.

Do you use a formatter? Does your formatter handle this (or undo this)?

@mscolnick
Copy link
Contributor

mscolnick commented Sep 22, 2024

Actually this might be a bug - seems like the tab logic is being intercepted by:

const startCompletionAtEndOfLine = (cm: EditorView): boolean => {
const { from, to } = cm.state.selection.main;
if (from !== to) {
// this is a selection
return false;
}
const line = cm.state.doc.lineAt(to);
return line.text.slice(0, to - line.from).trim() === ""
? // in the whitespace prefix of a line
false
: startCompletion(cm);
};

cc @akshayka

@mscolnick mscolnick added the bug Something isn't working label Sep 22, 2024
@akshayka
Copy link
Contributor

akshayka commented Sep 23, 2024

Is a completion accidentally being triggered?

EDIT: okay I think I understand. I can take a look.

@mscolnick
Copy link
Contributor

@jydiw - there was a bug in the existing code, which i have fixed here: #2394

The logic is still:

  • if you are at the end of the line, it will try to open the autocomplete
  • if you are in the beginning or middle, it will insert 4 spaces.

Is this ok for your use-case? If you are trying to insert the tab/spaces between you code and an inline-comment, this would work. But if you are trying to add a tab at the end of the line, this won't solve that case. Do you still hope for this to be configurable for that case?

@mscolnick
Copy link
Contributor

Sorry @jydiw - scratch what I saw. I think we plan on keeping Tab as completion anywhere in the line (not just the end). So we can keep this as a FR to make it configurable.

@mscolnick mscolnick added enhancement New feature or request and removed bug Something isn't working labels Sep 24, 2024
@mscolnick mscolnick changed the title allow tab to insert spaces at the end of a line configuration: allow tab to insert spaces at the end of a line Sep 24, 2024
@jydiw
Copy link
Author

jydiw commented Sep 25, 2024

I am coming from VSCode so perhaps this request is only because of what I am used to. Its behavior is slightly different than what you describe:

  • If you are at the beginning of a line, it will insert {tabwidth} spaces.
  • If you are anywhere else, it will insert however many spaces needed to get to the nearest multiple of {tabwidth}.
# if i type this sentence   < tab inserts to here
# and if i type this one    < tab also inserts to here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants