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
    Commented Apr 13, 2017 at 16:44

1 Answer 1


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:

  1. add an after advice to fundamental-mode to make it run emacs-lisp-mode,

  2. call org-table-edit-formulas,

  3. 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
    Commented Apr 13, 2017 at 14:35
  • Looking at org-table.el, I think that calling emacs-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
    Commented Apr 13, 2017 at 18:37
  • A "brute force" solution could be to copy the function org-table-edit-formulas from file org-table.el, change the call to fundamental-mode by emacs-lisp-mode and use that definition to override the one from org-table.el. I think this should work, but may break later when other things change in org-table.el.
    – JeanPierre
    Commented Apr 13, 2017 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
    Commented Apr 13, 2017 at 18:51
  • I just tried. It looks fine. many thanks.
    – gigiair
    Commented Apr 14, 2017 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.