From 62ff637748037dac5ce130ae359deb617a6bcce2 Mon Sep 17 00:00:00 2001 From: Somelauw Date: Tue, 29 Aug 2017 20:48:08 +0200 Subject: Replace bindings to lambdas by macros Deprecate evil-org-bol-call and evil-org-eol-call Add evil-org-define-bol-command and evil-org-define-eol-command This looks cleaner and might improve interaction with https://github.com/gabesoft/evil-mc --- doc/example_config.el | 8 ++---- doc/keythemes.org | 26 ++++++++--------- evil-org.el | 80 +++++++++++++++++++++++++++------------------------ 3 files changed, 58 insertions(+), 56 deletions(-) diff --git a/doc/example_config.el b/doc/example_config.el index e9682ea..5569710 100644 --- a/doc/example_config.el +++ b/doc/example_config.el @@ -14,12 +14,8 @@ (evil-define-key 'normal evil-org-mode-map (kbd "-") 'org-ctrl-c-minus (kbd "|") 'org-table-goto-column - (kbd "M-o") (lambda (arg) - (interactive "P") - (evil-org-eol-call #'org-insert-heading arg)) - (kbd "M-t") (lambda (arg) - (interactive "P") - (evil-org-eol-call #'org-insert-todo-heading arg))) + (kbd "M-o") (evil-org-define-eol-command org-insert-heading) + (kbd "M-t") (evil-org-define-eol-command org-insert-todo)) ;; Configure leader key (evil-leader/set-key-for-mode 'org-mode diff --git a/doc/keythemes.org b/doc/keythemes.org index 4e7b289..29e1475 100644 --- a/doc/keythemes.org +++ b/doc/keythemes.org @@ -127,23 +127,23 @@ ** Todo Disabled by default. - |-------+---------------------------------------| - | key | function | - |-------+---------------------------------------| - | =t= | org-todo | - | =T= | org-insert-todo-heading nil | - | =M-t= | org-insert-todo-heading+org-metaright | - |-------+---------------------------------------| + |-------+----------------------------| + | key | function | + |-------+----------------------------| + | =t= | org-todo | + | =T= | org-insert-todo-heading | + | =M-t= | org-insert-todo-subheading | + |-------+----------------------------| ** Heading Disabled by default. - |-------+----------------------------------| - | key | function | - |-------+----------------------------------| - | =O= | org-insert-heading | - | =M-o= | org-insert-heading+org-metaright | - |-------+----------------------------------| + |-------+-----------------------| + | key | function | + |-------+-----------------------| + | =O= | org-insert-heading | + | =M-o= | org-insert-subheading | + |-------+-----------------------| ** Commands without default binding These functions don't have any bindings by default. You can bind them under C-c or another leader key. These functions may have a few bugs. Improvements in the form of pull requests diff --git a/evil-org.el b/evil-org.el index 78e0901..76d944f 100644 --- a/evil-org.el +++ b/evil-org.el @@ -7,7 +7,7 @@ ;; Git-Repository: git://github.com/Somelauw/evil-org-mode.git ;; Created: 2012-06-14 ;; Forked-since: 2017-02-12 -;; Version: 0.9.3 +;; Version: 0.9.4 ;; Package-Requires: ((emacs "24.4") (evil "1.0") (org "8.0.0")) ;; Keywords: evil vim-emulation org-mode key-bindings presets @@ -117,6 +117,7 @@ By default, o and O are bound to ‘evil-org-open-above’ and ‘evil-org-open- "Go to end of line and call provided function. FUN function callback Optional argument ARGUMENTS arguments to pass to FUN." + (obsolete 'evil-org-define-bol-command "0.9.4") (end-of-visible-line) (apply fun arguments) (evil-insert nil)) @@ -125,7 +126,8 @@ Optional argument ARGUMENTS arguments to pass to FUN." "Go to beginning of line and call provided function. FUN function callback Optional argument ARGUMENTS arguments to pass to FUN." - (beginning-of-visual-line) + (obsolete 'evil-org-define-bol-command "0.9.4") + (beginning-of-line) (apply fun arguments) (evil-insert nil)) @@ -214,7 +216,8 @@ Optional argument ARGUMENTS arguments to pass to FUN." ;;; insertion commands (defun evil-org-insert-line (count) - "Insert at beginning of line, but if org-special-ctrl-a/e ignore heading and item markers. + "Insert at beginning of line. +If ‘org-special-ctrl-a/e’ insertion will be done after heading and item markers. The insertion will be repeated COUNT times." (interactive "p") (if (org-at-heading-or-item-p) @@ -225,7 +228,8 @@ The insertion will be repeated COUNT times." (evil-insert-line count))) (defun evil-org-append-line (count) - "Insert at beginning of line but if org-special-ctrl-a/e ignore tags and ellipses at end of the line. + "Append at end of line before ellipses if present. +If ‘org-special-ctrl-a/e’ insert before tags on headlines. The insertion will be repeated COUNT times." (interactive "p") (if (org-at-heading-p) @@ -267,23 +271,33 @@ Passing in any prefix argument, executes the command without special behavior." ((item) (beginning-of-line) (org-insert-item) (evil-insert nil)) (otherwise (evil-open-above count))))) -(defun evil-org-insert-subheading (&optional arg) - "Insert new subheading. -Optional argument ARG If one prefix argument is given, insert at the end of current subtree." - (interactive "P") - (end-of-visible-line) - (org-insert-heading arg) - (org-metaright) - (evil-insert nil)) - -(defun evil-org-insert-subtodo (&optional arg) - "Insert new todo subheading. -Optional argument ARG If one prefix argument is given, insert at the end of current subtree." - (interactive "P") - (end-of-visible-line) - (org-insert-todo-heading arg) - (org-metaright) - (evil-insert nil)) +(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. +For many org functions such as `org-insert-heading', this creates a heading below the current line." + (let ((newcmd (intern (concat "evil-org-" (symbol-name cmd) "-below")))) + `(progn + (defun ,newcmd () + ,(concat "Call `" (symbol-name cmd) "' at end of line and go to insert mode.") + (interactive) + (end-of-visible-line) + (call-interactively #',cmd) + (evil-insert nil)) + #',newcmd))) + +(defmacro evil-org-define-bol-command (cmd) + "Return a function that executes CMD at bol and then enters insert state. +bol stands for beginning of line. +For many org functions such as `org-insert-heading', this creates a heading above the current line." + (let ((newcmd (intern (concat "evil-org-" (symbol-name cmd) "-above")))) + `(progn + (defun ,newcmd () + ,(concat "Call `" (symbol-name cmd) "' at beginning of line and go to insert mode.") + (interactive) + (beginning-of-line) + (call-interactively #',cmd) + (evil-insert nil)) + #',newcmd))) ;;; operators (evil-define-operator evil-org-> (beg end count) @@ -580,14 +594,10 @@ Includes tables, list items and subtrees." (kbd "O") 'evil-org-open-above (kbd "x") 'evil-org-delete-char (kbd "X") 'evil-org-delete-backward-char - (kbd "") (lambda () - (interactive) - (evil-org-eol-call - #'org-insert-heading-respect-content)) - (kbd "") (lambda () - (interactive) - (evil-org-eol-call - #'org-insert-todo-heading-respect-content))) + (kbd "") (evil-org-define-eol-command + org-insert-heading-respect-content) + (kbd "") (evil-org-define-eol-command + org-insert-todo-heading-respect-content)) (evil-define-key '(normal visual) evil-org-mode-map (kbd "") 'org-cycle (kbd "") 'org-shifttab @@ -671,18 +681,14 @@ Includes tables, list items and subtrees." "Bindings for easy todo insertion." (evil-define-key 'normal evil-org-mode-map (kbd "t") 'org-todo - (kbd "T") (lambda (arg) - (interactive "P") - (evil-org-eol-call #'org-insert-todo-heading arg)) - (kbd "M-t") 'evil-org-insert-subtodo)) + (kbd "T") (evil-org-define-eol-command org-insert-todo-heading) + (kbd "M-t") (evil-org-define-eol-command org-insert-todo-subheading))) (defun evil-org--populate-heading-bindings () "Bindings for easy heading insertion." (evil-define-key 'normal evil-org-mode-map - (kbd "O") (lambda (arg) - (interactive "P") - (evil-org-eol-call #'org-insert-heading arg)) - (kbd "M-o") 'evil-org-insert-subheading)) + (kbd "O") (evil-org-define-eol-command org-insert-heading) + (kbd "M-o") (evil-org-define-eol-command org-insert-subheading))) ;;;###autoload (defun evil-org-set-key-theme (&optional theme) -- cgit v1.0