crazy mode

Introduction

crazy-mode is a Rube Goldberg machine (but simpler and one that works) mode for GNU Emacs. crazy-mode helps you code/go crazy. Currently good support for C programming is included.

crazy-mode hacks around the characters as you type in the buffer to do various stuff often reducing the effort to accomplish something.

Say for example, in c-mode, pressing space bar often inserts _ or sometimes real spaces depending on the context. It also inserts - when inside #include header names.

If you find this software useful, you may:

  • Help free software by switching to any GNU/Linux.
  • Regardless of the Operating System you use, always buy Debian main compatible hardware or at least ask for one.

crazy-mode-demo.gif

Figure 1: crazy-mode demo

Source: GitLab GitHub

History

It's known that GNU Emacs is extremely extensible, and when I was first introduced to GNU Emacs, I decided to do something weird. I liked the idea of dwim which is very popular in the Emacs world, and I wanted to reduce as much keystrokes to write my code. I wrote some elisp hacks to do so, which worked really great.

Since I has been using this in my personal config for quite some time, I decided to write a mode for that which is more maintainable.

Hacks

| in the examples is the cursor point. You can always do C-q key when do you wan't crazy-mode to act crazy for the given key.

c-mode

  • S-SPC (shift + space)
    • insert real space (may not work without a GUI)
  • . key
    • .. => (|)
    • #include.. => #include <|>
    • #include <.> => #include "|"
  • pressing space bar
    • _| => ->| (ie, pressing space bar twice gives ->)
    • #include <example|> => #include <example-|>
    • gtk| => gtk_|
    • difftime(time(NULL, |)) => difftime(time(NULL), |)
  • ' key
    • gtk_window| => GTK_WINDOW|
    • GTK_WINDOW| => GtkWindow|
  • , key
    • memcpy(dest|) => memcpy(dest, |)
    • items[|] => items[], |
    • power| => power, |
    • power, | => power = |
  • ; key
    • #include <stdio.h|> => #include "<stdio.h>\n|"
    • power = pow(3, 4|) => power = pow(3, 4);

Installation

crazy-mode has been tested only with GNU Emacs 27.1 and 28

Installing from git

git clone https://gitlab.com/sadiq/crazy-mode.git
emacs --batch --eval="(package-install-file \"$(realpath crazy-mode)\")"

Recommended configuration

;; set custom path if loading from custom path
;; (add-to-list 'load-path "~/.emacs.d/crazy-mode/")
(require 'crazy)
(add-hook 'c-mode-common-hook
   (lambda ()
          ;; note: "gnu" (default) style adds a space before function '('
          (add-to-list 'c-cleanup-list 'space-before-funcall)
          (c-toggle-auto-newline 1)
          (electric-pair-mode 1)
          (crazy-mode 1)))

License

Written in 2022 by Mohammed Sadiq <sadiq@sadiqpk.org>

To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see the license online.