Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 56 additions & 19 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![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.
_NOTE_: This package requires Emacs 29 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
Expand Down Expand Up @@ -47,22 +47,22 @@ 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)
(keymap-global-set "<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)
(keymap-global-set "<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)
(setopt god-exempt-major-modes nil)
(setopt god-exempt-predicates nil)
```

This means that `magit-mode` or `dired-mode`, for example, will also enter God
Expand All @@ -76,7 +76,7 @@ translated to <kbd>C-&lt;f5></kbd>. To disable this translation, you can set the
mode, as follows:

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

Expand Down Expand Up @@ -240,8 +240,8 @@ 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)
(keymap-set isearch-mode-map "escape>" #'god-mode-isearch-activate)
(keymap-set god-mode-isearch-map "<escape>" #'god-mode-isearch-disable)
```

You can also configure `god-mode-isearch-map` for additional keybindings.
Expand All @@ -259,7 +259,7 @@ mapping that calls `org-self-insert-command` in `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)
(keymap-set god-local-mode-map "<remap> <self-insert-command>" #'god-mode-self-insert)
```

## Useful key bindings
Expand All @@ -268,37 +268,74 @@ 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)))
(keymap-set god-local-mode-map "i" #'god-local-mode)
(keymap-global-set "<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)
(keymap-set god-local-mode-map "z" #'repeat)
```

Although I personally prefer:

```emacs-lisp
(define-key god-local-mode-map (kbd ".") #'repeat)
(keymap-set god-local-mode-map "." #'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)
(keymap-global-set "C-x C-1" #'delete-other-windows)
(keymap-global-set "C-x C-2" #'split-window-below)
(keymap-global-set "C-x C-3" #'split-window-right)
(keymap-global-set "C-x C-0" #'delete-window)

(define-key god-local-mode-map (kbd "[") #'backward-paragraph)
(define-key god-local-mode-map (kbd "]") #'forward-paragraph)
(keymap-set god-local-mode-map "[" #'backward-paragraph)
(keymap-set god-local-mode-map "]" #'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.

## Setup with use-package
You can also set all above customizations with following use-package:

```emacs-lisp
(use-package god-mode ; uncomment anything you want to use
:ensure t
:config
(require 'god-mode-isearch)
;; :custom
;; (god-exempt-major-modes nil)
;; (god-exempt-predicates nil)
;; (god-mode-enable-function-key-translation nil)
;; :custom-face
;; (god-mode-lighter ((t (:inherit error))))
:bind (:map
global-map
("<escape>" . god-local-mode)
;; ("<escape>" . god-mode-all)
;; ("<escape>" . (lambda () (interactive) (god-local-mode 1)))
;; ("i" . god-local-mode)
;; ("." . repeat)
;; ("C-x C-1" . delete-other-windows)
;; ("C-x C-2" . split-window-below)
;; ("C-x C-3" . split-window-right)
;; ("C-x C-0" . delete-window)
;; :map god-local-mode-map
;; ("[" . backward-paragraph)
;; ("]" . forward-paragraph)
;; :map
;; isearch-mode-map
;; ("<escape>" . god-mode-isearch-activate)
;; :map
;; god-mode-isearch-map
;; ("<escape>" . god-mode-isearch-disable)
))
```

## Exempt major modes

_NOTE_: This is less necessary in recent versions of God mode, as
Expand Down
20 changes: 10 additions & 10 deletions god-mode-isearch.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Author: Chris Done <chrisdone@gmail.com>
;; URL: https://github.com/emacsorphanage/god-mode
;; Version: 2.19.0
;; Package-Requires: ((emacs "26.3"))
;; Package-Requires: ((emacs "29"))

;; 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
Expand All @@ -29,16 +29,16 @@

;; 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)
;; (keymap-set isearch-mode-map "<escape>" 'god-mode-isearch-activate)
;; (keymap-set god-mode-isearch-map "<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.")
(defvar-keymap god-mode-isearch-map
:parent isearch-mode-map
:doc
"Keymap for modal isearch."
"s" #'isearch-repeat-forward
"r" #'isearch-repeat-backward
"w" #'isearch-yank-word-or-char)

(defun god-mode-isearch-activate ()
"Activate God mode in the isearch buffer."
Expand Down
33 changes: 16 additions & 17 deletions god-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

;;; Code:

(require 'cl-lib)

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

(defvar god-local-mode-paused nil)
Expand Down Expand Up @@ -129,17 +127,17 @@ For example, calling with arguments 5 and t yields the symbol `S-f5'."
(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)
(keymap-set map "<remap> <self-insert-command>" #'god-mode-self-insert)
(let ((i ?\s))
(while (< i 256)
(define-key map (vector i) 'god-mode-self-insert)
(keymap-set map (single-key-description 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)
(keymap-set map (single-key-description (god-mode-make-f-key (1+ i))) 'god-mode-self-insert)
(keymap-set map (single-key-description (god-mode-make-f-key (1+ i) t)) 'god-mode-self-insert)))
(keymap-set map "DEL" nil)
(keymap-set map "C-h k" #'god-mode-describe-key)
map))

;;;###autoload
Expand Down Expand Up @@ -192,10 +190,10 @@ 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))))
(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
Expand All @@ -213,7 +211,7 @@ is a negative number."
(call-interactively binding)
(execute-kbd-macro binding)))))

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

(defun god-mode-self-insert ()
Expand Down Expand Up @@ -279,7 +277,7 @@ KEY-STRING-SO-FAR should be nil for the first call in the sequence."
(S-delete . "<S-delete>")
(S-return . "<S-return>"))
;; f1..f35 and S-f1..S-f35
(cl-mapcan (lambda (i)
(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)))
Expand All @@ -298,9 +296,10 @@ 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)))
(mapcar (lambda (key)
(cons t key))
(append (read-kbd-macro key-string-so-far t)
(list help-char))))
;; Return nil so that `god-mode-lookup-command' doesn't perform any action.
nil)

Expand Down
Loading