Skip to content

Commit

Permalink
Merge pull request #111 from darth10/feature/new-ownership
Browse files Browse the repository at this point in the history
Tidying up god-mode package
  • Loading branch information
purcell authored Mar 29, 2020
2 parents 344167e + 8a05d41 commit b82ce18
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 98 deletions.
File renamed without changes.
18 changes: 13 additions & 5 deletions README.md → .github/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# God Mode — no more RSI

***NOTE***: Emacs 24.3 is required for this package to work well!
[![melpa-badge][melpa-badge]][melpa-link]
[![gh-actions-badge][gh-actions-badge]][gh-actions-link]

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

This is a global minor mode for entering Emacs commands without
modifier keys. It's similar to Vim's separation of commands and
Expand All @@ -13,9 +16,7 @@ In the example below you can see how much effort is reduced:
Before: C-p C-k C-n M-^ ) C-j C-y M-r C-x z z M-2 M-g M-g C-x C-s
After: p k n g ^ ) j y g r . . 2 g g x s

(Regarding `.` see
[nice keybindings](https://github.com/chrisdone/god-mode#nice-keybindings)
section.)
(Regarding `.` see [nice keybindings][nice-keybindings] section.)

You'll find that this mode comes surprisingly naturally and that you
already know how to run your existing Emacs commands.
Expand Down Expand Up @@ -73,7 +74,7 @@ Or use dconf:

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

See [here](http://askubuntu.com/questions/363346/how-to-permanently-switch-caps-lock-and-esc) for more details.
See [here][switch-caps-lock-and-esc] for more details.

## Mapping

Expand Down Expand Up @@ -250,3 +251,10 @@ be disabled for the current buffer. See the `god-exempt-predicates`
variable and its default members `god-exempt-mode-p`,
`god-comint-mode-p`, `god-view-mode-p` and `god-special-mode-p` for
further details.

[nice-keybindings]: https://github.com/emacsorphanage/god-mode#nice-keybindings
[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-badge]: https://melpa.org/packages/god-mode-badge.svg
[gh-actions-link]: https://github.com/emacsorphanage/god-mode/actions
[gh-actions-badge]: https://github.com/emacsorphanage/god-mode/workflows/CI/badge.svg
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
emacs_version:
- 24.4
- 24.5
- 25.1
- 25.2
- 25.3
- 26.1
- 26.2
- 26.3
- 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
- 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'
54 changes: 0 additions & 54 deletions .travis.yml

This file was deleted.

5 changes: 2 additions & 3 deletions Cask
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(source gnu)
(source melpa)

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

(development
(depends-on "ecukes")
(depends-on "ansi")
)
(depends-on "ansi"))
20 changes: 16 additions & 4 deletions god-mode-isearch.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
;;; god-mode-isearch.el --- God-mode-like behaviour for isearch
;;; god-mode-isearch.el --- God-mode-like behaviour for isearch -*- lexical-binding: t; -*-

;; Copyright (c) 2014 Chris Done. All rights reserved.
;; Copyright (C) 2014 Chris Done
;; Copyright (C) 2020 Akhil Wali

;; Author: Chris Done <[email protected]>
;; URL: https://github.com/chrisdone/god-mode
;; Version: 2.16.0
;; Package-Requires: ((emacs "24.4"))

;; 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 @@ -15,6 +21,10 @@
;; 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:

;; See README.md.

;;; Code:

;; Recommended use:
Expand All @@ -31,13 +41,15 @@
"Keymap for modal isearch.")

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

(defun god-mode-isearch-disable ()
"Switch back to regular isearch."
"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
67 changes: 35 additions & 32 deletions god-mode.el
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
;;; god-mode.el --- God-like command entering minor mode
;;; god-mode.el --- God-like command entering minor mode -*- 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 <[email protected]>
;; URL: https://github.com/chrisdone/god-mode
;; Version: 2.15.0
;; Version: 2.16.0
;; Package-Requires: ((emacs "24.4"))

;; This file is not part of GNU Emacs.

Expand Down Expand Up @@ -60,7 +62,7 @@
vc-annotate-mode
git-commit-mode ; For versions prior to Magit 2.1.0
magit-popup-mode)
"List of major modes that should not start in god-local-mode."
"List of major modes that should not start with `god-local-mode' enabled."
:group 'god
:type '(function))

Expand All @@ -70,8 +72,8 @@
#'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."
"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))

Expand All @@ -95,28 +97,28 @@ All predicates must return nil for god-local-mode to start."
(run-hooks 'god-mode-disabled-hook)))

(defun god-local-mode-pause ()
"Pause god-mode local to the buffer, if it's
enabled. See also `god-local-mode-resume'."
"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 ()
"Will re-enable god-mode, if it was active when
`god-local-mode-pause' was called. If not, nothing happens."
"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
"Activate God mode on all buffers?")
"Enable `god-local-mode' on all buffers.")

(defvar god-literal-sequence nil
"Activated after space is pressed in a command sequence.")
"Activated after `god-literal-key' is pressed in a command sequence.")

;;;###autoload
(defun god-mode ()
"Toggle global God mode."
"Toggle global `god-local-mode'."
(interactive)
(setq god-global-mode (not god-global-mode))
(if god-global-mode
Expand All @@ -125,7 +127,7 @@ enabled. See also `god-local-mode-resume'."

;;;###autoload
(defun god-mode-all ()
"Toggle God mode in all buffers."
"Toggle `god-local-mode' in all buffers."
(interactive)
(let ((new-status (if (bound-and-true-p god-local-mode) -1 1)))
(setq god-global-mode t)
Expand All @@ -136,7 +138,7 @@ enabled. See also `god-local-mode-resume'."
(setq god-global-mode (= new-status 1))))

(defun god-mode-maybe-universal-argument-more ()
"If god mode is enabled, call `universal-argument-more'."
"If `god-local-mode' is enabled, call `universal-argument-more'."
(interactive)
(if god-local-mode
(call-interactively #'universal-argument-more)
Expand Down Expand Up @@ -167,25 +169,24 @@ enabled. See also `god-local-mode-resume'."
(execute-kbd-macro binding))))

(defun god-mode-upper-p (char)
"Is the given char upper case?"
"Check if CHAR is an upper case character."
(and (>= char ?A)
(<= char ?Z)
(/= char ?G)))

(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."
"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
(key-string-after-consuming-key sanitized-key key-string-so-far))))
(god-key-string-after-consuming-key sanitized-key key-string-so-far))))

(defun god-mode-sanitized-key-string (key)
"Convert any special events to textual."
"Convert any special events in KEY to textual representation."
(cl-case key
(tab "TAB")
(?\ "SPC")
Expand All @@ -199,9 +200,10 @@ the sequence."
(return "RET")
(t (char-to-string key))))

(defun key-string-after-consuming-key (key key-string-so-far)
"Interpret god-mode special keys for key (consumes more keys if
appropriate). Append to keysequence."
(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 ((key-consumed t) (next-modifier "") next-key)
(message key-string-so-far)
(cond
Expand Down Expand Up @@ -234,8 +236,7 @@ appropriate). Append to keysequence."
(concat next-modifier next-key))))

(defun god-mode-lookup-command (key-string)
"Execute extended keymaps such as C-c, or if it is a command,
call it."
"Execute extended keymaps in KEY-STRING, or call it if it is a command."
(let* ((key-vector (read-kbd-macro key-string t))
(binding (key-binding key-vector)))
(cond ((commandp binding)
Expand All @@ -248,18 +249,20 @@ call it."

;;;###autoload
(defun god-mode-maybe-activate (&optional status)
"Activate God mode locally on individual buffers when appropriate."
"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 mode locally on individual buffers when appropriate."
"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.
"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))

Expand All @@ -272,15 +275,15 @@ Members of the `god-exempt-major-modes' list are exempt."
(t nil))))

(defun god-comint-mode-p ()
"Return non-nil if major-mode is child of comint-mode."
"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 a child of special-mode."
"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 view-mode is enabled in current buffer."
"Return non-nil if variable `view-mode' is non-nil in current buffer."
view-mode)

(defun god-git-commit-mode-p ()
Expand Down

0 comments on commit b82ce18

Please sign in to comment.