0

Is there a simple way to get command-i, command-b, and command-u to operate in emacs org-mode on Mac in exactly the way that they operate in a typical word processor on Mac (for example, Microsoft Word for Mac)?


[Edit (Mar 14 '21)]:

To be more precise, I think I want typing 'command-i', for example, to do something like the following:

For every chunk of selected text (counting a cursor with no text selected as a selection with zero length):

  • Adding emphasis markers:
    • If no '/' immediately precedes the selection and no '/' begins the selection, then add a '/' immediately before the selection;
    • If no '/' immediately follows the selection and no '/' ends the selection, then add a '/' immediately after the selection;
  • Deleting emphasis markers:
    • Deleting emphasis markers at the start of the selection:
      • If a '/' immediately precedes the selection if and only if no '/' begins the selection, then delete the '/' that precedes or begins the selection;
      • If a '/' immediately precedes the selection and a '/' begins the selection, then delete the '/' that begins the selection;
    • Deleting emphasis markers at the end of the selection:
      • If a '/' immediately follows the selection if and only if no '/' ends the selection, then delete the '/' that follows or ends the selection;
      • If a '/' immediately follows the selection and a '/' ends the selection, then delete the '/' that ends the selection.

I’m a writer/academic, and I’ve been looking for a new text editor. It looks like it should be possible to set up emacs org-mode in a way that meets almost all of my requirements, so I'm thinking of making the switch from writing markdown in Visual Studio Code. My main concern regards the keybindings. I would like to be able to keep as many of the standard Mac/Windows keybindings as possible so that I’m not constantly getting tripped up whenever I switch between different applications and computers, which I will need to do regularly. I’m aware that there’s a mode called ‘cua-mode’ which allows the use of C-c, C-x, C-v, and C-z for copy, cut, paste, undo, etc., and I’ve downloaded Aquamacs which appears to use most of the standard Mac keybindings (using the more standard command key rather than the control key).

The main thing I would like to be able to do is to use the standard (on Mac) command-i, command-b, and command-u to toggle italics, bold, and underline, respectively, in org-mode, inserting or removing the relevant emphasis marks around the selected region (or point, if nothing is selected). The closest solution I’ve found so far is a configuration called emacs-org-mode-for-the-laity, but its keybindings for removing italics, bold, or underline from a selection are non-standard, requiring the use of the shift key.

I'm surprised not to have found an existing simple way of implementing this (I'm currently using an extension that does exactly this for markdown syntax in Visual Studio Code). This makes me think that it may be trickier to set this up in org-mode than one might think. Would it be particularly difficult to set this up in org-mode? Is there an existing package that I've overlooked that allows for this functionality?

7
  • It is curious! Org as a markdown has its limitations. For example, you can not have different overlapping emphasis markers in a text and have them exported correctly. Also, try adding bold to letters within a word. That does not work. You have to add emphasis to whole words. This creates complications if you are used to selecting text with the mouse and try to remove part of the emphasis. It is all doable, but expected behaviour is not clear to me. It would be helpful if you were to describe what exactly you try to do. – Heikki Mar 12 at 6:48
  • Are you using (setq org-hide-emphasis-markers t) to see how org mode understands your added emphasis markers? – Heikki Mar 12 at 6:52
  • Most of the evelopment happens at Gnu Emacs. Aquaemacs might have quite an old version of org mode. Check the version with org-version. – Heikki Mar 12 at 6:54
  • Thanks for letting me know about the problems with combining emphasis markers and emphasising parts of words in org-mode. As you indicated, it looks like there are ways around most of these problems with some tweaking (according to this answer and this answer, for example)—although this does add even more to the setup cost of switching to org-mode. – user32038 Mar 13 at 3:06
  • Not sure how much this actually bears on my question, but yes, I've experimented with (setq org-hide-emphasis-markers t); org-mode seems to highlight the emphasised text the same way either way. And the version of org-mode that's included in the version of Aquamacs I've installed is org-mode 8.2.10. – user32038 Mar 13 at 3:12
0

This works for me (using general), though it doesn't remove markup, so perhaps YMMV. See also this stack exchange answer: Unable to bind emphasize key in org-mode

See also: org-appear for showing and hiding markup.

Note that below requires expand region as well.

  (general-define-key :states '(normal insert) :keymaps 'org-mode-map
    "s-b" (lambda () (interactive) (er/mark-word) (org-emphasize ?\*))
    "s-i" (lambda () (interactive) (er/mark-word) (org-emphasize ?\/))
    "s-l" (lambda () (interactive) (er/mark-word) (org-emphasize ?\=))
    ;; better pasting behavior in org-mode
    "s-v" 'org-yank))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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