A few typing-saving Racket tips for Emacs...

* If you're a weirdo who is using Quack rather than Greg Hendershott's much newer Emacs racket-mode, and your keyboard requires you to use the Shift key to type parentheses, you can instead just use the square brackets keys to get parentheses inserted, with this setting:

(setq quack-smart-open-paren-p t)

Specifically, "[" key inserts paren, and "]" inserts closing paren/bracket that agrees with the matching open.  "C-q" can be used on a per-character basis to defeat this.  (Note that you'll want some different behavior if you like to use a PLT-style mix of parens and square brackets in your Racket code, since you don't want to be typing "C-q [" often.)

* You can add sexp-based operation key bindings like these:

(global-set-key [(meta left)]      'backward-sexp)
(global-set-key [(meta right)]     'forward-sexp)
(global-set-key [(meta backspace)] 'backward-kill-sexp)
(global-set-key [(meta delete)]    'kill-sexp)
(global-set-key [(meta up)]        'backward-up-list)
(global-set-key [(meta down)]      'down-list)

Quack has special code for Scheme that makes these standard Emacs commands work for most Scheme/Racket code, but these bindings should also work in other Emacs language modes that implement these standard operations.

Note that you can type `[(meta left)]` as "Alt simultaneous with Left" or as "Esc and then Left".  You can also bind unmodified keys, like your F keys or your numeric keypad, to these operations.

* If you want to be a super power user, you might try out Taylor Campbell's ParEdit.  https://www.emacswiki.org/emacs/ParEdit

* Instead of various typing to fix indentation and extraneous whitespace in your code, try out the `quack-tidy-buffer` command.

* Again, occasionally, instead of watching overhyped Netflix shows that drag out a single disposable 90-minute horror flick into an entire first season, you might read around the Emacs documentation and Web, to see whether there's other big typing-saving features.

As an example, one thing that it seems a lot of people don't learn is keyboard macros, which can save lots of typing and time, with very little upfront cost.  To make some of the the macro commands easier to type, here's some key bindings:

(global-set-key [f5]            'call-last-kbd-macro)
(global-set-key [(control f5)]  'my-macro-record-toggle)

(defun my-macro-record-toggle ()
  (interactive)
  (if defining-kbd-macro
      (end-kbd-macro)
    (start-kbd-macro nil)))

As you learn more Emacs commands, you can combine these with macros, and get some very powerful ad hoc operations going.  One of the tricks is to have the macro leave the point at the start of the next place to do the operation (perhaps involving search), and then tell emacs to do the macro for the rest of the buffer or narrowing, or to have you hit F5 after confirming that the operation should be performed (or skip to the next search result separately), or to use the `C-u` Emacs command prefix to say to apply the macro n times.

There's tons more Emacs features that are standard or provided by open source Emacs Lisp files, and some of them will save typing.

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to