Full Code of chrisdone/god-mode for AI

master e6eef24dbf73 cached
20 files
91.8 KB
23.3k tokens
1 requests
Download .txt
Repository: chrisdone/god-mode
Branch: master
Commit: e6eef24dbf73
Files: 20
Total size: 91.8 KB

Directory structure:
gitextract_41c9285x/

├── .github/
│   ├── CONTRIBUTING.md
│   ├── README.md
│   └── workflows/
│       └── test.yml
├── .gitignore
├── Cask
├── LICENSE
├── features/
│   ├── c-commands.feature
│   ├── digit-arguments.feature
│   ├── execute-with-current-bindings.feature
│   ├── insertion-mode.feature
│   ├── last-command-event.feature
│   ├── predicates-disable.feature
│   ├── prefix-arguments.feature
│   ├── prefix-help.feature
│   ├── regions.feature
│   ├── repeat.feature
│   ├── step-definitions/
│   │   └── god-mode-steps.el
│   └── support/
│       └── env.el
├── god-mode-isearch.el
└── god-mode.el

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/CONTRIBUTING.md
================================================
# Contributing

Please write a failing test before submitting pull requests. All new features should be accompanied by new tests.

Tests are written in [Ecukes](https://github.com/ecukes/ecukes), an integration testing framework for Emacs.

## Setup

To fetch the test dependencies, install [cask](https://github.com/cask/cask):

```bash
curl -fsSkL https://raw.github.com/cask/cask/master/go | python
```

then:

```bash
cd /path/to/god-mode
cask
```

Run the tests with:

```bash
cask exec ecukes
```


================================================
FILE: .github/README.md
================================================
# God Mode — no more RSI

[![melpa-badge][melpa-badge]][melpa-link]
[![melpa-stable-badge][melpa-stable-badge]][melpa-stable-link]
[![gh-actions-badge][gh-actions-badge]][gh-actions-link]

_NOTE_: This package requires Emacs 26.3 to work well.

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

All existing key bindings will work in God mode. It's only there to reduce your
usage of modifier keys.

## 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-f C-x C-s
After:    p   k   n g ^ )   j   y g r     . .   2 g f   x   s
```

(Regarding <kbd>.</kbd>, see the [useful key bindings section][useful-key-bindings].)

You'll find this mode surprisingly natural, as you would already know how to use
your existing Emacs commands. Whenever you feel like it, you can explicitly use
modifier keys too.

See the [key mapping section][key-mapping] for a complete walk-through of key
translations.

## Setup

You can load and activate God mode as follows:

```emacs-lisp
(require 'god-mode)
(god-mode)
```

This will activate God mode in all future buffers. However, activation of God
mode itself is buffer-local.

God mode can be toggled through `god-local-mode` using the escape key
(<kbd>ESC</kbd>) as follows:

```emacs-lisp
(global-set-key (kbd "<escape>") #'god-local-mode)
```

If you want to toggle God mode on _all active and future buffers_, use
`god-mode-all` as follows:

```emacs-lisp
(global-set-key (kbd "<escape>") #'god-mode-all)
```

If God mode is activated through `god-mode` or `god-mode-all`, you might want to
ensure that no buffers are skipped, as follows:

```emacs-lisp
(setq god-exempt-major-modes nil)
(setq god-exempt-predicates nil)
```

This means that `magit-mode` or `dired-mode`, for example, will also enter God
mode when you activate it in all buffers. This means you can always reliably use
God mode commands in any buffer.

When God mode is enabled, entering function keys will be translated to use
appropriate key modifiers. For example, entering <kbd>&lt;f5></kbd> is
translated to <kbd>C-&lt;f5></kbd>. To disable this translation, you can set the
`god-mode-enable-function-key-translation` variable to `nil` before loading God
mode, as follows:

``` emacs-lisp
(setq god-mode-enable-function-key-translation nil)
(require 'god-mode)
```

Also, you can add this to your `.xmodmap` to rebind the caps lock key to the
escape key:

```
remove Lock = Caps_Lock
keysym Caps_Lock = Escape
```

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

Or use `dconf`:

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

See [this link][switch-caps-lock-and-esc] for more details.

## Key mapping

This package defines the following key mappings:

* All commands are assumed to use the control modifier (<kbd>C-</kbd>) unless 
  otherwise indicated. Here are some examples:

   * <kbd>x</kbd> → <kbd>C-x</kbd>
   * <kbd>f</kbd> → <kbd>C-f</kbd>
   * <kbd>x</kbd> <kbd>s</kbd> → <kbd>C-x</kbd> <kbd>C-s</kbd>
   * <kbd>x</kbd> <kbd>SPC</kbd> <kbd>s</kbd> → <kbd>C-x</kbd> <kbd>s</kbd>

   Note the use of the space key (<kbd>SPC</kbd>)
   to produce <kbd>C-x</kbd> <kbd>s</kbd>.

* The literal key (<kbd>SPC</kbd>) is sticky. This means you don't have to enter 
  <kbd>SPC</kbd> repeatedly for key bindings such as <kbd>C-x</kbd> <kbd>r</kbd> <kbd>t</kbd>.
  Entering the literal key again toggles its state.
  The literal key can be changed through `god-literal-key`. Here are some examples:
  
   * <kbd>x</kbd> <kbd>SPC</kbd> <kbd>r</kbd> <kbd>t</kbd> → <kbd>C-x</kbd> <kbd>r</kbd> <kbd>t</kbd>
   * <kbd>x</kbd> <kbd>SPC</kbd> <kbd>r</kbd> <kbd>SPC</kbd> <kbd>g</kbd> <kbd>w</kbd> → <kbd>C-x</kbd> <kbd>r</kbd> <kbd>M-w</kbd>

* <kbd>g</kbd> is used to indicate the meta modifier (<kbd>M-</kbd>). This means
  that there is no way to enter <kbd>C-g</kbd> in God mode, and you must
  therefore type in <kbd>C-g</kbd> directly. This key can be changed through
  `god-mode-alist`. Here are some examples:

   * <kbd>g</kbd> <kbd>x</kbd> → <kbd>M-x</kbd>
   * <kbd>g</kbd> <kbd>f</kbd> → <kbd>M-f</kbd>

* <kbd>G</kbd> is used to indicate both the control and meta modifiers
  (<kbd>C-M-</kbd>). This key can also be changed through `god-mode-alist`. Here
  are some examples:

   * <kbd>G</kbd> <kbd>x</kbd> → <kbd>C-M-x</kbd>
   * <kbd>G</kbd> <kbd>f</kbd> → <kbd>C-M-f</kbd>

* Digit arguments can also be used:

  * <kbd>1</kbd> <kbd>2</kbd> <kbd>f</kbd> → <kbd>M-12</kbd> <kbd>C-f</kbd>

* If you use some of the [useful key bindings][useful-key-bindings],
  <kbd>z</kbd> or <kbd>.</kbd> can repeat the previous command:

  * <kbd>g</kbd> <kbd>f</kbd> <kbd>.</kbd> <kbd>.</kbd> → <kbd>M-f</kbd>
    <kbd>M-f</kbd> <kbd>M-f</kbd>

* Universal arguments can also be specified using <kbd>u</kbd>:

  * <kbd>u</kbd> <kbd>c</kbd> <kbd>o</kbd> → <kbd>C-u</kbd> <kbd>C-c</kbd>
    <kbd>C-o</kbd>

## 	Lookup a key sequence
You can use `god-mode-describe-key` to check what command would be triggered by particular keys. This function works similarly to `describe-key`: it prompts for a key combination, translates it into a command, and display its information in the Help buffer.

By default, `god-mode-describe-key` is bound to `C-h k` in `god-local-mode-map`.

Note that `god-mode-describe-key` is only able to interpret key-bindings that are specific to `god-mode`. For other key-bindings, mouse-clicks, and menu items, it's better to use `describe-key`.

## Visual indicators for God mode

God mode allows you to customize its minor mode lighter by customizing the `god-mode-lighter-string` variable and the `god-mode-lighter` face.
For example, if you don't want any lighter, you can set the string to nil.
On the other hand, if you want the lighter to stand out, you can change the face, e.g. by making it inherit from `error`.
You can do this using `M-x customize-face RET god-mode-lighter` or as follows:

```emacs-lisp
(custom-set-faces
 '(god-mode-lighter ((t (:inherit error)))))
```

Additionally, you can change the cursor style to visually indicate whether God mode is active
as follows:

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

(add-hook 'post-command-hook #'my-god-mode-update-cursor-type)
```

You can also change the foreground and background of the mode line to indicate
whether God mode is active as follows:

```emacs-lisp
(defun my-god-mode-update-mode-line ()
  (cond
   (god-local-mode
    (set-face-attribute 'mode-line nil
                        :foreground "#604000"
                        :background "#fff29a")
    (set-face-attribute 'mode-line-inactive nil
                        :foreground "#3f3000"
                        :background "#fff3da"))
   (t
    (set-face-attribute 'mode-line nil
			:foreground "#0a0a0a"
			:background "#d7d7d7")
    (set-face-attribute 'mode-line-inactive nil
			:foreground "#404148"
			:background "#efefef"))))

(add-hook 'post-command-hook #'my-god-mode-update-mode-line)
```

Note that using `post-command-hook` here should not be an issue for performance.
If you are concerned about performance for any reason, you can use
`god-mode-enabled-hook` and `god-mode-disabled-hook`.
With Emacs 27.1+, you can also use [window hooks][window-hooks].


## `overwrite-mode`

You can pause or resume God mode depending on whether `overwrite-mode` is
activated as follows:

```emacs-lisp
(defun my-god-mode-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 #'my-god-mode-toggle-on-overwrite)
```

## `isearch` integration

There is an optional feature for providing God mode behaviour in `isearch`. It
allows you to hit <kbd>ESC</kbd>, for example, while in `isearch` to enable God
mode. Here's a more complete example:

<kbd>s</kbd> <kbd>h</kbd> <kbd>e</kbd> <kbd>y</kbd> <kbd>ESC</kbd> 
<kbd>s</kbd> <kbd>s</kbd> <kbd>s</kbd> <kbd>RET</kbd> → <kbd>C-s</kbd>
<kbd>h</kbd> <kbd>e</kbd> <kbd>y</kbd> <kbd>C-s</kbd> <kbd>C-s</kbd>
<kbd>C-s</kbd> <kbd>RET</kbd>

You can load and activate this feature as follows:

```emacs-lisp
(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)
```

You can also configure `god-mode-isearch-map` for additional keybindings.

## Rebinding `self-insert-command`

You can rebind `self-insert-command` as you prefer. For example, here's a
mapping that calls `org-self-insert-command` in `org-mode`:

```emacs-lisp
(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)))

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

## Useful key bindings

For vim refugees, consider using `i` and `<escape>` to toggle god-mode off and
on:

```emacs-lisp
(define-key god-local-mode-map (kbd "i") #'god-local-mode)
(global-set-key (kbd "<escape>") #'(lambda () (interactive) (god-local-mode 1)))
```

The following key binding is also popular:

```emacs-lisp
(define-key god-local-mode-map (kbd "z") #'repeat)
```

Although I personally prefer:

```emacs-lisp
(define-key god-local-mode-map (kbd ".") #'repeat)
```

These are also handy:

```emacs-lisp
(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)

(define-key god-local-mode-map (kbd "[") #'backward-paragraph)
(define-key god-local-mode-map (kbd "]") #'forward-paragraph)
```

So that you can run <kbd>x</kbd> <kbd>1</kbd>, <kbd>x</kbd>
<kbd>2</kbd>, <kbd>x</kbd> <kbd>3</kbd>, and <kbd>x</kbd> <kbd>0</kbd> in God mode.

## Exempt major modes

_NOTE_: This is less necessary in recent versions of God mode, as
it overrides all printable single byte keys and bindings in 
most major modes.

Sometimes, God mode is enabled in buffers where it makes no sense. In
such cases, you can add the major mode to `god-exempt-major-modes`:

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

Since `dired-mode` is already in the list, that's a no-op, 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 the behavior of God mode in new buffers is to provide
a function with no arguments that must return non-nil if God mode should be
disabled in 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.

## Usage with Evil

[Evil][evil] is a popular Emacs package that provides modal editing in the style
of Vi. While Evil doesn't always work well with God mode, there are a few simple
customizations that enable them to be used together smoothly.

* For running occasional and single commands in God mode, the built-in
  `god-execute-with-current-bindings` command works well with Evil without
  additional customization. This is quite similar to Evil's
  `evil-execute-in-emacs-state` command. All Evil bindings remain available when
  using `god-execute-with-current-bindings`. For example, executing
  `god-execute-with-current-bindings` and entering <kbd>v</kbd> will execute
  `evil-visual-block`, which is bound to <kbd>C-v</kbd> in Evil's Normal state.

* For sustained usage of God mode, it's a bit trickier as keybindings in Evil
  states generally override God mode. For example, if God mode is activated in
  Normal state, entering <kbd>v</kbd> executes `evil-visual-char`, which is
  bound to <kbd>v</kbd> in Normal state, instead of executing
  `evil-visual-block`. A good option to use Evil's state-specific keybindings
  through God mode is to create an intercept keymap using
  `evil-make-intercept-map` and `god-local-mode-map`. For example, you can
  enable use of God mode in Normal state as follows:

  ```emacs-lisp
  (with-eval-after-load 'god-mode
    (evil-make-intercept-map god-local-mode-map 'normal)
    (add-hook 'god-local-mode-hook #'evil-normalize-keymaps))
  ```

* Another option to use God mode with Evil is to use the
  [`evil-god-state`][evil-god-state] package, which provides a dedicated Evil
  state for using God mode. For running occasional, single commands through God
  mode, use the `evil-execute-in-god-state` command. This works similar to
  `god-execute-with-current-bindings`. For sustained use of God mode, use the
  `evil-god-state` command. `evil-god-state` is also useful for accessing
  default Emacs keybindings through God mode. However, a disadvantage of
  `evil-god-state` is that Evil's state-specific keybindings will not be
  available in God mode.
 
* [`evil-god-toggle`][evil-god-toggle] is an expanded version of
  `evil-god-state` with features like persistence of visual selections
  to corresponding active regions, global `god-mode` scope, and a
  `god-off` which is like `emacs-state` but more easy to toggle in and
  out of.  The ability to use a persistent `god-state` is also better
  documented.

[useful-key-bindings]: #useful-key-bindings
[key-mapping]: #key-mapping
[switch-caps-lock-and-esc]: https://askubuntu.com/questions/363346/how-to-permanently-switch-caps-lock-and-esc
[melpa-link]: https://melpa.org/#/god-mode
[melpa-stable-link]: https://stable.melpa.org/#/god-mode
[melpa-badge]: https://melpa.org/packages/god-mode-badge.svg
[melpa-stable-badge]: https://stable.melpa.org/packages/god-mode-badge.svg
[gh-actions-link]: https://github.com/emacsorphanage/god-mode/actions?query=workflow%3ACI+branch%3Amaster
[gh-actions-badge]: https://github.com/emacsorphanage/god-mode/actions/workflows/test.yml/badge.svg?branch=master
[evil]: https://github.com/emacs-evil/evil
[evil-god-state]: https://github.com/gridaphobe/evil-god-state
[evil-god-toggle]: https://github.com/jam1015/evil-god-toggle
[window-hooks]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Window-Hooks.html


================================================
FILE: .github/workflows/test.yml
================================================
name: CI

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        emacs_version:
          - 26.3
          - 27.2
          - 28.1
          - 28.2
          - 29.1
          - 29.2
          - 29.3
          - 29.4
          - 30.1
          - snapshot
        include:
          - emacs_version: snapshot
            allow_failure: true
    steps:
    - uses: purcell/setup-emacs@master
      with:
        version: ${{ matrix.emacs_version }}
    - uses: actions/checkout@v1
    - uses: conao3/setup-cask@master
      if: steps.cache-cask-executable.outputs.cache-hit != 'true'
      with:
        version: snapshot
    - name: Install dependencies
      run: 'cask install'
    - name: Run tests
      if: matrix.allow_failure != true
      run: 'cask exec ecukes'
    - name: Run tests (allow failure)
      if: matrix.allow_failure == true
      run: 'cask exec ecukes || true'


================================================
FILE: .gitignore
================================================
.cask
.ecukes-failing-scenarios
*.elc


================================================
FILE: Cask
================================================
(source gnu)
(source melpa)

(package "god-mode" "2.19.0" "God-like command entering minor mode.")

(development
 (depends-on "ecukes")
 (depends-on "ansi"))


================================================
FILE: LICENSE
================================================
                    GNU GENERAL PUBLIC LICENSE
                       Version 3, 29 June 2007

 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The GNU General Public License is a free, copyleft license for
software and other kinds of works.

  The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.  We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors.  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

  To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights.  Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received.  You must make sure that they, too, receive
or can get the source code.  And you must show them these terms so they
know their rights.

  Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.

  For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software.  For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.

  Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so.  This is fundamentally incompatible with the aim of
protecting users' freedom to change the software.  The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable.  Therefore, we
have designed this version of the GPL to prohibit the practice for those
products.  If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.

  Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary.  To prevent this, the GPL assures that
patents cannot be used to render the program non-free.

  The precise terms and conditions for copying, distribution and
modification follow.

                       TERMS AND CONDITIONS

  0. Definitions.

  "This License" refers to version 3 of the GNU General Public License.

  "Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.

  "The Program" refers to any copyrightable work licensed under this
License.  Each licensee is addressed as "you".  "Licensees" and
"recipients" may be individuals or organizations.

  To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy.  The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.

  A "covered work" means either the unmodified Program or a work based
on the Program.

  To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy.  Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.

  To "convey" a work means any kind of propagation that enables other
parties to make or receive copies.  Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.

  An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License.  If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.

  1. Source Code.

  The "source code" for a work means the preferred form of the work
for making modifications to it.  "Object code" means any non-source
form of a work.

  A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.

  The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form.  A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.

  The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities.  However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work.  For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.

  The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.

  The Corresponding Source for a work in source code form is that
same work.

  2. Basic Permissions.

  All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met.  This License explicitly affirms your unlimited
permission to run the unmodified Program.  The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work.  This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.

  You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force.  You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright.  Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.

  4. Conveying Verbatim Copies.

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.

  You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.

  5. Conveying Modified Source Versions.

  You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:

    a) The work must carry prominent notices stating that you modified
    it, and giving a relevant date.

    b) The work must carry prominent notices stating that it is
    released under this License and any conditions added under section
    7.  This requirement modifies the requirement in section 4 to
    "keep intact all notices".

    c) You must license the entire work, as a whole, under this
    License to anyone who comes into possession of a copy.  This
    License will therefore apply, along with any applicable section 7
    additional terms, to the whole of the work, and all its parts,
    regardless of how they are packaged.  This License gives no
    permission to license the work in any other way, but it does not
    invalidate such permission if you have separately received it.

    d) If the work has interactive user interfaces, each must display
    Appropriate Legal Notices; however, if the Program has interactive
    interfaces that do not display Appropriate Legal Notices, your
    work need not make them do so.

  A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit.  Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.

  6. Conveying Non-Source Forms.

  You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:

    a) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by the
    Corresponding Source fixed on a durable physical medium
    customarily used for software interchange.

    b) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by a
    written offer, valid for at least three years and valid for as
    long as you offer spare parts or customer support for that product
    model, to give anyone who possesses the object code either (1) a
    copy of the Corresponding Source for all the software in the
    product that is covered by this License, on a durable physical
    medium customarily used for software interchange, for a price no
    more than your reasonable cost of physically performing this
    conveying of source, or (2) access to copy the
    Corresponding Source from a network server at no charge.

    c) Convey individual copies of the object code with a copy of the
    written offer to provide the Corresponding Source.  This
    alternative is allowed only occasionally and noncommercially, and
    only if you received the object code with such an offer, in accord
    with subsection 6b.

    d) Convey the object code by offering access from a designated
    place (gratis or for a charge), and offer equivalent access to the
    Corresponding Source in the same way through the same place at no
    further charge.  You need not require recipients to copy the
    Corresponding Source along with the object code.  If the place to
    copy the object code is a network server, the Corresponding Source
    may be on a different server (operated by you or a third party)
    that supports equivalent copying facilities, provided you maintain
    clear directions next to the object code saying where to find the
    Corresponding Source.  Regardless of what server hosts the
    Corresponding Source, you remain obligated to ensure that it is
    available for as long as needed to satisfy these requirements.

    e) Convey the object code using peer-to-peer transmission, provided
    you inform other peers where the object code and Corresponding
    Source of the work are being offered to the general public at no
    charge under subsection 6d.

  A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.

  A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling.  In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage.  For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product.  A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.

  "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source.  The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.

  If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information.  But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).

  The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed.  Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.

  Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.

  7. Additional Terms.

  "Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law.  If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.

  When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it.  (Additional permissions may be written to require their own
removal in certain cases when you modify the work.)  You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.

  Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:

    a) Disclaiming warranty or limiting liability differently from the
    terms of sections 15 and 16 of this License; or

    b) Requiring preservation of specified reasonable legal notices or
    author attributions in that material or in the Appropriate Legal
    Notices displayed by works containing it; or

    c) Prohibiting misrepresentation of the origin of that material, or
    requiring that modified versions of such material be marked in
    reasonable ways as different from the original version; or

    d) Limiting the use for publicity purposes of names of licensors or
    authors of the material; or

    e) Declining to grant rights under trademark law for use of some
    trade names, trademarks, or service marks; or

    f) Requiring indemnification of licensors and authors of that
    material by anyone who conveys the material (or modified versions of
    it) with contractual assumptions of liability to the recipient, for
    any liability that these contractual assumptions directly impose on
    those licensors and authors.

  All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10.  If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term.  If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.

  If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.

  Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.

  8. Termination.

  You may not propagate or modify a covered work except as expressly
provided under this License.  Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).

  However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.

  Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

  Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.

  9. Acceptance Not Required for Having Copies.

  You are not required to accept this License in order to receive or
run a copy of the Program.  Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance.  However,
nothing other than this License grants you permission to propagate or
modify any covered work.  These actions infringe copyright if you do
not accept this License.  Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.

  10. Automatic Licensing of Downstream Recipients.

  Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License.  You are not responsible
for enforcing compliance by third parties with this License.

  An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations.  If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.

  You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License.  For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.

  11. Patents.

  A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based.  The
work thus licensed is called the contributor's "contributor version".

  A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version.  For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.

  Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.

  In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement).  To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.

  If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients.  "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.

  If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.

  A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License.  You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.

  Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.

  12. No Surrender of Others' Freedom.

  If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all.  For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.

  13. Use with the GNU Affero General Public License.

  Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work.  The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.

  14. Revised Versions of this License.

  The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

  Each version is given a distinguishing version number.  If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation.  If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.

  If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.

  Later license versions may give you additional or different
permissions.  However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.

  15. Disclaimer of Warranty.

  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. Limitation of Liability.

  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.

  17. Interpretation of Sections 15 and 16.

  If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

  If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

    <program>  Copyright (C) <year>  <name of author>
    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".

  You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.

  The GNU General Public License does not permit incorporating your program
into proprietary programs.  If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.  But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.


================================================
FILE: features/c-commands.feature
================================================
Feature: C- commands
  Background:
    Given I am in buffer "god-mode-test"
    And the buffer is empty
    And I insert:
    """
    laziness
    impatience
    hubris
    """
    Then I have god-mode on

  Scenario: map k into kill-line
    Given I go to line "1"
    When I send the key sequence "kk"
    Then the buffer's contents should be:
    """
    impatience
    hubris
    """

  Scenario: map / into undo
    Given I go to line "1"
    And I send the key sequence "kk"
    When I send the key sequence "//"
    Then the buffer's contents should be:
    """
    laziness
    impatience
    hubris
    """

  Scenario: execute named keyboard macro
    Given I go to line "1"
    And I bind a named keyboard macro which kills line to C-c C-r
    When I send the key sequence "cr"
    Then the buffer's contents should be:
    """
    impatience
    hubris
    """

  Scenario: execute C-[god-literal-key]
    Given I bind "C-SPC" to "set-mark-command"
    And I go to beginning of buffer
    And I send the key sequence "SPC"
    And I go to end of buffer
    When I send the key sequence "u SPC"
    Then the cursor should be at point "1"

  Scenario: execute long sequence of literals
    Given I bind "C-c b e g" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c SPC b e g"
    Then the cursor should be at point "1"

  Scenario: toggle god-literal-key
    Given I bind "C-c k M-l" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c SPC k SPC g l"
    Then the cursor should be at point "1"

  Scenario: toggle god-literal-key (sticky)
    Given I bind "C-c k l" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c SPC k l"
    Then the cursor should be at point "1"

  Scenario: execute commands with C-arrow
    Given I bind "C-x C-<left>" to "backward-word"
    And I go to line "1"
    And I go to end of line
    When I send the key sequence "x <left>"
    Then the cursor should be at point "1"

  Scenario: execute commands with uppercase letters (control)
    Given I bind "C-S-A" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "A"
    Then the cursor should be at point "1"

  Scenario: execute commands with uppercase letters (control+meta)
    Given I bind "C-M-S-A" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "GA"
    Then the cursor should be at point "1"

  Scenario: execute commands with uppercase letters (meta)
    Given I bind "M-A" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "g A"
    Then the cursor should be at point "1"

  Scenario: execute commands with uppercase letters (combination)
    Given I bind "C-x C-S-A" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "xA"
    Then the cursor should be at point "1"

  Scenario: execute commands with uppercase letters (literal)
    Given I bind "C-c L" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c SPC L"
    Then the cursor should be at point "1"

  Scenario: execute commands with delete (control)
    Given I bind "C-c C-<delete>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c <delete>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shifted arrows (control)
    Given I bind "C-x C-S-<left>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "x S-<left>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shifted arrows (meta)
    Given I bind "M-S-<left>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "g S-<left>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shifted arrows (shift)
    Given I bind "C-c C-S-<left>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c S-<left>"
    Then the cursor should be at point "1"

  Scenario: execute commands with numbered function keys (literal)
    Given I bind "C-c <f12>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c SPC <f12>"
    Then the cursor should be at point "1"

  Scenario: execute commands with numbered function keys (control)
    Given I bind "C-c C-<f12>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c <f12>"
    Then the cursor should be at point "1"

  Scenario: execute commands with numbered function keys (meta)
    Given I bind "C-c M-<f12>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c g <f12>"
    Then the cursor should be at point "1"

  Scenario: execute commands with numbered function keys (control+shift)
    Given I bind "C-c C-S-<f12>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c S-<f12>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and space (control+shift)
    Given I bind "C-c C-S-SPC" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c S-SPC"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and return (control+shift)
    Given I bind "C-c C-S-<return>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c <S-return>"
    Then the cursor should be at point "1"

  Scenario: execute commands with fallback lookup
    Given I bind "C-c a" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c a"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and tab (control+shift)
    Given I bind "C-c C-S-<iso-lefttab>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c <S-iso-lefttab>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and backspace (control+shift)
    Given I bind "C-c C-S-<backspace>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c <S-backspace>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and delete (control+shift)
    Given I bind "C-c C-S-<delete>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "c <S-delete>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and space (meta+shift)
    Given I bind "M-S-SPC" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "g S-SPC"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and return (meta+shift)
    Given I bind "M-S-<return>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "g S-<return>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and tab (meta+shift)
    Given I bind "M-S-<iso-lefttab>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "g <S-iso-lefttab>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and backspace (meta+shift)
    Given I bind "M-S-<backspace>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "g S-<backspace>"
    Then the cursor should be at point "1"

  Scenario: execute commands with shift and backspace (meta+shift)
    Given I bind "M-S-<delete>" to "beginning-of-buffer"
    And I go to end of buffer
    When I send the key sequence "g S-<delete>"
    Then the cursor should be at point "1"


================================================
FILE: features/digit-arguments.feature
================================================
Feature: Digit arguments
  Background:
    Given I am in buffer "god-mode-test"
    And the buffer is empty
    And I insert "abcdefghijklmnopqrstuvwxyz"
    And I have god-mode on
    And I go to line "1"

  Scenario: M-5 C-d does delete 5 times
    When I send the key sequence "M-5 C-d"
    Then the buffer's contents should be "fghijklmnopqrstuvwxyz"

  Scenario: 5d does delete 5 times
    When I send the key sequence "5d"
    Then the buffer's contents should be "fghijklmnopqrstuvwxyz"


================================================
FILE: features/execute-with-current-bindings.feature
================================================
Feature: Execute with current bindings
  Background:
    Given I am in buffer "god-mode-test"
    And I bind "C-e" to "god-execute-with-current-bindings"
    And the buffer is empty
    And I insert "abcdefghijkl"
    And I go to beginning of buffer

  Scenario: no effect when already in God mode
    Given I have god-mode on
    When I send the key sequence "C-e q Z"
    Then the buffer's contents should be "Zabcdefghijkl"
    And god-mode is enabled
    
  Scenario: runs one command in God mode
    Given I am in insertion mode
    When I send the key sequence "C-e q Z"
    Then the buffer's contents should be "Zabcdefghijkl"
    And god-mode is disabled

  Scenario: handles prefix arguments
    Given I am in insertion mode
    When I send the key sequence "C-u 1 C-e 0 f"
    Then the cursor should be at point "11"


================================================
FILE: features/insertion-mode.feature
================================================
Feature: Insertion mode
  Background:
    Given I am in buffer "god-mode-test"
    And the buffer is empty
    And I am in insertion mode

  Scenario: C-u u inserts u 4 times
    When I send the key sequence "C-u u"
    Then the buffer's contents should be "uuuu"

  Scenario: C-u C-u u inserts u 16 times
    When I send the key sequence "C-u C-u u"
    Then the buffer's contents should be "uuuuuuuuuuuuuuuu"


================================================
FILE: features/last-command-event.feature
================================================
Feature: Prefix arguments
  Background:
    Given I am in buffer "god-mode-test"
    And the buffer is empty
    And I insert "abcdefghijklmnopqrstuvwxyz"
    And I have god-mode on
    And I go to line "1"

  Scenario: M-4 C-d does delete 4 times
    When I send the key sequence "M-4 C-d"
    Then the buffer's contents should be "efghijklmnopqrstuvwxyz"

  Scenario: g4d does delete 4 times
    When I send the key sequence "g4d"
    Then the buffer's contents should be "efghijklmnopqrstuvwxyz"


================================================
FILE: features/predicates-disable.feature
================================================
Feature: Predicate based disable
  Background:
    Given god-mode is enabled for all buffers
    And I am in buffer "god-mode-test"
    And I describe function "god-mode"
    And I grep current directory
    And I start ielm

  Scenario: God mode is automatically enabled for fundamental-mode
    When I switch to buffer "god-mode-test"
    Then god-mode is enabled

  Scenario: God mode is disabled for help-mode (a special derived mode)
    When I switch to buffer "*Help*"
    Then god-mode is disabled

  Scenario: God mode is disabled for grep-mode (an explicitly disabled mode)
    When I switch to buffer "*grep*"
    Then god-mode is disabled

  Scenario: God mode is disabled in buffers with view-mode
    When I open a view-mode buffer
    Then god-mode is disabled

  Scenario: God mode is disabled in comint derived buffers
    When I switch to buffer "*ielm*"
    Then god-mode is disabled

  Scenario: God mode is disabled in mode-class special buffers
    When I open a test-special-mode buffer
    Then god-mode is disabled


================================================
FILE: features/prefix-arguments.feature
================================================
Feature: Prefix arguments
  Background:
    Given I am in buffer "god-mode-test"
    And the buffer is empty
    And I insert "abcdefghijklmnopqrstuvwxyz"
    And I have god-mode on
    And I go to line "1"

  Scenario: C-u C-d does delete 4 times
    When I send the key sequence "C-u C-d"
    Then the buffer's contents should be "efghijklmnopqrstuvwxyz"

  Scenario: ud does delete 4 times
    When I send the key sequence "ud"
    Then the buffer's contents should be "efghijklmnopqrstuvwxyz"

  Scenario: C-u C-u C-d does delete 16 times
    When I send the key sequence "C-u C-u C-d"
    Then the buffer's contents should be "qrstuvwxyz"

  Scenario: uud does delete 16 times
    When I send the key sequence "uud"
    Then the buffer's contents should be "qrstuvwxyz"


================================================
FILE: features/prefix-help.feature
================================================
Feature: Prefix help
  Background:
    Given I am in buffer "god-mode-test"
    And the buffer is empty
    And I have god-mode on
    And I bind "C-c C-e" to "end-of-line"
    And I bind "M-s C-e" to "end-of-line"

  Scenario: shows help on entering C-h (control)
    When I send the key sequence "C-c C-h"
    Then there is a "*Help*" buffer

  Scenario: help buffer shows relevant bindings (control)
    Given I send the key sequence "C-c C-h"
    When I switch to buffer "*Help*"
    Then the buffer's contents should contain "Major Mode Bindings Starting With C-c:"
    And the buffer's contents should contain "Global Bindings Starting With C-c:"

  Scenario: shows help on entering C-h (meta)
    When I send the key sequence "M-s C-h"
    Then there is a "*Help*" buffer

  Scenario: help buffer shows relevant bindings (meta)
    Given I send the key sequence "M-s C-h"
    When I switch to buffer "*Help*"
    Then the buffer's contents should contain "Major Mode Bindings Starting With M-s:"
    And the buffer's contents should contain "Global Bindings Starting With M-s:"


================================================
FILE: features/regions.feature
================================================
Feature: Regions
  Background:
    Given I am in buffer "god-mode-test"
    And the buffer is empty
    And I insert "Here we go"
    And I have god-mode on
    And I go to beginning of buffer
    And I set the mark

  Scenario: mark is preserved (control)
    When I send the key sequence "f"
    Then the region should be "H"

  Scenario: mark is preserved (meta)
    When I send the key sequence "gf"
    Then the region should be "Here"

  Scenario: mark is preserved (control+meta)
    When I send the key sequence "gfGf"
    Then the region should be "Here we"


================================================
FILE: features/repeat.feature
================================================
Feature: Repeat
  Background:
    Given I am in buffer "god-mode-test"
    And the buffer is empty
    And I insert "abcdefghijklmnopqrstuvwxyz one two three"
    And I have god-mode on
    And I go to line "1"

  Scenario: M-5 C-d C-x z does delete 5 times then 5 more times
    When I send the key sequence "M-5 C-d C-x z"
    Then the buffer's contents should be "klmnopqrstuvwxyz one two three"

  Scenario: 5dx z does delete 5 times then 5 more times
    When I send the key sequence "5dx SPC z"
    Then the buffer's contents should be "klmnopqrstuvwxyz one two three"

  Scenario: M-f C-x z M-d deletes the second word
    When I send the key sequence "M-f C-x z M-d"
    Then the buffer's contents should be "abcdefghijklmnopqrstuvwxyz one three"

  Scenario: gfx zgd deletes the second word
    When I send the key sequence "gfx SPC zgd"
    Then the buffer's contents should be "abcdefghijklmnopqrstuvwxyz one three"


================================================
FILE: features/step-definitions/god-mode-steps.el
================================================
;; This file contains your project specific step definitions. All
;; files in this directory whose names end with "-steps.el" will be
;; loaded automatically by Ecukes.

(require 'seq)

(Given "^I bind a named keyboard macro which kills line to C-c C-r$"
       (lambda ()
         (fset 'god-mode-test-keyboard-macro
               "\C-a\C-k\C-k")
         (global-set-key (kbd "C-c C-r") 'god-mode-test-keyboard-macro)))

(Given "^I bind \"\\([^\"]+\\)\" to \"\\([^\"]+\\)\""
       (lambda (key cmd)
         (local-set-key (kbd key) (intern cmd))))

(Given "^god-mode is enabled for all buffers$"
       (lambda ()
         (when (not god-global-mode)
           (god-mode))))

(Given "^I describe function \"\\(.+\\)\"$"
       (lambda (fn)
         (describe-function (intern fn))))

(Given "^I grep current directory"
       (lambda ()
         (set-process-query-on-exit-flag
          (get-buffer-process (grep "grep -Rin god ."))
          nil)))

(Given "^I open a view-mode buffer"
       (lambda ()
         (set-buffer (get-buffer-create "*view-mode-buffer*"))
         (view-mode)
         (god-local-mode 0)
         (god-mode-maybe-activate)))

(Given "^I open a test-special-mode buffer"
       (lambda ()
         (set-buffer (get-buffer-create "*test-special-mode*"))
         (test-special-mode)))

(Given "^I start ielm$"
       (lambda ()
         (require 'ielm)
         (ielm)))

(When "I send the key sequence \"\\(.+\\)\""
      (lambda (keys)
        (execute-kbd-macro (kbd keys))))

(Then "^god-mode is enabled$"
      (lambda ()
        (cl-assert (not (null god-local-mode)))))

(Then "^god-mode is disabled$"
      (lambda ()
        (cl-assert (null god-local-mode))))

(Then "^I have god-mode on$"
      "Turn god-mode on."
      (lambda ()
        (god-local-mode 1)))

(Then "^I am in insertion mode$"
      "Turn god-mode off."
      (lambda ()
        (god-local-mode -1)))

(Then "^there is a \"\\([^\"]+\\)\" buffer$"
      (lambda (name)
        (cl-assert
         (seq-filter (lambda (b) (string-prefix-p name (buffer-name b)))
                     (buffer-list)))))

(Then "^the buffer's contents should be\\(?: \"\\(.+\\)\"\\|:\\)$"
      "Asserts that the current buffer includes some text.

Examples:
 - Then the buffer's contents should be  \"CONTENTS\"
 - Then the buffer's contents should be:
     \"\"\"
     CONTENTS
     \"\"\""
      (lambda (expected)
        (let ((actual (buffer-string))
              (message "Expected buffer's contents to be '%s', but was '%s'"))
          (cl-assert (s-equals? expected actual) nil message expected actual))))

(Then "^the buffer's contents should contain\\(?: \"\\(.+\\)\"\\|:\\)$"
      "Asserts that the current buffer contains some text.

Examples:
 - Then the buffer's contents should contain  \"CONTENTS\"
 - Then the buffer's contents should contain:
     \"\"\"
     CONTENTS
     \"\"\""
      (lambda (expected)
        (let ((actual (buffer-string))
              (message "Expected buffer's contents to contain '%s', but was '%s'"))
          (cl-assert (s-contains? expected actual) nil message expected actual))))


================================================
FILE: features/support/env.el
================================================
(require 'f)
(require 'cl-lib)

(defvar god-mode-support-path
  (f-dirname load-file-name))

(defvar god-mode-features-path
  (f-parent god-mode-support-path))

(defvar god-mode-root-path
  (f-parent god-mode-features-path))

(add-to-list 'load-path god-mode-root-path)

(define-derived-mode test-special-mode fundamental-mode "Test"
  "This mode is marked special via its mode class rather than
through inheritance.")

(put 'test-special-mode 'mode-class 'special)

(require 'god-mode)
(require 'espuds)

(Setup
 ;; Before anything has run
 )

(Before
 ;; Before each scenario is run
 )

(After
 ;; After each scenario is run
 )

(Teardown
 ;; After when everything has been run
 )


================================================
FILE: god-mode-isearch.el
================================================
;;; god-mode-isearch.el --- God mode behaviour for isearch  -*- lexical-binding: t; -*-

;; Copyright (C) 2014 Chris Done
;; Copyright (C) 2020 Akhil Wali

;; Author: Chris Done <chrisdone@gmail.com>
;; URL: https://github.com/emacsorphanage/god-mode
;; Version: 2.19.0
;; Package-Requires: ((emacs "26.3"))

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Global minor mode for entering Emacs commands without modifier keys.

;;; Code:

;; Recommended use:

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

(defvar god-mode-isearch-map
  (let ((map (copy-keymap isearch-mode-map)))
    (define-key map (kbd "s") 'isearch-repeat-forward)
    (define-key map (kbd "r") 'isearch-repeat-backward)
    (define-key map (kbd "w") 'isearch-yank-word-or-char)
    map)
  "Keymap for modal isearch.")

(defun god-mode-isearch-activate ()
  "Activate God mode in the isearch buffer."
  (interactive)
  (setq overriding-terminal-local-map god-mode-isearch-map))

(defun god-mode-isearch-disable ()
  "Deactivate God mode in the isearch buffer."
  (interactive)
  (setq overriding-terminal-local-map isearch-mode-map))

(provide 'god-mode-isearch)

;;; god-mode-isearch.el ends here


================================================
FILE: god-mode.el
================================================
;;; god-mode.el --- Minor mode for God-like command entering  -*- lexical-binding: t; -*-

;; Copyright (C) 2013 Chris Done
;; Copyright (C) 2013 Magnar Sveen
;; Copyright (C) 2013 Rüdiger Sonderfeld
;; Copyright (C) 2013 Dillon Kearns
;; Copyright (C) 2013 Fabián Ezequiel Gallina
;; Copyright (C) 2020 Akhil Wali

;; Author: Chris Done <chrisdone@gmail.com>
;; URL: https://github.com/emacsorphanage/god-mode
;; Version: 2.19.0
;; Package-Requires: ((emacs "26.3"))

;; This file is not part of GNU Emacs.

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; Global minor mode for entering Emacs commands without modifier keys.

;;; Code:

(require 'cl-lib)

(add-hook 'after-change-major-mode-hook 'god-mode-maybe-activate)

(defvar god-local-mode-paused nil)
(make-variable-buffer-local 'god-local-mode-paused)

;; DEPRECATED
(defvaralias 'god-mod-alist 'god-mode-alist
  "Alias of `god-mode-alist' for backward compatibility.
Use `god-mode-alist' instead.")
(make-obsolete 'god-mod-alist 'god-mode-alist "2.16.1")

(defcustom god-mode-alist
  '((nil . "C-")
    ("g" . "M-")
    ("G" . "C-M-"))
  "List of keys and their associated modifer."
  :group 'god
  :type '(alist))

(defcustom god-literal-key
  "SPC"
  "The key used for literal interpretation."
  :group 'god
  :type 'string)

(defcustom god-exempt-major-modes
  '(Custom-mode
    Info-mode
    ag-mode
    calculator-mode
    calendar-mode
    cider-test-report-mode
    compilation-mode
    debugger-mode
    dired-mode
    edebug-mode
    ediff-mode
    eww-mode
    geben-breakpoint-list-mode
    git-commit-mode                     ; For versions prior to Magit 2.1.0
    grep-mode
    ibuffer-mode
    magit-popup-mode
    org-agenda-mode
    pdf-outline-buffer-mode
    recentf-dialog-mode
    sldb-mode
    sly-db-mode
    vc-annotate-mode
    wdired-mode)
  "List of major modes that should not start with `god-local-mode' enabled."
  :group 'god
  :type '(repeat symbol))

(defcustom god-exempt-predicates
  (list #'god-exempt-mode-p
        #'god-comint-mode-p
        #'god-git-commit-mode-p
        #'god-view-mode-p
        #'god-special-mode-p)
  "List of predicates checked before enabling `god-local-mode'.
All predicates must return nil for `god-local-mode' to start."
  :group 'god
  :type '(repeat function))

(defcustom god-mode-enable-function-key-translation t
  "Enables translation of function keys to use modifier keys.
For example, if this variable is non-nil, then entering `<f5>'
in God mode will be translated to `C-<f5>'."
  :group 'god
  :type 'boolean)

(defcustom god-mode-lighter-string
  "God"
  "String displayed on the mode line when God mode is active.
Set it to nil if you don't want a mode line indicator."
  :group 'god
  :type '(choice string (const :tag "None" nil)))

(defface god-mode-lighter
  '((t))
  "Face for God mode's lighter."
  :group 'god)

(defun god-mode-make-f-key (n &optional shift)
  "Get the event for numbered function key N, with shift status SHIFT.
For example, calling with arguments 5 and t yields the symbol `S-f5'."
  (intern (format "%sf%d" (if shift "S-" "") n)))

(defvar god-local-mode-map
  (let ((map (make-sparse-keymap)))
    (suppress-keymap map t)
    (define-key map [remap self-insert-command] 'god-mode-self-insert)
    (let ((i ?\s))
      (while (< i 256)
        (define-key map (vector i) 'god-mode-self-insert)
        (setq i (1+ i))))
    (when god-mode-enable-function-key-translation
      (dotimes (i 35)
        (define-key map (vector (god-mode-make-f-key (1+ i))) 'god-mode-self-insert)
        (define-key map (vector (god-mode-make-f-key (1+ i) t)) 'god-mode-self-insert)))
    (define-key map (kbd "DEL") nil)
    (define-key map (kbd "C-h k") #'god-mode-describe-key)
    map))

;;;###autoload
(define-minor-mode god-local-mode
  "Minor mode for running commands."
  :init-value nil
  :lighter (god-mode-lighter-string
            ((" "
             (:propertize god-mode-lighter-string face god-mode-lighter))))
  :keymap god-local-mode-map
  (if god-local-mode
      (run-hooks 'god-mode-enabled-hook)
    (run-hooks 'god-mode-disabled-hook)))

(defun god-local-mode-pause ()
  "Pause `god-local-mode' if it is enabled.
See also `god-local-mode-resume'."
  (when god-local-mode
    (god-local-mode -1)
    (setq god-local-mode-paused t)))

(defun god-local-mode-resume ()
  "Re-enable `god-local-mode'.
If it was not active when `god-local-mode-pause' was called, nothing happens."
  (when (bound-and-true-p god-local-mode-paused)
    (setq god-local-mode-paused nil)
    (god-local-mode 1)))

(defvar god-global-mode nil
  "Enable `god-local-mode' on all buffers.")

(defvar god-literal-sequence nil
  "Toggled when `god-literal-key' is pressed in a command sequence.")

;;;###autoload
(defun god-mode ()
  "Toggle global `god-local-mode'."
  (interactive)
  (setq god-global-mode (not god-global-mode))
  (if god-global-mode
      (god-local-mode 1)
    (god-local-mode -1)))

;;;###autoload
(defun god-mode-all (&optional arg)
  "Toggle `god-local-mode' in all buffers.

Toggle the mode if ARG is nil. If ARG is non-nil, enable the mode
if ARG is zero or a positive number, or disable the mode if ARG
is a negative number."
  (interactive)
  (let ((new-status
	 (cond
	  ((null arg) (if (bound-and-true-p god-local-mode) -1 1))
	  ((> 0 arg) -1)
	  (t 1))))
    (setq god-global-mode t)
    (mapc (lambda (buffer)
            (with-current-buffer buffer
              (god-mode-activate new-status)))
          (buffer-list))
    (setq god-global-mode (= new-status 1))))

(defun god-mode-maybe-universal-argument-more ()
  "If `god-local-mode' is enabled, call `universal-argument-more'."
  (interactive)
  (if god-local-mode
      (call-interactively #'universal-argument-more)
    (let ((binding (god-mode-lookup-command "u")))
      (if (commandp binding t)
          (call-interactively binding)
        (execute-kbd-macro binding)))))

(define-key universal-argument-map (kbd "u")
  #'god-mode-maybe-universal-argument-more)

(defun god-mode-self-insert ()
  "Handle self-insert keys."
  (interactive)
  (let* ((initial-key (aref (this-command-keys-vector)
                            (- (length (this-command-keys-vector)) 1)))
         (binding (god-mode-lookup-key-sequence initial-key)))
    (when binding
      ;; For now, set the shift-translation status only for alphabetic keys.
      (when (god-mode-upper-p initial-key)
        (setq this-command-keys-shift-translated t))
      (setq this-original-command binding)
      (setq this-command binding)
      ;; `real-this-command' is used by emacs to populate
      ;; `last-repeatable-command', which is used by `repeat'.
      (setq real-this-command binding)
      (setq god-literal-sequence nil)
      (if (commandp binding t)
          (call-interactively binding)
        (execute-kbd-macro binding)))))

(defun god-mode-upper-p (key)
  "Check if KEY is an upper case character not present in `god-mode-alist'."
  (and (characterp key)
       (not (member (char-to-string key) (mapcar #'car god-mode-alist)))
       (>= key ?A)
       (<= key ?Z)))

(defun god-mode-lookup-key-sequence (&optional key key-string-so-far)
  "Lookup the command for the given KEY (or the next keypress, if KEY is nil).
This function sometimes recurses.
KEY-STRING-SO-FAR should be nil for the first call in the sequence."
  (interactive)
  (let ((sanitized-key
         (god-mode-sanitized-key-string
          (or key (read-event key-string-so-far)))))
    (god-mode-lookup-command
     (god-key-string-after-consuming-key sanitized-key key-string-so-far))))

(defvar god-mode-sanitized-key-alist
  (append
   '((tab . "TAB")
     (?\  . "SPC")
     (left . "<left>")
     (right . "<right>")
     (up . "<up>")
     (down . "<down>")
     (prior . "<prior>")
     (next . "<next>")
     (backspace . "DEL")
     ;; FIXME delete key is not picked up `god-mode-self-insert'.
     (delete . "<delete>")
     (return . "RET")
     (S-iso-lefttab . "<S-iso-lefttab>")
     ;; Use key code for S-SPC
     (33554464 . "S-SPC")
     (S-left . "S-<left>")
     (S-right . "S-<right>")
     (S-up . "S-<up>")
     (S-down . "S-<down>")
     (S-backspace . "<S-backspace>")
     (S-delete . "<S-delete>")
     (S-return . "<S-return>"))
   ;; f1..f35 and S-f1..S-f35
   (cl-mapcan (lambda (i)
                (list (cons (god-mode-make-f-key i)   (format "<f%d>" i))
                      (cons (god-mode-make-f-key i t) (format "S-<f%d>" i))))
              (number-sequence 1 35)))
  "Association list mapping special events to their textual representations.")

(defun god-mode-sanitized-key-string (key)
  "Convert any special events in KEY to textual representation."
  (or (cdr (assq key god-mode-sanitized-key-alist))
      (char-to-string key)))

(defun god-mode-help-char-dispatch (_help-key key-string-so-far)
  "Invokes `prefix-help-command' by entering the key sequence KEY-STRING-SO-FAR
followed by the `help-char' key.
HELP-KEY contains the key that caused `god-mode-help-char-dispatch' to be called
from the command loop."
  ;; Adding an element (t . key) to `unread-command-events' will add key to
  ;; the current command's key sequence.
  (setq unread-command-events
        (cl-loop for key in (append (read-kbd-macro key-string-so-far t)
                                    (list help-char))
                 collect (cons t key)))
  ;; Return nil so that `god-mode-lookup-command' doesn't perform any action.
  nil)

(defun god-key-string-after-consuming-key (key key-string-so-far)
  "Interpret god-mode special keys for KEY.
Consumes more keys if appropriate.
Appends to key sequence KEY-STRING-SO-FAR."
  (let ((modifier "")
        (next-key (lambda () (god-mode-sanitized-key-string (read-event key-string-so-far)))))
    (message key-string-so-far)
    (when key-string-so-far ; Don't check for `god-literal-key' with the first key.
      (while (string= key god-literal-key)
        (setq god-literal-sequence (not god-literal-sequence)
              key (funcall next-key))))
    (unless god-literal-sequence
      (let ((modifier-lookup (and (stringp key) (assoc key god-mode-alist))))
        (if modifier-lookup
            (setq modifier (cdr modifier-lookup)
                  key (funcall next-key))
          (setq modifier (cdr (assoc nil god-mode-alist))))))
    (if (and key-string-so-far (string= key (format "%c" help-char)))
        (god-mode-help-char-dispatch key key-string-so-far)
      (when (and (= (length key) 1)
                 (string= (get-char-code-property (aref key 0) 'general-category) "Lu")
                 ;; If C- is part of the modifier, S- needs to be given
                 ;; in order to distinguish the uppercase from the
                 ;; lowercase bindings. If C- is not in the modifier,
                 ;; then emacs natively treats uppercase differently
                 ;; from lowercase, and the S- modifier should not be
                 ;; supplied.
                 (string-prefix-p "C-" modifier))
        (setq modifier (concat modifier "S-")))
      (if key-string-so-far
          (concat key-string-so-far " " modifier key)
        (concat modifier key)))))

(defun god-mode-lookup-command (key-string)
  "Look up and return the command for KEY-STRING.
Tries fallback for the last key by removing Control modifier. If no command is found,
returns a keymap to allow further key input, or nil if completely unbound."
  (when key-string
    (let* ((key-vector (read-kbd-macro key-string t))
           (binding (key-binding key-vector)))
      (cond
       ;; Case 1: found an actual command
       ((commandp binding)
        (setq last-command-event (aref key-vector (1- (length key-vector))))
        binding)

       ;; Case 2: it's a keymap (partial key sequence)
       ((keymapp binding)
        (god-mode-lookup-key-sequence nil key-string))

       ;; Case 3: try fallback by removing C- from the last key
       ((string-match "\\(.*\\) C-\\(.\\)$" key-string)
        (let* ((prefix (match-string 1 key-string))
               (last (match-string 2 key-string))
               (key-str (format "%s %s" prefix last))
               (fallback-key (if (>= emacs-major-version 28)
                                 (string-trim-right key-str)
                               (replace-regexp-in-string
                                "[ \t\n\r]+$" "" ;; Remove trailing whitespace
                                key-str)))
               (fallback-vector (read-kbd-macro fallback-key t))
               (fallback-binding (key-binding fallback-vector)))
          (cond
           ((commandp fallback-binding)
            (message "Using fallback command: %s" fallback-key)
            (setq last-command-event (aref fallback-vector (1- (length fallback-vector))))
            fallback-binding)

           ((keymapp fallback-binding)
            (message "Using fallback keymap: %s" fallback-key)
            (god-mode-lookup-key-sequence nil fallback-key))

           ;; Not a command nor a map — wait for more input, don't fail
           )))))))

;;;###autoload
(defun god-mode-maybe-activate (&optional status)
  "Activate `god-local-mode' on individual buffers when appropriate.
STATUS is passed as an argument to `god-mode-activate'."
  (when (not (minibufferp))
    (god-mode-activate status)))

(defun god-mode-activate (&optional status)
  "Activate `god-local-mode' on individual buffers when appropriate.
STATUS is passed as an argument to `god-local-mode'."
  (when (and god-global-mode
             (god-passes-predicates-p))
    (god-local-mode (if status status 1))))

(defun god-exempt-mode-p ()
  "Return non-nil if `major-mode' is exempt.
Members of the `god-exempt-major-modes' list are exempt."
  (memq major-mode god-exempt-major-modes))

(defun god-mode-child-of-p (mode parent-mode)
  "Return non-nil if MODE is derived from PARENT-MODE."
  (let ((parent (get mode 'derived-mode-parent)))
    (cond ((eq parent parent-mode))
          ((not (null parent))
           (god-mode-child-of-p parent parent-mode))
          (t nil))))

(defun god-comint-mode-p ()
  "Return non-nil if `major-mode' is derived from `comint-mode'."
  (god-mode-child-of-p major-mode 'comint-mode))

(defun god-special-mode-p ()
  "Return non-nil if `major-mode' is special or derived from `special-mode'."
  (eq (get major-mode 'mode-class) 'special))

(defun god-view-mode-p ()
  "Return non-nil if variable `view-mode' is non-nil in current buffer."
  view-mode)

(defun god-git-commit-mode-p ()
  "Return non-nil if a `git-commit-mode' will be enabled in this buffer."
  (and (bound-and-true-p global-git-commit-mode)
       ;; `git-commit-filename-regexp' defined in the same library as
       ;; `global-git-commit-mode'.  Expression above maybe evaluated
       ;; to true because of autoload cookie.  So we perform
       ;; additional check.
       (boundp 'git-commit-filename-regexp)
       buffer-file-name
       (string-match-p git-commit-filename-regexp buffer-file-name)))

(defun god-passes-predicates-p ()
  "Return non-nil if all `god-exempt-predicates' return nil."
  (not
   (catch 'disable
     (let ((preds god-exempt-predicates))
       (while preds
         (when (funcall (car preds))
           (throw 'disable t))
         (setq preds (cdr preds)))))))

;;;###autoload
(defun god-execute-with-current-bindings (&optional called-interactively)
  "Execute a single command from God mode, preserving current keybindings.

This command activates God mode temporarily, and deactivates God
mode as soon as the next command is run.  Prefix arguments do not
count as commands for this purpose, and do not cause God mode to
exit.  Moreover, any prefix argument that exists at the time of
this command's invocation is passed along to the next command.

Unlike normal use of God mode, this command makes available all
keybindings that were active at the time of its invocation,
including keybindings that are normally invisible to God mode,
such as those in `emulation-mode-map-alists' or text overlay
properties.  This makes it suitable for use with packages like
Evil that utilize such higher-priority keymaps.  (See Info
node `(elisp)Active Keymaps' for technical details on keymap
precedence.  For an alternative to this command, check out the
evil-god-state package, available on MELPA.)

This command has no effect when called from within God mode.

For interactive use only.  CALLED-INTERACTIVELY is a dummy
parameter to help enforce this restriction."
  (interactive "d")
  (if called-interactively
      (unless god-local-mode
        (message "Switched to God mode for the next command ...")
        (letrec ((caller this-command)
                 (buffer (current-buffer))
                 (cleanup
                  (lambda ()
                    ;; Perform cleanup in original buffer even if the command
                    ;; switched buffers.
                    (if (buffer-live-p buffer)
                        (with-current-buffer buffer
                          (unwind-protect (god-local-mode 0)
                            (remove-hook 'post-command-hook post-hook)))
                      (remove-hook 'post-command-hook post-hook))))
                 (kill-transient-map
                  (set-transient-map
                   god-local-mode-map 'god-prefix-command-p cleanup))
                 (post-hook
                  (lambda ()
                    (unless (and
                             (eq this-command caller)
                             ;; If we've entered the minibuffer, this implies
                             ;; a non-prefix command was run, even if
                             ;; `this-command' has not changed.  For example,
                             ;; `execute-extended-command' behaves this way.
                             (not (window-minibuffer-p)))
                      (funcall kill-transient-map)))))
          (add-hook 'post-command-hook post-hook)
          ;; Pass the current prefix argument along to the next command.
          (setq prefix-arg current-prefix-arg)
          ;; Technically we don't need to activate God mode since the
          ;; transient keymap is already in place, but it's useful to provide
          ;; a mode line lighter and run any hook functions the user has set
          ;; up.  This could be made configurable in the future.
          (god-local-mode 1)))
    (error "This function should only be called interactively")))

(defun god-prefix-command-p ()
  "Return non-nil if the current command is a \"prefix\" command.
This includes prefix arguments and any other command that should
be ignored by `god-execute-with-current-bindings'."
  (memq this-command '(god-mode-self-insert
                       digit-argument
                       negative-argument
                       universal-argument
                       universal-argument-more)))


(defvar god-latest-described-command nil
  "The latest command recorded by `god-mode-describe-key'.")

(defun god-mode--help-fn-describe-function (_arg)
  "Insert information about `god-mode' key-bindings for the described function.
The argument _ARG is ignored: it's only needed because all hooks in
`help-fns-describe-function-functions' take the function-name as argument.
But in our case it's redundant"
  (insert
   (format-message "\n  %s\n  %s%s\n  %s%s%s\n\n"
                   "(`god-local-mode' is enabled. "
                   " The given key-sequence: "
                   (god-mode-get-described-key-seq)
                   " corresponds to this key-binding: "
                   (if (> emacs-major-version 27)
                       (help--key-description-fontified
                        god-latest-described-command)
                     god-latest-described-command)
                   ")")))

(defun god-mode-get-described-key-seq ()
  "Return the keys that were pressed after `god-mode-describe-key' was called."
  (let* ((latest-keys (recent-keys 'include-cmds))
         (latest-describe-key-index
          (cl-position '(nil . god-mode-self-insert)
                       latest-keys :from-end t :test #'equal))
         (start-index (+ 3 latest-describe-key-index))
         (key-sequence (key-description (seq-subseq latest-keys start-index))))
    (if (> emacs-major-version 27)
        (propertize key-sequence
                    'font-lock-face 'help-key-binding
                    'face 'help-key-binding)
      key-sequence)))

(defun god-mode-describe-key ()
  "Describe a key-sequence as interpreted by `god-mode'.
Prompt for a key sequence, use `god-mode-lookup-key-sequence' to translate it
into the appropriate command, and use `describe-function' to describe it"
  (interactive)
  (message "Describe the following god-mode key: ")
  (advice-add #'god-mode-lookup-command :filter-args
              (lambda (key-string)
                (setq god-latest-described-command key-string)))
  ;; use unwind-protect, and remove the advice / hook in the unwind forms
  (unwind-protect
      (let ((command
             ;; if the key is not recognized by god-mode,
             ;; we will pass it to the regular `describe-key'
             (condition-case err
                 (god-mode-lookup-key-sequence)
               (wrong-type-argument
                ;; due to how errors are passed,
                ;; we do not have enough information
                ;; to pass menu items
                (if (not (equal (cddr err) '((menu-bar))))
                    (describe-key (vector (caddr err))))))))
        (if command
            (progn
              (add-hook 'help-fns-describe-function-functions
                        #'god-mode--help-fn-describe-function)
              (describe-function command))))
    ;; unwind forms:
    (advice-remove #'god-mode-lookup-command
                   (lambda (key-string)
                     (setq god-latest-described-command key-string)))
    (remove-hook 'help-fns-describe-function-functions
                 #'god-mode--help-fn-describe-function)))

(provide 'god-mode)

;;; god-mode.el ends here
Download .txt
gitextract_41c9285x/

├── .github/
│   ├── CONTRIBUTING.md
│   ├── README.md
│   └── workflows/
│       └── test.yml
├── .gitignore
├── Cask
├── LICENSE
├── features/
│   ├── c-commands.feature
│   ├── digit-arguments.feature
│   ├── execute-with-current-bindings.feature
│   ├── insertion-mode.feature
│   ├── last-command-event.feature
│   ├── predicates-disable.feature
│   ├── prefix-arguments.feature
│   ├── prefix-help.feature
│   ├── regions.feature
│   ├── repeat.feature
│   ├── step-definitions/
│   │   └── god-mode-steps.el
│   └── support/
│       └── env.el
├── god-mode-isearch.el
└── god-mode.el
Condensed preview — 20 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (98K chars).
[
  {
    "path": ".github/CONTRIBUTING.md",
    "chars": 503,
    "preview": "# Contributing\n\nPlease write a failing test before submitting pull requests. All new features should be accompanied by n"
  },
  {
    "path": ".github/README.md",
    "chars": 14411,
    "preview": "# God Mode — no more RSI\n\n[![melpa-badge][melpa-badge]][melpa-link]\n[![melpa-stable-badge][melpa-stable-badge]][melpa-st"
  },
  {
    "path": ".github/workflows/test.yml",
    "chars": 933,
    "preview": "name: CI\n\non: [push, pull_request]\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        emacs_"
  },
  {
    "path": ".gitignore",
    "chars": 38,
    "preview": ".cask\n.ecukes-failing-scenarios\n*.elc\n"
  },
  {
    "path": "Cask",
    "chars": 158,
    "preview": "(source gnu)\n(source melpa)\n\n(package \"god-mode\" \"2.19.0\" \"God-like command entering minor mode.\")\n\n(development\n (depen"
  },
  {
    "path": "LICENSE",
    "chars": 35147,
    "preview": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
  },
  {
    "path": "features/c-commands.feature",
    "chars": 7765,
    "preview": "Feature: C- commands\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And the buffer is empty\n    And I insert"
  },
  {
    "path": "features/digit-arguments.feature",
    "chars": 494,
    "preview": "Feature: Digit arguments\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And the buffer is empty\n    And I in"
  },
  {
    "path": "features/execute-with-current-bindings.feature",
    "chars": 827,
    "preview": "Feature: Execute with current bindings\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And I bind \"C-e\" to \"g"
  },
  {
    "path": "features/insertion-mode.feature",
    "chars": 411,
    "preview": "Feature: Insertion mode\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And the buffer is empty\n    And I am "
  },
  {
    "path": "features/last-command-event.feature",
    "chars": 499,
    "preview": "Feature: Prefix arguments\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And the buffer is empty\n    And I i"
  },
  {
    "path": "features/predicates-disable.feature",
    "chars": 1040,
    "preview": "Feature: Predicate based disable\n  Background:\n    Given god-mode is enabled for all buffers\n    And I am in buffer \"god"
  },
  {
    "path": "features/prefix-arguments.feature",
    "chars": 775,
    "preview": "Feature: Prefix arguments\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And the buffer is empty\n    And I i"
  },
  {
    "path": "features/prefix-help.feature",
    "chars": 1085,
    "preview": "Feature: Prefix help\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And the buffer is empty\n    And I have g"
  },
  {
    "path": "features/regions.feature",
    "chars": 567,
    "preview": "Feature: Regions\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And the buffer is empty\n    And I insert \"He"
  },
  {
    "path": "features/repeat.feature",
    "chars": 927,
    "preview": "Feature: Repeat\n  Background:\n    Given I am in buffer \"god-mode-test\"\n    And the buffer is empty\n    And I insert \"abc"
  },
  {
    "path": "features/step-definitions/god-mode-steps.el",
    "chars": 3126,
    "preview": ";; This file contains your project specific step definitions. All\n;; files in this directory whose names end with \"-step"
  },
  {
    "path": "features/support/env.el",
    "chars": 683,
    "preview": "(require 'f)\n(require 'cl-lib)\n\n(defvar god-mode-support-path\n  (f-dirname load-file-name))\n\n(defvar god-mode-features-p"
  },
  {
    "path": "god-mode-isearch.el",
    "chars": 1874,
    "preview": ";;; god-mode-isearch.el --- God mode behaviour for isearch  -*- lexical-binding: t; -*-\n\n;; Copyright (C) 2014 Chris Don"
  },
  {
    "path": "god-mode.el",
    "chars": 22730,
    "preview": ";;; god-mode.el --- Minor mode for God-like command entering  -*- lexical-binding: t; -*-\n\n;; Copyright (C) 2013 Chris D"
  }
]

About this extraction

This page contains the full source code of the chrisdone/god-mode GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 20 files (91.8 KB), approximately 23.3k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!