summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSomelauw <Somelauw@gmail.com>2018-01-16 22:47:40 +0100
committerGitHub <noreply@github.com>2018-01-16 22:47:40 +0100
commit491b0b302b95d44ceb73d291dedbb9d5517ccee2 (patch)
treef90521bbed33ab6f66e0fa10a2df88e28930afbc
parent22c248deb6c74a5bcdb0268306eed878a44fe517 (diff)
parent1e64669cd65fc0f900a1166cfc4520f77aa5e41f (diff)
Merge pull request #32 from Somelauw/hybrid-shift
Make shift keytheme context sensitive
-rw-r--r--doc/changelog.org3
-rw-r--r--doc/keythemes.org2
-rw-r--r--evil-org.el29
3 files changed, 33 insertions, 1 deletions
diff --git a/doc/changelog.org b/doc/changelog.org
index 7094783..5e0790d 100644
--- a/doc/changelog.org
+++ b/doc/changelog.org
@@ -1,3 +1,5 @@
+* Version 1.1
+ - Implement hybrid shift keys
* Version 1.0
- Make =dw= realign tags. Make =dd= renumber lists.
- Simplify implementation of `evil-org-open-above/below`.
@@ -5,6 +7,7 @@
- Add =return= keytheme.
- Add =calendar= keytheme.
- Remove =rsi= keytheme
+ - Add org-agenda bindings (thanks to Ambrevar)
* Version 0.9
- Make =I= / =A= ignore ellipses on heading. Also make them respect =org-special-ctrl-a/e=.
- Make it possible for =<= and =>= (renamed to evil-org-</>) to move table columns.
diff --git a/doc/keythemes.org b/doc/keythemes.org
index 7ac6385..7bd755b 100644
--- a/doc/keythemes.org
+++ b/doc/keythemes.org
@@ -164,6 +164,8 @@
| =K= | org-shiftup | increase priority |
|-----+----------------+--------------------|
+ When point is not at a heading or item, these keys fall back on their binding in non-org modes. For example, you can still use =J= to join lines when not at a heading. This behaviour can be configured using =evil-org-want-hybrid-shift=. By default this option is set to ~t~.
+
** Todo
Disabled by default.
diff --git a/evil-org.el b/evil-org.el
index 1d5f288..fcb0bd9 100644
--- a/evil-org.el
+++ b/evil-org.el
@@ -95,6 +95,13 @@ By default, o and O are bound to ‘evil-org-open-above’ and ‘evil-org-open-
:group 'evil-org
:type 'boolean)
+(defcustom evil-org-want-hybrid-shift t
+ "Whether HJKL should fall back on default bindings if not on heading/item.
+This variable only takes effect when shift keytheme is enabled and should be set
+before calling `evil-org-set-keytheme'."
+ :group 'evil-org
+ :type 'boolean)
+
;;; Variable declarations
(defvar browse-url-generic-program)
(defvar browse-url-generic-args)
@@ -296,6 +303,17 @@ The behavior of this function can be controlled using `evil-org-special-o/O’."
(string-match-p "^[[:space:]]*-[[:space:]]*\\(::[[:space:]]*\\)?$"
(thing-at-point 'line)))))
+;; other
+(defun evil-org-shift-fallback-command ()
+ "Call the default evil command that is bound the currently pressed key."
+ (when (and evil-mode evil-org-mode evil-org-want-hybrid-shift)
+ (let ((key (this-command-keys)))
+ (when-let ((command (or (lookup-key evil-normal-state-map key)
+ (lookup-key evil-motion-state-map key))))
+ (when (commandp command)
+ (call-interactively command)
+ t)))))
+
(defmacro evil-org-define-eol-command (cmd)
"Return a function that executes CMD at eol and then enters insert state.
eol stands for end of line.
@@ -684,7 +702,16 @@ Includes tables, list items and subtrees."
(capitalize .left) 'org-shiftleft
(capitalize .right) 'org-shiftright
(capitalize .down) 'org-shiftdown
- (capitalize .up) 'org-shiftup)))
+ (capitalize .up) 'org-shiftup)
+
+ ;; Make shift keys fall back on the keys they have replaced
+ (when evil-org-want-hybrid-shift
+ (dolist (hook '(org-shiftleft-final-hook
+ org-shiftright-final-hook
+ org-shiftdown-final-hook
+ org-shiftup-final-hook))
+ (add-hook hook #'evil-org-shift-fallback-command 'append)))))
+
(defun evil-org--populate-todo-bindings ()
"Bindings for easy todo insertion."