GithubHelp home page GithubHelp logo

romanab / god-mode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emacsorphanage/god-mode

0.0 1.0 0.0 663 KB

Global minor mode for entering Emacs commands without modifier keys

License: GNU General Public License v2.0

Emacs Lisp 75.33% Gherkin 24.67%

god-mode's Introduction

God Mode — no more RSI

NOTE: Emacs 24.3 is required for this package to work well!

This is a global minor mode for entering Emacs commands without modifier keys. It's similar to Vim's separation of commands and insertion mode.

Example

In the example below you can see how much effort is reduced:

Before: C-p C-k C-n M-^ ) C-j C-y M-r C-x z z M-2 M-g M-g C-x C-s
After:    p   k   n g ^ )   j   y g r     . .   2   g   g   x   s

(Regarding . see nice keybindings section.)

You'll find that this mode comes surprisingly naturally and that you already know how to run your existing Emacs commands.

See the Mapping section for a complete rundown of the transformations.

Activation

Load it up:

(require 'god-mode)

Activate for all future buffers by running M-x god-mode. Although the activation is buffer-local.

Toggle between God mode and non-God mode using ESC:

(global-set-key (kbd "<escape>") 'god-local-mode)

If you want to enable/disable on all active and future buffers, use this:

(global-set-key (kbd "<escape>") 'god-mode-all)

If you are using the global mode, you might want to make no buffers exempt:

(setq god-exempt-major-modes nil)
(setq god-exempt-predicates nil)

This means that e.g. magit-mode or dired-mode will also enter god-mode when you activate it globally, and vise-verse. It means you can always reliably use god-mode commands in any buffer as long as it is globally activated.

Also, you can add this to your .xmodmap to rebind Caps Lock to Escape:

remove Lock = Caps_Lock
keysym Caps_Lock = Escape

And run xmodmap .xmodmap for the changes to take effect immediately.

Or use dconf:

dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']"

See here for more details.

Mapping

This library defines the following mapping:

  • All commands are assumed to be C-<something> unless otherwise indicated. Examples:

    • aC-a
    • sC-s
    • aknyC-a C-k C-n C-y
    • xsC-x C-s
    • x sC-x s

    Note the use of space to produce C-x s.

  • g is a special key to indicate M-<something>. This means that there is no way to write C-g in this mode, you must therefore type C-g directly. Examples:

    • gfM-f
    • gxM-x
  • G is a special key to indicate C-M-<something>. Example:

    • GxC-M-x
  • Digit arguments:

    • 12fM-12 C-f
  • Repetition (with . keybinding):

    • gf..M-f M-f M-f
  • Universal boolean argument:

    • ucoC-u C-c C-o

Cursor style to indicate mode

You can change the cursor style indicate whether you're in God mode or not.

(defun my-update-cursor ()
  (setq cursor-type (if (or god-local-mode buffer-read-only)
                        'box
                      'bar)))

(add-hook 'god-mode-enabled-hook 'my-update-cursor)
(add-hook 'god-mode-disabled-hook 'my-update-cursor)

Change modeline color

You can use the following function to switch the entire modeline's foreground and background:

(defun c/god-mode-update-cursor ()
  (let ((limited-colors-p (> 257 (length (defined-colors)))))
    (cond (god-local-mode (progn
                            (set-face-background 'mode-line (if limited-colors-p "white" "#e9e2cb"))
                            (set-face-background 'mode-line-inactive (if limited-colors-p "white" "#e9e2cb"))))
          (t (progn
               (set-face-background 'mode-line (if limited-colors-p "black" "#0a2832"))
               (set-face-background 'mode-line-inactive (if limited-colors-p "black" "#0a2832")))))))

Overwrite mode

You can pause god-mode when overwrite-mode is enabled and resume when overwrite-mode is disabled.

(defun god-toggle-on-overwrite ()
  "Toggle god-mode on overwrite-mode."
  (if (bound-and-true-p overwrite-mode)
      (god-local-mode-pause)
    (god-local-mode-resume)))

(add-hook 'overwrite-mode-hook 'god-toggle-on-overwrite)

isearch integration

There is a small module for providing god-mode-like behaviour for isearch: You can hit while in isearch, for example:

s hello <escape> s s s RET

For

C-s hello C-s C-s C-s RET

Activate and configure with the following:

(require 'god-mode-isearch)
(define-key isearch-mode-map (kbd "<escape>") 'god-mode-isearch-activate)
(define-key god-mode-isearch-map (kbd "<escape>") 'god-mode-isearch-disable)

Configure god-mode-isearch-map for additional keybindings.

Using with org-mode fast keys

If you want to use god-mode with fast-keys, you can use a rebinding of self-insert like this:

(define-key god-local-mode-map [remap self-insert-command] 'my-god-mode-self-insert)

(defun my-god-mode-self-insert ()
  (interactive)
  (if (and (bolp)
           (eq major-mode 'org-mode))
      (call-interactively 'org-self-insert-command)
    (call-interactively 'god-mode-self-insert)))

Nice keybindings

The following customizations are popular:

(define-key god-local-mode-map (kbd "z") 'repeat)
(define-key god-local-mode-map (kbd "i") 'god-local-mode)

Although I personally prefer:

(define-key god-local-mode-map (kbd ".") 'repeat)

Feel free to alter and customize as you prefer.

Also handy are these:

(global-set-key (kbd "C-x C-1") 'delete-other-windows)
(global-set-key (kbd "C-x C-2") 'split-window-below)
(global-set-key (kbd "C-x C-3") 'split-window-right)
(global-set-key (kbd "C-x C-0") 'delete-window)

So that you can run x1/x2/x3/x0 in god-mode.

Global god-mode and exempt major modes

Note: This is less necessary in recent god-mode, as god-mode overrides all printable single byte keys, so it will override dired-mode or magit-mode.

If you do M-x god-mode, then all buffers will be started in God mode. If you don't like that behavior, just use the god-local-mode toggler with a keybinding.

Sometimes god-mode is enabled in buffers where it makes no sense. In that case you can add the major mode to god-exempt-major-modes:

(add-to-list 'god-exempt-major-modes 'dired-mode)

Since dired-mode is already in the list, that's a noop, but you get the idea. Consider opening an issue or pull request if you find a major mode that should be on the official list.

Another option to control god-mode's global behavior is to provide a function with no arguments that must return non-nil if god-mode should be disabled for the current buffer. See the god-exempt-predicates variable and its default members god-exempt-mode-p, god-comint-mode-p, god-view-mode-p and god-special-mode-p for further details.

god-mode's People

Contributors

bradwright avatar chrisdone avatar conorbev avatar dillonkearns avatar dragonwasrobot avatar fgallina avatar kyleam avatar magnars avatar proofit404 avatar pyluyten avatar ruediger avatar yangzhao11 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.