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

Mismatched sexp state: wrapping would break structure #1175

Open
xaosfiftytwo opened this issue Oct 28, 2023 · 0 comments
Open

Mismatched sexp state: wrapping would break structure #1175

xaosfiftytwo opened this issue Oct 28, 2023 · 0 comments

Comments

@xaosfiftytwo
Copy link

Mismatched sexp state: wrapping would break structure

Expected behaviour

In org mode buffer, with smartparens mode enabled, selecting text and pressing '*' should wrap the text in parens and emphasize it.

Actual behaviour

No closing paren is inserted and an error message is shown:

Mismatched sexp state: wrapping would break structure

Steps to reproduce the problem

This can easily and consistently be reproduced:

  • Open a new buffer in Org mode.
  • Optional: insert a new header line.
  • Insert some text that you want to emphasize.
  • Select the text either from the start or from the end.
  • Insert '*'.

Backtrace

I edited smartparens.el, replacing 'user-error' with 'error' to get a Backtrace.

Debugger entered--Lisp error: (error "Mismatched sexp state: wrapping would break struct...")
  error("Mismatched sexp state: wrapping would break struct...")
  (if (sp-region-ok-p sp-wrap-point (mark)) nil (error "Mismatched sexp state: wrapping would break struct..."))
  (cond ((and point-string-context mark-string-context (eq (car point-string-context) (car mark-string-context)))) ((and (not point-string-context) (not mark-string-context)) (if (sp-region-ok-p sp-wrap-point (mark)) nil (error "Mismatched sexp state: wrapping would break struct..."))) ((if point-string-context (not mark-string-context) mark-string-context) (user-error "Mismatched string state: point %sin string, mark %..." (if (car-safe point-string-context) "" "not ") (if (car-safe mark-string-context) "" "not "))) (t (user-error "Mismatched string state: point and mark are inside...")))
  (let ((inserted-string (prog1 (delete-and-extract-region sp-wrap-point (point)) (setq syntax-propertize--done -1) (syntax-propertize (point-max)))) (point-string-context (sp-get-quoted-string-bounds sp-wrap-point)) (mark-string-context (sp-get-quoted-string-bounds (mark)))) (cond ((and point-string-context mark-string-context (eq (car point-string-context) (car mark-string-context)))) ((and (not point-string-context) (not mark-string-context)) (if (sp-region-ok-p sp-wrap-point (mark)) nil (error "Mismatched sexp state: wrapping would break struct..."))) ((if point-string-context (not mark-string-context) mark-string-context) (user-error "Mismatched string state: point %sin string, mark %..." (if (car-safe point-string-context) "" "not ") (if (car-safe mark-string-context) "" "not "))) (t (user-error "Mismatched string state: point and mark are inside..."))) (insert inserted-string))
  (progn (let ((inserted-string (prog1 (delete-and-extract-region sp-wrap-point (point)) (setq syntax-propertize--done -1) (syntax-propertize (point-max)))) (point-string-context (sp-get-quoted-string-bounds sp-wrap-point)) (mark-string-context (sp-get-quoted-string-bounds (mark)))) (cond ((and point-string-context mark-string-context (eq (car point-string-context) (car mark-string-context)))) ((and (not point-string-context) (not mark-string-context)) (if (sp-region-ok-p sp-wrap-point (mark)) nil (error "Mismatched sexp state: wrapping would break struct..."))) ((if point-string-context (not mark-string-context) mark-string-context) (user-error "Mismatched string state: point %sin string, mark %..." (if (car-safe point-string-context) "" "not ") (if (car-safe mark-string-context) "" "not "))) (t (user-error "Mismatched string state: point and mark are inside..."))) (insert inserted-string)))
  (unwind-protect (progn (let ((inserted-string (prog1 (delete-and-extract-region sp-wrap-point (point)) (setq syntax-propertize--done -1) (syntax-propertize (point-max)))) (point-string-context (sp-get-quoted-string-bounds sp-wrap-point)) (mark-string-context (sp-get-quoted-string-bounds (mark)))) (cond ((and point-string-context mark-string-context (eq (car point-string-context) (car mark-string-context)))) ((and (not point-string-context) (not mark-string-context)) (if (sp-region-ok-p sp-wrap-point (mark)) nil (error "Mismatched sexp state: wrapping would break struct..."))) ((if point-string-context (not mark-string-context) mark-string-context) (user-error "Mismatched string state: point %sin string, mark %..." (if (car-safe point-string-context) "" "not ") (if (car-safe mark-string-context) "" "not "))) (t (user-error "Mismatched string state: point and mark are inside..."))) (insert inserted-string))) (if (or (not modified) (eq modified 'autosaved)) (progn (restore-buffer-modified-p modified))))
  (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (let ((inserted-string (prog1 (delete-and-extract-region sp-wrap-point ...) (setq syntax-propertize--done -1) (syntax-propertize ...))) (point-string-context (sp-get-quoted-string-bounds sp-wrap-point)) (mark-string-context (sp-get-quoted-string-bounds (mark)))) (cond ((and point-string-context mark-string-context (eq ... ...))) ((and (not point-string-context) (not mark-string-context)) (if (sp-region-ok-p sp-wrap-point ...) nil (error "Mismatched sexp state: wrapping would break struct..."))) ((if point-string-context (not mark-string-context) mark-string-context) (user-error "Mismatched string state: point %sin string, mark %..." (if ... "" "not ") (if ... "" "not "))) (t (user-error "Mismatched string state: point and mark are inside..."))) (insert inserted-string))) (if (or (not modified) (eq modified 'autosaved)) (progn (restore-buffer-modified-p modified)))))
  (let ((inserted-string-length (- (point) sp-pre-command-point))) (setq sp-wrap-point (- (point) inserted-string-length)) (setq sp-wrap-mark (mark)) (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (let ((inserted-string (prog1 ... ... ...)) (point-string-context (sp-get-quoted-string-bounds sp-wrap-point)) (mark-string-context (sp-get-quoted-string-bounds ...))) (cond ((and point-string-context mark-string-context ...)) ((and ... ...) (if ... nil ...)) ((if point-string-context ... mark-string-context) (user-error "Mismatched string state: point %sin string, mark %..." ... ...)) (t (user-error "Mismatched string state: point and mark are inside..."))) (insert inserted-string))) (if (or (not modified) (eq modified 'autosaved)) (progn (restore-buffer-modified-p modified))))) (if (> (point) (mark)) (progn (let ((char (delete-and-extract-region (- ... inserted-string-length) (point)))) (exchange-point-and-mark) (insert char)))) (let* ((oleft (make-overlay (- (region-beginning) inserted-string-length) (region-beginning) nil nil t)) (oright (make-overlay (region-end) (region-end) nil nil t))) (setq sp-wrap-overlays (cons oleft oright)) (if sp-highlight-wrap-overlay (progn (overlay-put oleft 'face 'sp-wrap-overlay-face) (overlay-put oright 'face 'sp-wrap-overlay-face))) (overlay-put oleft 'priority 100) (overlay-put oright 'priority 100) (overlay-put oleft 'keymap sp-wrap-overlay-keymap) (overlay-put oleft 'type 'wrap) (setq sp-previous-point (point)) (goto-char (1+ (overlay-start oleft)))))
  (progn (let ((inserted-string-length (- (point) sp-pre-command-point))) (setq sp-wrap-point (- (point) inserted-string-length)) (setq sp-wrap-mark (mark)) (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (let ((inserted-string ...) (point-string-context ...) (mark-string-context ...)) (cond (...) (... ...) (... ...) (t ...)) (insert inserted-string))) (if (or (not modified) (eq modified 'autosaved)) (progn (restore-buffer-modified-p modified))))) (if (> (point) (mark)) (progn (let ((char (delete-and-extract-region ... ...))) (exchange-point-and-mark) (insert char)))) (let* ((oleft (make-overlay (- (region-beginning) inserted-string-length) (region-beginning) nil nil t)) (oright (make-overlay (region-end) (region-end) nil nil t))) (setq sp-wrap-overlays (cons oleft oright)) (if sp-highlight-wrap-overlay (progn (overlay-put oleft 'face 'sp-wrap-overlay-face) (overlay-put oright 'face 'sp-wrap-overlay-face))) (overlay-put oleft 'priority 100) (overlay-put oright 'priority 100) (overlay-put oleft 'keymap sp-wrap-overlay-keymap) (overlay-put oleft 'type 'wrap) (setq sp-previous-point (point)) (goto-char (1+ (overlay-start oleft))))))
  (if (and sp-autowrap-region (sp-wrap--can-wrap-p)) (progn (let ((inserted-string-length (- (point) sp-pre-command-point))) (setq sp-wrap-point (- (point) inserted-string-length)) (setq sp-wrap-mark (mark)) (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (let (... ... ...) (cond ... ... ... ...) (insert inserted-string))) (if (or (not modified) (eq modified ...)) (progn (restore-buffer-modified-p modified))))) (if (> (point) (mark)) (progn (let ((char ...)) (exchange-point-and-mark) (insert char)))) (let* ((oleft (make-overlay (- ... inserted-string-length) (region-beginning) nil nil t)) (oright (make-overlay (region-end) (region-end) nil nil t))) (setq sp-wrap-overlays (cons oleft oright)) (if sp-highlight-wrap-overlay (progn (overlay-put oleft 'face 'sp-wrap-overlay-face) (overlay-put oright 'face 'sp-wrap-overlay-face))) (overlay-put oleft 'priority 100) (overlay-put oright 'priority 100) (overlay-put oleft 'keymap sp-wrap-overlay-keymap) (overlay-put oleft 'type 'wrap) (setq sp-previous-point (point)) (goto-char (1+ (overlay-start oleft)))))))
  sp-wrap--initialize()
  sp--post-self-insert-hook-handler()
  self-insert-command(1)
  org-self-insert-command(1)
  funcall-interactively(org-self-insert-command 1)
  command-execute(org-self-insert-command)

Smartpackage configuration

Standard configuration, except setting for sp-navigate-consider-symbols, set to nil.

Actually, setting sp-navigate-consider-symbols to t solves the problem, but I insist on setting it to nil for fast navigation in emacs-lisp mode.

(use-package smartparens
  :hook  ((org-mode prog-mode))
  :init
  (setq sp-navigate-consider-symbols nil)
  :config
  (require 'smartparens-config))

Ouput from sp-describe-system

  • smartparens version: 20231024.1804
  • Active major-mode: org-mode
  • Smartparens strict mode: nil
  • Emacs version (M-x emacs-version): GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.16.0) of 2023-08-30, modified by Debian
  • Starterkit/Distribution: Vanilla
  • OS: gnu/linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

No branches or pull requests

1 participant