The default mode is fundamental, which is not really comfortable to edit elisp code did I miss something ?
-
@JeanPierre provides code to switch to emacs-lisp-mode for editing table formulas. You cannot switch to emacs-lisp-mode without 'turning-off' the table-editing commands provided by org-mode. You can add individual features from elisp-mode, or at least keybindings. Are there particular parts of emacs-lisp-mode you want to have access to? We might be able to help you set them up. – Tyler Apr 13 '17 at 16:44
A first idea is to to use an after advice to ensure
emacs-lisp-mode
is turned on after org-table-edit-formulas
is run.
(advice-add #'org-table-edit-formulas :after #'emacs-lisp-mode)
However, this does not work well. Examining the source of the
function (in file org-table.el
) shows that it turns
fundamental-mode
on then sets up a few things (variables and
keybindings) that the call to emacs-lisp-mode
will undo.
We want to call emacs-lisp-mode
just after (or ideally, instead of)
the call to fundamental mode
in org-table-edit-formulas
. Here's
how to do it:
(defun my--advice-for-edit-formulas (orig-fun &rest args)
(advice-add #'fundamental-mode :after #'emacs-lisp-mode)
(apply orig-fun args)
(advice-remove #'fundamental-mode #'emacs-lisp-mode))
(advice-add #'org-table-edit-formulas :around #'my--advice-for-edit-formulas)
We set an around advice to org-table-edit-formulas
whose job is
to:
add an after advice to
fundamental-mode
to make it runemacs-lisp-mode
,call
org-table-edit-formulas
,- remove the advice to
fundamental-mode
.
This way, fundamental-mode
calls emacs-lisp-mode
only when itself
called from org-table-edit-formulas
.
Now it's possible it would be better to add an option to choose the
mode org-table-edit-formulas
will use, or to make it automatically
select emacs-lisp-mode
when the formulas are in elisp.
-
Thank you for your interest, but the problem il the same if I active emacs-lisp-mode while interactive. C-c ' is no longer bound to org-table-fedit-finish and all edits are lost. – gigiair Apr 13 '17 at 14:35
-
Looking at
org-table.el
, I think that callingemacs-lisp-mode
after the function cancels a number of things the function has set up (including bindings, but also variables), so this indeed not a viable solution. – JeanPierre Apr 13 '17 at 18:37 -
A "brute force" solution could be to copy the function
org-table-edit-formulas
from fileorg-table.el
, change the call tofundamental-mode
byemacs-lisp-mode
and use that definition to override the one fromorg-table.el
. I think this should work, but may break later when other things change inorg-table.el
. – JeanPierre Apr 13 '17 at 18:40 -
How about this? (defun my--advice-for-edit-formulas (orig-fun &rest args) (advice-add #'fundamental-mode :after #'emacs-lisp-mode) (apply orig-fun args) (advice-remove #'fundamental-mode #'emacs-lisp-mode)) (advice-add #'org-table-edit-formulas :around #'my--advice-for-edit-formulas) – JeanPierre Apr 13 '17 at 18:51
-