summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSomelauw <Somelauw>2017-10-30 21:51:24 +0100
committerSomelauw <Somelauw>2017-10-31 00:20:48 +0100
commit28baac58e607fe0581d6f01dd539916616784d8d (patch)
tree9c3f03c038df1f0ed6c5fee18e55c68151145a60
parent84d4a509d230b943ae56ac2283dc61fc62a55ff1 (diff)
Add optional return binding
Still experimental
-rw-r--r--doc/changelog.org1
-rw-r--r--doc/keythemes.org23
-rw-r--r--evil-org.el31
3 files changed, 52 insertions, 3 deletions
diff --git a/doc/changelog.org b/doc/changelog.org
index 0911c2b..9010b26 100644
--- a/doc/changelog.org
+++ b/doc/changelog.org
@@ -2,6 +2,7 @@
- Make =dw= realign tags. Make =dd= renumber lists.
- Simplify implementation of `evil-org-open-above/below`.
- Only continue item lists on first line.
+ - Add =return= keytheme.
* 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 a2d2ea3..cccb15b 100644
--- a/doc/keythemes.org
+++ b/doc/keythemes.org
@@ -63,6 +63,29 @@
(kbd "<") 'org-meta-left)
#+end_src
Or enable the additional key binding theme and use =M-h= and =M-l.=
+
+** Return
+ Experimental function bound to =RET=.
+ Disabled by default. If enabled, it's active in insert and emacs state.
+
+ Depending on context, it performs one of the following actions:
+ - When on an empty item or table row, abort or split the item list or table.
+ - When on a non-empty item or table row, continue the item list or table.
+ - Otherwise, insert a newline and indent.
+
+ This makes =RET= more consistent with =evil-org-open-above/below= (which are bound to =o= and =O= by default).
+
+ |-------+-----------------|
+ | key | function |
+ |-------+-----------------|
+ | =RET= | evil-org-return |
+ |-------+-----------------|
+
+ Based on the following earlier work:
+ - https://github.com/calvinwyoung/org-autolist
+ - http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
+
+ * The cases in which =RET= should behave special can be controlled using =evil-org-special-o/O=. By default it's set to ~'(table-row item)~.
** Navigation
If you don't want to use =h/j/k/l,= you can customize =evil-org-movement-bindings=.
diff --git a/evil-org.el b/evil-org.el
index fc01479..171eda2 100644
--- a/evil-org.el
+++ b/evil-org.el
@@ -59,6 +59,7 @@ arguments."
:group 'evil-org
:type '(set (const navigation)
(const insert)
+ (const return)
(const textobjects)
(const rsi)
(const additional)
@@ -94,8 +95,6 @@ By default, o and O are bound to ‘evil-org-open-above’ and ‘evil-org-open-
:group 'evil-org
:type 'boolean)
-;; Constants
-
;;; Variable declarations
(defvar browse-url-generic-program)
(defvar browse-url-generic-args)
@@ -269,7 +268,30 @@ Passing in any prefix argument, executes the command without special behavior."
(evil-insert nil))
((evil-open-above count))))
- (evil-insert nil))
+(defun evil-org-return (arg)
+ "Like `org-return', but continues items and tables like `evil-open-below'.
+Pressing return twice cancels the continuation of the itemlist or table.
+If ARG is set it will not cancel the continuation.
+The behavior of this function can be controlled using `evil-org-special-o/O’."
+ (interactive "P")
+ (cond ((and (not arg) (evil-org--empty-element-p))
+ (delete-region (line-beginning-position) (line-end-position)))
+ ((eolp)
+ (call-interactively #'evil-org-open-below))
+ ('otherwise
+ (call-interactively #'org-return-indent))))
+
+(defun evil-org--empty-element-p ()
+ "Return if pointer is on an empty element."
+ (cond ((org-at-table-p)
+ (let* ((rows (cl-remove 'hline (org-table-to-lisp)))
+ (row (nth (1- (org-table-current-line)) rows)))
+ (cl-every 'string-empty-p row)))
+ ((org-at-item-p)
+ (let ((e (org-element-at-point)))
+ (or (not (org-element-property :contents-begin e))
+ (> (org-element-property :contents-begin e)
+ (line-end-position)))))))
(defmacro evil-org-define-eol-command (cmd)
"Return a function that executes CMD at eol and then enters insert state.
@@ -698,6 +720,9 @@ Optional argument THEME list of themes. See evil-org-keytheme for a list of valu
(evil-org--populate-base-bindings)
(when (memq 'navigation theme) (evil-org--populate-navigation-bindings))
(when (memq 'insert theme) (evil-org--populate-insert-bindings))
+ (when (memq 'return theme)
+ (evil-define-key 'insert evil-org-mode-map (kbd "RET") 'evil-org-return)
+ (define-key evil-org-mode-map (kbd "RET") 'evil-org-return))
(when (memq 'textobjects theme) (evil-org--populate-textobjects-bindings))
(when (memq 'rsi theme) (evil-org--populate-rsi-bindings))
(when (memq 'additional theme) (evil-org--populate-additional-bindings))