BrettWitty / TADS-3-Mode-for-Emacs

(Ancient) TADS3 mode for Emacs
2 stars 2 forks source link

electric-tads-brace misbehaves #6

Open alexispurslane opened 1 year ago

alexispurslane commented 1 year ago

When entering an open curly brace, it puts the cursor outside of the braces instead of inside when auto-newline is enabled.

BrettWitty commented 1 year ago

I'm not seeing this behaviour. Do you have smartparens enabled? I see that buggy behaviour then. Might be a conflict with that and electric-tads-brace.

alexispurslane commented 1 year ago

Ohhhh, I'll check on that. I'd removed that behavior entirely to make it more usable in the meantime but I can put it back.

alexispurslane commented 1 year ago

Yup, it was a conflict with smartparens. I'm going to see if I can figure out how to modify the function so that it is compatible with smartparens being on.

alexispurslane commented 1 year ago

Alright, I managed to get a (possibly simpleminded) prototype implementation of electric braces going that works with and without smartparens enabled. Here it is:

(defun electric-tads3-brace (arg)
    "Insert character and correct line's indentation."
    (interactive "P")
    (let (insertpos)
        (if (and tads3-auto-newline
                (not (save-excursion
                         (skip-chars-backward " \t")
                         (bolp))))
            (progn
                (tads3-indent-line)
                (newline)))
        (self-insert-command (prefix-numeric-value arg))
        (tads3-indent-line)
        (newline)
        (save-excursion
            (newline)
            (tads3-indent-line))
        (tads3-indent-line)))
alexispurslane commented 1 year ago

I kept insertpos around bc if I need to expand this later to add some of the logic back, it might be needed.