Skip to content

improve prompt-window completion keys#2121

Open
mahmoodsh36 wants to merge 1 commit into
lem-project:mainfrom
mahmoodsh36:completion
Open

improve prompt-window completion keys#2121
mahmoodsh36 wants to merge 1 commit into
lem-project:mainfrom
mahmoodsh36:completion

Conversation

@mahmoodsh36

@mahmoodsh36 mahmoodsh36 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

previously:

  • return key did both either complete or choose the current candidate, it was ambiguous.
  • tab and shift-tab behaved just like C-n/C-p for navigating candidates in the completion, which is redundant imo
  • M-n/M-p also behaved like C-n/C-p

now:

  • return key selects the current candidate and exits immediately. *completion-select-hook* was introduced to make this work
  • M-n/M-p navigate history in minibuffer completion prompt
  • C-n/C-p navigate candidates
  • tab completes the prompt to the currently focused candidate

previously:
- return key did both either complete or choose the current candidate, it was ambiguous.
- tab and shift-tab behaved just like C-n/C-p for navigating candidates
  in the completion, which is redundant imo
- M-n/M-p also behaved like C-n/C-p
now:
- return key selects the current candidate and exits immediately
  `*completion-select-hook*` was introduced to make this work
- M-n/M-p navigate history in minibuffer completion prompt
- C-n/C-p navigate candidates
- tab completes the prompt to the currently focused candidate
@code-contractor-app

code-contractor-app Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

❌ Code Contractor Validation: FAILED

=== Contract: contract ===

✓ Code Contractor Validation Result
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📋 Contract Source: Repository

📊 Statistics:
  Files Changed:    2
  Lines Added:      46
  Lines Deleted:    20
  Total Changed:    66
  Delete Ratio:     0.30 (30%)

Status: FAILED ❌

🤖 AI Providers:
  - codex — model: gpt-5.2

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ Violations Found (1):

[ERROR] functional_style_rule
  AI check failed: "functional_style_rule"
  ❌ Reason:
    Added a new global special variable via `defvar` to pass selection
    behavior between components; this introduces dynamic state instead of
    using explicit function arguments.
📋 Contract Configuration: contract (Source: Repository)
version: 2

trigger:
  paths:
    - "extensions/**"
    - "frontends/**/*.lisp"
    - "src/**"
    - "tests/**"
    - "contrib/**"
    - "**/*.asd"
  head_branches:
    exclude:
      - 'revert-*'

validation:
  limits:
    max_total_changed_lines: 400
    max_delete_ratio: 0.5
    max_files_changed: 10
    severity: warning

  ai:
    system_prompt: |
      You are a senior Common Lisp engineer reviewing code for Lem editor.
      Lem is a text editor with multiple frontends (ncurses, SDL2, webview).
      Focus on maintainability, consistency with existing code, and Lem-specific conventions.
    rules:
      # === File Structure ===
      - name: defpackage_rule
        prompt: |
          First form must be `defpackage` or `uiop:define-package`.
          Package name should match filename (e.g., `foo.lisp` → `:lem-ext/foo` or `:lem-foo`).
          Extensions must use `lem-` prefix (e.g., `:lem-python-mode`).

      - name: file_structure_rule
        prompt: |
          File organization (top to bottom):
          1. defpackage
          2. defvar/defparameter declarations
          3. Key bindings (define-key, define-keys)
          4. Class/struct definitions
          5. Functions and commands

      # === Style ===
      - name: loop_keywords_rule
        prompt: |
          Loop keywords must use colons: `(loop :for x :in list :do ...)`
          NOT: `(loop for x in list do ...)`

      - name: naming_conventions_rule
        prompt: |
          Naming conventions:
          - Functions/variables: kebab-case (e.g., `find-buffer`)
          - Special variables: *earmuffs* (e.g., `*global-keymap*`)
          - Constants: +plus-signs+ (e.g., `+default-tab-size+`)
          - Predicates: -p suffix for functions (e.g., `buffer-modified-p`)
          - Do NOT use -p suffix for user-configurable variables

      # === Documentation ===
      - name: docstring_rule
        prompt: |
          Required docstrings for:
          - Exported functions, methods, classes
          - `define-command` (explain what the command does)
          - Generic functions (`:documentation` option)
          Important functions should explain "why", not just "what".
        severity: warning

      # === Lem-Specific ===
      - name: internal_symbol_rule
        prompt: |
          Use exported symbols from `lem` or `lem-core` package.
          Avoid `lem::internal-symbol` access.
          If internal access is necessary, document why.

      - name: error_handling_rule
        prompt: |
          - `error`: Internal/programming errors
          - `editor-error`: User-facing errors (displayed in echo area)
          Always use `editor-error` for messages shown to users.

      - name: frontend_interface_rule
        prompt: |
          Frontend-specific code must use `lem-if:*` protocol.
          Do not call frontend implementation directly from core.
        severity: warning

      # === Functional Style ===
      - name: functional_style_rule
        prompt: |
          Prefer explicit function arguments over dynamic variables.
          Avoid using `defvar` for state passed between functions.
          Exception: Well-documented cases like `*current-buffer*`.

      - name: dynamic_symbol_call_rule
        prompt: |
          Avoid `uiop:symbol-call`. Rethink architecture instead.
          If unavoidable, document the reason.

      # === Libraries ===
      - name: alexandria_usage_rule
        prompt: |
          Alexandria utilities allowed: `if-let`, `when-let`, `with-gensyms`, etc.
          Avoid: `alexandria:curry` (use explicit lambdas)
          Avoid: `alexandria-2:*` functions not yet used in codebase

      # === Macros ===
      - name: macro_style_rule
        prompt: |
          Keep macros small. For complex logic, use `call-with-*` pattern:
          ```lisp
          (defmacro with-foo (() &body body)
            `(call-with-foo (lambda () ,@body)))
          ```
          Prefer `list` over backquote outside macros.

💬 Feedback

Reply to a violation comment with:

  • /dismiss <reason> - Report false positive or not applicable
📚 About Code Contractor

Declarative Code Standards That Learn and Improve

Define domain-specific validation rules in YAML.
Your contracts document team knowledge and evolve into more accurate AI enforcement.

Want this for your repo?
Install Code Contractor

@code-contractor-app code-contractor-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Contractor validation failed ❌ — see the sticky comment for full results.

@@ -17,6 +18,7 @@

(defvar *completion-context* nil)
(defvar *completion-reverse* nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Contractor: functional_style_rule

Contract: contract

AI check failed: "functional_style_rule"

Reason:
Added a new global special variable via defvar to pass selection behavior between components; this introduces dynamic state instead of using explicit function arguments.

@mahmoodsh36

Copy link
Copy Markdown
Contributor Author

C-n/C-p worked before this commit though, my changes didnt touch them anyway.

@vindarel

Copy link
Copy Markdown
Collaborator

I like Tab and shift-Tab to cycle through the completions,
so I tried your patch and this feels weird (actually unusable!).

If there's pressure or good reasons to change it, then so be it…

I like Enter's new behavior to directly select the candidate, but I fear it is not suitable in all contexts, in all types of completions:

  • Alt-x … RET to choose a command: OK (and better)
  • Alt-x project-find-file RET choose file RET => we might want to edit the selected file name
    • with your changes, we can complete the file name with Tab and edit it
  • or imagine another command that prompts for strings but would accept an edited string. If Enter validated the prompt we could not edit it. Or, how?

Thoughts?

ps: would you enable C-n right after a Alt-x to start the completion? Currently it does nothing, only Tab opens the completion buffer.

@mahmoodsh36

Copy link
Copy Markdown
Contributor Author

I like Tab and shift-Tab to cycle through the completions, so I tried your patch and this feels weird (actually unusable!).

If there's pressure or good reasons to change it, then so be it…

I like Enter's new behavior to directly select the candidate, but I fear it is not suitable in all contexts, in all types of completions:

* Alt-x … RET to choose a command: OK (and better)

* Alt-x project-find-file RET choose file RET => we might want to edit the selected file name
  
  * with your changes, we can complete the file name with Tab and edit it

* or imagine another command that prompts for strings but would accept an edited string. If Enter validated the prompt we could not edit it. Or, how?

Thoughts?

ps: would you enable C-n right after a Alt-x to start the completion? Currently it does nothing, only Tab opens the completion buffer.

this was the idea, to make return less ambiguous and use tab for selecting the current candidate for furhter editing. so return is for "choose this and exit" and tab is for "choose this".
i understand that this might be unintuitive for people that expect tab to also behave like C-n, perhaps we can have a variable for it like *prompt-tab-for-complete* or something? or maybe just bind this "complete without exiting" behavior to another key?

about the latter idea, im not sure i know what you mean, but wasnt *automatic-tab-completion* added for this purpose?

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been inactive for {days} days. If there is no activity within the next 7 days, it will be automatically closed. Please comment or push new commits to keep it open.

@github-actions github-actions Bot added the stale label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants