1

Only when rust-mode is enabled, what is the best way to insert a newline after a press on the ; key? This is what I have actually:

(defun my-rust-lang-mode-config ()
   (local-set-key (kbd ";") (lambda () (interactive) (insert ";")(newline-and-indent))))
(add-hook 'rust-mode-hook 'my-rust-lang-mode-config) 
  • 1
    Isn't it desirable to not insert a new line if there is already one? – Name Jul 23 '15 at 4:56
3

The "best" way? Dunno. Define your criteria for "best". Looks OK to me, FWIW.

But I would probably just do this:

(define-key 'rust-mode-map ";" (lambda () ...))

That assumes the mode map is rust-mode-map. Oh, and I would also probably name the command, instead of using an anonymous function -- makes it easier to work with.

But it probably doesn't make a lot of difference how you create the key binding.

  • I was reading (and not understanding) about cc-mode auto-newlines and thought maybe it was "the best" way. – Nsukami _ Jul 23 '15 at 3:15
2

An even shorter way:

(define-key 'rust-mode-map ";" (kbd "C-q ; RET"))

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.