Search code examples
emacsorg-modecua-mode

Turn rectangle mark mode off in org mode in emacs


How do I disable cua's rectangle mark mode when using org mode in emacs? Ctrl + Enter is used by both modes and I'd prefer to just lose cua's functionality when I'm in org mode since I don't usually need to select a rectangle when editing an org document.

I'm pretty sure I once had some code in my .emacs that performed this function but I can no longer find it anywhere online. Sadly I'm not enough of an elisp guru to figure it out myself.


Solution

  • I don't use CUA except for the rectangles, so I do

    (global-set-key (kbd "C-<return>") 'cua-rectangle-mark-mode)
    

    Org mode's bindings automatically override global bindings, so C-<enter> runs org-insert-heading-respect-content with no extra configuration.


    I assume you're using cua-selection-mode or cua-mode, though. Since it's global you can't turn it off in just org buffers. Probably the best thing is to define your own function and bind it to cua-mode's map.

    (defun jpk/C-<return> (&optional arg)
      (interactive "P")
      (if (eq major-mode 'org-mode)
          (org-insert-heading-respect-content arg)
        (cua-rectangle-mark-mode arg)))
    
    (define-key cua-global-keymap (kbd "C-<return>") #'jpk/C-<return>)
    

    CUA does things kind of weirdly compared to most minor modes, so while the above works for me it might be wonky if your setup is different from mine.