edwtjo / evil-org-mode

Supplemental evil-mode keybindings to emacs org-mode
204 stars 37 forks source link

Rebind deletion keys to org equivalents #15

Open rpglover64 opened 9 years ago

rpglover64 commented 9 years ago

In particular, Backspace in insert state and x in normal state; otherwise, table alignment gets screwed up until something repairs it.

wsdookadr commented 9 years ago

@rpglover64 C-c C-c in normal mode can repair the table alignment, right ?

Using the advice feature , something like this should re-align the table after you've deleted a character in it with x :

(advice-add 'evil-delete-char
            :after '(lambda (beg end type register)
                      (interactive)
                      (org-ctrl-c-ctrl-c)
                      ))
wsdookadr commented 9 years ago

@rpglover64 bump ^^ , would this fit your use-case ?

rpglover64 commented 9 years ago

It seems like the wrong way to accomplish it, but it also seems like it would work. I worry, though, how it would act when you switch out of org-mode.

wsdookadr commented 9 years ago

@rpglover64 yeah, you're right, this should only work while in org-mode.

how about this ?

(require 'advice)
(advice-add 'evil-delete-char
            :after '(lambda (&rest args)
                      (when (and
                             (string-equal "org-mode" major-mode)
                             (string-match "^table.*$"
                                           (symbol-name
                                            (car
                                             (car
                                              (org-element-at-point (point)))))))
                        (org-ctrl-c-ctrl-c)
                        )))
rpglover64 commented 9 years ago

Why not

(evil-define-operator evil-org-delete-char (beg end type register)
  "Delete next character."
  :motion evil-forward-char
  (interactive "<R><x>")
  (evil-delete beg end type register)
  (org-fix-tags-on-the-fly))

(evil-define-operator evil-org-delete-backward-char (beg end type register)
  "Delete previous character."
  :motion evil-backward-char
  (interactive "<R><x>")
  (evil-delete beg end type register)
  (org-fix-tags-on-the-fly))

and then rebind x and Backspace?

I'm not sure if it's quite right, but that's what I got skimming evil-delete-char and org-delete-char.

Somelauw commented 7 years ago

@rpglover64 I did something like that in my plugin here. Now I'm wondering whether it would be a good idea to realign tables on every deletion command, but even org-mode itself doesn't doesn't realign tables on e.g. C-w, so there might be a good reason not to.