lokedhs / gnu-apl-mode

GNU APL mode for Emacs
GNU General Public License v3.0
94 stars 19 forks source link

Add a configurable flash on send command and send line command #40

Closed doyougnu closed 3 years ago

doyougnu commented 3 years ago

I'm writing a spacemacs layer for gnu-apl and thought I would add some small niceties. All this PR does is add a function to flash regions when they are sent to the apl interpreter which can be disabled and a send line function. Any comments welcome.

lokedhs commented 3 years ago

Thank you for your contribution. Looks good to me for the most part. I'll be happy to merge it once you've looked over my comments.

There is also code to flash content in the function gnu-apl-interactive-send-current-function. Perhaps it would make sense to merge this.

doyougnu commented 3 years ago

Thanks for you comments. I've made the requested changes.

For whatever reason there is an extra newline on input to the interpreter:

With this example

⎕ ← ⊂data ← (1 2 3 4) (2 5 8 6) (8 6 2 3) (8 7 6 1)
data
2 4⍴⍳8 

calling gnu-apl-interactive-send-line or gnu-apl-interactive-send-region produces this:

      ╔═══════════════════════════════════════╗
║┏→━━━━━━┓ ┏→━━━━━━┓ ┏→━━━━━━┓ ┏→━━━━━━┓║
║┃1 2 3 4┃ ┃2 5 8 6┃ ┃8 6 2 3┃ ┃8 7 6 1┃║
║┗━━━━━━━┛ ┗━━━━━━━┛ ┗━━━━━━━┛ ┗━━━━━━━┛║
╚═══════════════════════════════════════╝
      ╔═══════╗
║1 2 3 4║
║5 6 7 8║
╚═══════╝

I believe the output should not have a tab character on the first line, like so:

╔═══════════════════════════════════════╗
║┏→━━━━━━┓ ┏→━━━━━━┓ ┏→━━━━━━┓ ┏→━━━━━━┓║
║┃1 2 3 4┃ ┃2 5 8 6┃ ┃8 6 2 3┃ ┃8 7 6 1┃║
║┗━━━━━━━┛ ┗━━━━━━━┛ ┗━━━━━━━┛ ┗━━━━━━━┛║
╚═══════════════════════════════════════╝
╔═══════╗
║1 2 3 4║
║5 6 7 8║
╚═══════╝
lokedhs commented 3 years ago

The issue with the indentation is caused by the fact that printing will start at the end of the buffer. GNU APL assumes that the cursor is at the beginning of the line, since after a command has been typed, the cursor has moved to the next line. When using gnu-apl-interactive-send-region no command was actually input, which leaves the cursor after the prompt.

One solution to this would be to check if the buffer ends with a prompt (i.e. it's waiting for input) and then delete it before sending the command. This should be safe, as GNU APL only accepts commands from Emacs while it's waiting at the prompt.

This fix is independent of this PR though, so I'll merge this, and if you would like to implement that solution you're welcome to send another one.

doyougnu commented 3 years ago

The issue with the indentation is caused by the fact that printing will start at the end of the buffer. GNU APL assumes that the cursor is at the beginning of the line, since after a command has been typed, the cursor has moved to the next line. When using gnu-apl-interactive-send-region no command was actually input, which leaves the cursor after the prompt.

One solution to this would be to check if the buffer ends with a prompt (i.e. it's waiting for input) and then delete it before sending the command. This should be safe, as GNU APL only accepts commands from Emacs while it's waiting at the prompt.

This fix is independent of this PR though, so I'll merge this, and if you would like to implement that solution you're welcome to send another one.

Thanks for the fast responses. I've opened an issue for this and intend to work on it. I have a long flight coming up so I'll give this a go then.