justinbarclay / parinfer-rust-mode

Simplifying how you write Lisp
https://shaunlebron.github.io/parinfer/
GNU General Public License v3.0
228 stars 15 forks source link

Error in REPLs #97

Open contrapunctus-1 opened 1 month ago

contrapunctus-1 commented 1 month ago

Minimal init.el -

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)

(package-install 'geiser)
(require 'geiser)
(package-install 'geiser-chicken)
(require 'geiser-chicken)
(package-install 'geiser-guile)
(require 'geiser-guile)

(package-install 'parinfer-rust-mode)
(require 'parinfer-rust-mode)

(add-hook 'geiser-repl-mode-hook 'parinfer-rust-mode)
(setq-default indent-tabs-mode nil)
(setq-default parinfer-rust--in-debug t)

Steps

  1. Install CHICKEN, Guile, or other Scheme implementation supported by Geiser
  2. Start Emacs with the given init.el
  3. M-x geiser-chicken, or M-x geiser-guile, etc
  4. Insert an opening parenthesis. An error is displayed - Error in pre-command-hook (parinfer-rust--check-for-issues): (text-read-only)

GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.42, cairo version 1.18.0) of 2024-06-30, modified by Debian parinfer-rust-mode v0.9.0

EDIT - This seems to be an issue in SLIME and Sly REPLs too.

contrapunctus-1 commented 1 month ago

The contents of my parinfer debug file -

Options:
Options { cursor_x: Some(0), cursor_line: Some(7), prev_cursor_x: None, prev_cursor_line: None, prev_text: None, selection_start_line: None, changes: [], partial_result: false, force_balance: false, return_parens: false, comment_char: ';', string_delimiters: ["\""], lisp_vline_symbols: false, lisp_block_comments: false, guile_block_comments: false, scheme_sexp_comments: false, janet_long_strings: false }
Response:
Answer { text: "CHICKEN\n(c) 2008-2021, The CHICKEN Team\n(c) 2000-2007, Felix L. Winkelmann\nVersion 5.3.0 (rev e31bbee5)\nlinux-unix-gnu-x86-64 [ 64bit dload ptables]\n\nType ,? for help.\n#;1> ", success: true, error: None, cursor_x: Some(0), cursor_line: Some(7), tab_stops: [], paren_trails: [ParenTrail { line_no: 3, start_x: 27, end_x: 28 }, ParenTrail { line_no: 4, start_x: 43, end_x: 44 }], parens: [] }
Options:
Options { cursor_x: Some(0), cursor_line: Some(7), prev_cursor_x: None, prev_cursor_line: None, prev_text: None, selection_start_line: None, changes: [], partial_result: false, force_balance: false, return_parens: false, comment_char: ';', string_delimiters: ["\""], lisp_vline_symbols: false, lisp_block_comments: false, guile_block_comments: false, scheme_sexp_comments: false, janet_long_strings: false }
Response:
Answer { text: "CHICKEN\n(c) 2008-2021, The CHICKEN Team\n(c) 2000-2007, Felix L. Winkelmann\nVersion 5.3.0 (rev e31bbee5)\nlinux-unix-gnu-x86-64 [ 64bit dload ptables]\n\nType ,? for help.\n#;1> ", success: true, error: None, cursor_x: Some(0), cursor_line: Some(7), tab_stops: [], paren_trails: [ParenTrail { line_no: 3, start_x: 27, end_x: 28 }, ParenTrail { line_no: 4, start_x: 43, end_x: 44 }], parens: [] }
contrapunctus-1 commented 1 month ago

Normally I would attach a backtrace, but parinfer-rust-mode seems to be performing some heavy wizardry that prevents M-x toggle-debug-on-error from providing one.

EDIT: It's because it uses pre-command-hook.

justinbarclay commented 1 month ago

Thanks for taking the time to report this; however, I don't consider this a bug.

parinfer needs access to the entire file or buffer to work and the file or buffer that it's working in needs to be a valid lisp file. This means that parinfer-rust-mode supports things like buffers that contain read-only text or have a mix of sexps and plain text.

I'm open to pull requests if someone wants to make a new minor mode that makes this work.

On the other hand, if all you're looking for is something to auto balance parens, I would recommend electric-pair-mode instead.