0

I would like to change the default behavior in emacs when '\n' meta-characters are encountered by the cursor. The default behavior is such that at '\n',

(1) right-key sends the cursor to the beginning of the next line, (2) up-key sends the cursor to the end of the prev line, (3) down-key sends the cursor to the end of the next line.

How can I get emacs to ignore '\n' meta-characters in a given buffer? Or how can I get emacs to ignore either one of the keys identified in (1), (2) and (3)?

1
1

You can reassign the keys to new functions that don't move if the char at point is a newline:

(defun maybe-down ()
  "Move down if char at point is not a newline."
  (interactive)
  (if (char-equal (char-after) 10) (ignore) (next-line)))
(define-key (current-local-map) [down] 'maybe-down)

And similarly for [right] with (right-char).

5
  • Thanks for the suggestion. This fails to run emacs 27. Fails next-line check. Fails define-key: Wrong type argument: keymapp, nil – OS2 Jan 20 at 22:18
  • The nil means there's no local map. You can define one, or turn on a major mode to establish one. I don't know what you mean by "fails next-line check". – choroba Jan 20 at 22:56
  • Yes it's working as expected. Thank you. However, why do I get Invalid function: (ignore) when this condition gets satisfied: (if (char-equal (char-after) 10) ((ignore) (next-line)) (forward-char))) – OS2 Jan 20 at 23:49
  • Seems I can ignore the ignore next-line completely and have just: (if (char-equal (char-after) 10) () (forward-char))) – OS2 Jan 21 at 1:01
  • @OS2: I wrote (ignore), not ((ignore) ... – choroba Jan 21 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.