1

I'm trying to be able to draw ascii art in emacs picture-mode by moving left, down, up, and right with the j,h,k,l keys in evil-normal-mode.

To do this I used these bindings:

(nmap :keymaps 'picture-mode-map "k" (lambda () (picture-movement-up) (picture-self-insert (string-to-char "."))) "j" (lambda () (picture-movement-down) (picture-self-insert (string-to-char "."))) "h" (lambda () (picture-movement-left) (picture-self-insert (string-to-char "."))) "l" (lambda () (picture-movement-right) (picture-self-insert (string-to-char "."))))

What I expect is a single insertion of the . and for the motion to be changed with the corresponding picture-movement function.

However when I tried out these bindings the direction of text being inserted was right but 46 characters were inserted at once. And the character was they key I pressed, not the period.

For example when I pressed l I'd get llllllllllllllllllllllllllllllllllllllllllllll immediately instead of just a gradual succession of periods as I continued presssing l.

Why am I getting this behavior and how could I achieve my expected behavior?

Piglet
  • 73
  • 2
  • 7

1 Answers1

0

The ASCII character . has the integer value 46. The picture-self-insert function passes its argument as a count, along with the value of the last-command-event variable, to the picture-insert function. For your case, this results in 46 insertions of the value of last-command-event, which happens to be whatever key you pressed.

In your lambda functions, replace (picture-self-insert (string-to-char ".")) with:

(picture-insert ?. 1)

This will perform 1 insertion of the . character.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
  • I noticed there was one unusual behavior. When I use `picture-insert` to insert a character when I'm at the beginning of a line, it jumps what seems to certain number of spaces forward. It varies every time. But seems to be 1 greater than the spaces inserted from previous time. But `picture-self-insert` inserts a character at the beginning of the line as we would expect. This might be out of the scope of my question, but do you have an idea of why this is? I removed all modes that seemed related to indentation and this still happens. – Piglet Dec 24 '17 at 16:19
  • This is because before it calls `picture-insert`, `picture-self-insert` calls `picture-update-desired-column`. You might try calling it the same way prior to your `picture-insert` call: `(picture-update-desired-column (not (eq this-command last-command)))`. – Steve Vinoski Dec 24 '17 at 23:06